Skip to content

Commit b480c53

Browse files
authored
chore(fuselage): Surfaces variation to box prop (#844)
1 parent 39d8028 commit b480c53

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

packages/fuselage/src/components/Box/props.stories.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ The `is` prop allows `Box` to render any component capable of handling common DO
146146
<Box color='danger-500' />
147147
<Box color='danger-500-50' />
148148
<Box color='surface' />
149+
<Box color='surface-light' />
150+
<Box color='surface-tint' />
151+
<Box color='surface-neutral' />
149152
<Box color='default' />
150153
<Box color='info' />
151154
<Box color='hint' />
@@ -197,6 +200,9 @@ The `is` prop allows `Box` to render any component capable of handling common DO
197200
<Box bg='danger-500' />
198201
<Box bg='danger-500-50' />
199202
<Box bg='surface' />
203+
<Box bg='surface-light' />
204+
<Box bg='surface-tint' />
205+
<Box bg='surface-neutral' />
200206
<Box bg='default' />
201207
<Box bg='info' />
202208
<Box bg='hint' />

packages/fuselage/src/styleTokens.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const getForegroundColor = (
138138
const paletteColorRegex =
139139
/^(neutral|primary|info|success|warning|danger)-(\d+)(-(\d+))?$/;
140140

141+
const cssSupportsVariable = cssSupports('(--foo: bar)');
141142
export const color = memoize((value) => {
142143
if (typeof value !== 'string') {
143144
return;
@@ -159,25 +160,40 @@ export const color = memoize((value) => {
159160

160161
const [customProperty, color] = getPaletteColor(type, grade, alpha);
161162

162-
if (customProperty && cssSupports('(--foo: bar)')) {
163+
if (customProperty && cssSupportsVariable) {
163164
return `var(${customProperty}, ${color})`;
164165
}
165166

166167
return color;
167168
}
168169

169-
if (value === 'surface') {
170-
if (cssSupports('(--foo: bar)')) {
171-
return 'var(--rcx-color-surface, white)';
170+
if (value === 'surface' || value === 'surface-light') {
171+
if (cssSupportsVariable) {
172+
return `var(--rcx-color-surface-light, ${tokenColors.white})`;
172173
}
173174

174-
return 'white';
175+
return tokenColors.white;
176+
}
177+
178+
if (value === 'surface-tint') {
179+
if (cssSupportsVariable) {
180+
return `var(--rcx-color-surface-tint, ${tokenColors.n100})`;
181+
}
182+
183+
return tokenColors.n100;
184+
}
185+
186+
if (value === 'surface-neutral') {
187+
if (cssSupportsVariable) {
188+
return `var(--rcx-color-surface-neutral, ${tokenColors.n400})`;
189+
}
190+
return tokenColors.n400;
175191
}
176192

177193
if (isForegroundColorRef(value)) {
178194
const [customProperty, color] = getForegroundColor(value);
179195

180-
if (customProperty && cssSupports('(--foo: bar)')) {
196+
if (customProperty && cssSupportsVariable) {
181197
return `var(${customProperty}, ${color})`;
182198
}
183199

@@ -237,7 +253,7 @@ export const fontFamily = memoize((value: unknown): string | undefined => {
237253
.map((fontFace) => (fontFace.includes(' ') ? `'${fontFace}'` : fontFace))
238254
.join(', ');
239255

240-
if (cssSupports('(--foo: bar)')) {
256+
if (cssSupportsVariable) {
241257
return `var(--rcx-font-family-${value}, ${fontFamily})`;
242258
}
243259

0 commit comments

Comments
 (0)