Skip to content

Commit 33e8655

Browse files
authored
feat: add subtle and outline fill to s2 badge (#6898)
* feat: add subtle and outline fill to s2 badge * update comment * add transparent border, fix neutral outline color * fix layout * make props optional
1 parent 72ec2f5 commit 33e8655

File tree

1 file changed

+99
-35
lines changed

1 file changed

+99
-35
lines changed

packages/@react-spectrum/s2/src/Badge.tsx

Lines changed: 99 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export interface BadgeStyleProps {
3434
*
3535
* @default 'neutral'
3636
*/
37-
variant: 'accent' | 'informative' | 'neutral' | 'positive' | 'notice' | 'negative' | 'gray' | 'red' | 'orange' | 'yellow' | 'charteuse' | 'celery' | 'green' | 'seafoam' | 'cyan' | 'blue' | 'indigo' | 'purple' | 'fuchsia' | 'magenta' | 'pink' | 'turquoise' | 'brown' | 'cinnamon' | 'silver'
37+
variant?: 'accent' | 'informative' | 'neutral' | 'positive' | 'notice' | 'negative' | 'gray' | 'red' | 'orange' | 'yellow' | 'charteuse' | 'celery' | 'green' | 'seafoam' | 'cyan' | 'blue' | 'indigo' | 'purple' | 'fuchsia' | 'magenta' | 'pink' | 'turquoise' | 'brown' | 'cinnamon' | 'silver',
38+
/**
39+
* The fill of the badge.
40+
* @default 'bold'
41+
*/
42+
fillStyle?: 'bold' | 'subtle' | 'outline'
3843
}
3944

4045
export interface BadgeProps extends DOMProps, AriaLabelingProps, StyleProps, BadgeStyleProps, SlotProps {
@@ -73,42 +78,100 @@ const badge = style<BadgeStyleProps>({
7378
},
7479
columnGap: 'text-to-visual',
7580
color: {
76-
default: 'white',
77-
variant: {
78-
notice: 'black',
79-
orange: 'black',
80-
yellow: 'black',
81-
charteuse: 'black',
82-
celery: 'black'
81+
fillStyle: {
82+
bold: {
83+
default: 'white',
84+
variant: {
85+
notice: 'black',
86+
orange: 'black',
87+
yellow: 'black',
88+
charteuse: 'black',
89+
celery: 'black'
90+
}
91+
},
92+
subtle: 'gray-1000',
93+
outline: 'gray-1000'
8394
}
8495
},
8596
backgroundColor: {
86-
variant: {
87-
accent: 'accent',
88-
informative: 'informative',
89-
neutral: 'neutral-subdued',
90-
positive: 'positive',
91-
notice: 'notice',
92-
negative: 'negative',
93-
gray: 'gray',
94-
red: 'red',
95-
orange: 'orange',
96-
yellow: 'yellow',
97-
charteuse: 'chartreuse',
98-
celery: 'celery',
99-
green: 'green',
100-
seafoam: 'seafoam',
101-
cyan: 'cyan',
102-
blue: 'blue',
103-
indigo: 'indigo',
104-
purple: 'purple',
105-
fuchsia: 'fuchsia',
106-
magenta: 'magenta',
107-
pink: 'pink',
108-
turquoise: 'turquoise',
109-
brown: 'brown',
110-
cinnamon: 'cinnamon',
111-
silver: 'silver'
97+
fillStyle: {
98+
bold: {
99+
variant: {
100+
accent: 'accent',
101+
informative: 'informative',
102+
neutral: 'neutral-subdued',
103+
positive: 'positive',
104+
notice: 'notice',
105+
negative: 'negative',
106+
gray: 'gray',
107+
red: 'red',
108+
orange: 'orange',
109+
yellow: 'yellow',
110+
charteuse: 'chartreuse',
111+
celery: 'celery',
112+
green: 'green',
113+
seafoam: 'seafoam',
114+
cyan: 'cyan',
115+
blue: 'blue',
116+
indigo: 'indigo',
117+
purple: 'purple',
118+
fuchsia: 'fuchsia',
119+
magenta: 'magenta',
120+
pink: 'pink',
121+
turquoise: 'turquoise',
122+
brown: 'brown',
123+
cinnamon: 'cinnamon',
124+
silver: 'silver'
125+
}
126+
},
127+
subtle: {
128+
variant: {
129+
accent: 'accent-200',
130+
informative: 'informative-subtle',
131+
neutral: 'neutral-subtle',
132+
positive: 'positive-subtle',
133+
notice: 'notice-subtle',
134+
negative: 'negative-subtle',
135+
gray: 'gray-100',
136+
red: 'red-200',
137+
orange: 'orange-200',
138+
yellow: 'yellow-200',
139+
charteuse: 'chartreuse-200',
140+
celery: 'celery-200',
141+
green: 'green-200',
142+
seafoam: 'seafoam-200',
143+
cyan: 'cyan-200',
144+
blue: 'blue-200',
145+
indigo: 'indigo-200',
146+
purple: 'purple-200',
147+
fuchsia: 'fuchsia-200',
148+
magenta: 'magenta-200',
149+
pink: 'pink-200',
150+
turquoise: 'turquoise-200',
151+
brown: 'brown-200',
152+
cinnamon: 'cinnamon-200',
153+
silver: 'silver-200'
154+
}
155+
},
156+
outline: 'gray-25'
157+
}
158+
},
159+
borderStyle: 'solid',
160+
boxSizing: 'border-box',
161+
borderWidth: 2,
162+
borderColor: {
163+
default: 'transparent',
164+
fillStyle: {
165+
outline: {
166+
variant: {
167+
accent: 'accent-800',
168+
informative: 'informative-800',
169+
neutral: 'gray-700',
170+
positive: 'positive-700',
171+
notice: 'notice-700',
172+
negative: 'negative-800',
173+
}
174+
}
112175
}
113176
},
114177
'--iconPrimary': {
@@ -123,6 +186,7 @@ function Badge(props: BadgeProps, ref: DOMRef<HTMLDivElement>) {
123186
children,
124187
variant = 'neutral',
125188
size = 'S',
189+
fillStyle = 'bold',
126190
...otherProps
127191
} = props; // useProviderProps(props) in v3
128192
let domRef = useDOMRef(ref);
@@ -140,7 +204,7 @@ function Badge(props: BadgeProps, ref: DOMRef<HTMLDivElement>) {
140204
<span
141205
{...filterDOMProps(otherProps)}
142206
role="presentation"
143-
className={(props.UNSAFE_className || '') + badge({variant, size}, props.styles)}
207+
className={(props.UNSAFE_className || '') + badge({variant, size, fillStyle}, props.styles)}
144208
ref={domRef}>
145209
{
146210
typeof children === 'string' || isTextOnly

0 commit comments

Comments
 (0)