Skip to content

Commit ad154f8

Browse files
committed
fix: sentiment style map
1 parent 98a1d99 commit ad154f8

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

packages/ui/src/components/Tag/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ import { CloseIcon } from '@ultraviolet/icons'
44
import type { MouseEventHandler, ReactNode } from 'react'
55
import { useMemo } from 'react'
66
import useClipboard from 'react-use-clipboard'
7+
import type { Color } from '../../theme'
78
import { Button } from '../Button'
89
import { Loader } from '../Loader'
910
import { Text } from '../Text'
1011
import { Tooltip } from '../Tooltip'
11-
import type { TagVariants } from './styles.css'
1212
import { closeButtonTag, containerTag, textTag } from './styles.css'
1313

1414
const COPY_DURATION = 2500
1515

1616
type TagProps = {
1717
isLoading?: boolean
1818
onClose?: MouseEventHandler<HTMLButtonElement>
19+
sentiment?: Color
20+
disabled?: boolean
21+
copiable?: boolean
1922
copyText?: string
2023
copiedText?: string
2124
className?: string
2225
children: ReactNode
2326
'data-testid'?: string
24-
} & TagVariants
27+
}
2528

2629
type TagInnerProps = Omit<
2730
TagProps,

packages/ui/src/components/Tag/styles.css.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { theme } from '@ultraviolet/themes'
2-
import type { RecipeVariants } from '@vanilla-extract/recipes'
32
import { recipe } from '@vanilla-extract/recipes'
4-
import type { Color } from '../../theme'
53
import { style } from '@vanilla-extract/css'
64

75
const SENTIMENTS = [
@@ -12,15 +10,8 @@ const SENTIMENTS = [
1210
'secondary',
1311
'success',
1412
'warning',
15-
] as Color[]
13+
] as const
1614

17-
function getSentimentStyle(sentiment: (typeof SENTIMENTS)[number]) {
18-
return {
19-
color: theme.colors[sentiment].text,
20-
background: theme.colors[sentiment].background,
21-
border: `solid 1px ${sentiment === 'neutral' ? theme.colors.neutral.border : theme.colors[sentiment].background}`,
22-
}
23-
}
2415
export const containerTag = recipe({
2516
base: {
2617
display: 'inline-flex',
@@ -49,16 +40,16 @@ export const containerTag = recipe({
4940
},
5041
},
5142

52-
sentiment: {
53-
danger: getSentimentStyle('danger'),
54-
info: getSentimentStyle('info'),
55-
neutral: getSentimentStyle('neutral'),
56-
primary: getSentimentStyle('primary'),
57-
secondary: getSentimentStyle('secondary'),
58-
success: getSentimentStyle('success'),
59-
warning: getSentimentStyle('warning'),
60-
},
61-
43+
sentiment: Object.fromEntries(
44+
SENTIMENTS.map(sentiment => [
45+
sentiment,
46+
{
47+
color: theme.colors[sentiment].text,
48+
background: theme.colors[sentiment].background,
49+
border: `solid 1px ${sentiment === 'neutral' ? theme.colors.neutral.border : theme.colors[sentiment].background}`,
50+
},
51+
]),
52+
),
6253
disabled: {
6354
true: {
6455
color: theme.colors.neutral.textDisabled,
@@ -84,5 +75,3 @@ export const closeButtonTag = style({
8475
height: 'fit-content',
8576
padding: theme.space['0.25'],
8677
})
87-
88-
export type TagVariants = NonNullable<RecipeVariants<typeof containerTag>>

0 commit comments

Comments
 (0)