Skip to content

Commit f291e81

Browse files
joshblackjonrohan
andauthoredJan 28, 2025··
fix(BaseStyles): remove unknown props from fallback when feature flag is enabled (#5606)
* refactor(storybook): add feature flags as outermost component * fix(FeatureFlags): merge scope with parent context scope * fix(BaseStyles): remove unknown props from fallback when feature flag is enabled * chore: add changeset * chore: fix eslint violation * test(vrt): update snapshots * chore: add stylelint disables * test(vrt): update snapshots * Revert "test(vrt): update snapshots" This reverts commit f127d0c. * fix(BaseStyles): add data-color-mode support for color-scheme * test(vrt): update snapshots --------- Co-authored-by: joshblack <joshblack@users.noreply.github.com> Co-authored-by: Jon Rohan <yes@jonrohan.codes>
1 parent 50ef6a4 commit f291e81

File tree

32 files changed

+68
-38
lines changed

32 files changed

+68
-38
lines changed
 

‎.changeset/angry-ties-push.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Update BaseStyles to no longer pass system props when feature flag is enabled

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

‎packages/react/.storybook/preview.jsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const preview = {
6262
['*', 'Playground', /Playground$/, 'Features', 'Examples'],
6363
],
6464
],
65-
]
66-
]
65+
],
66+
],
6767
],
6868
'Behaviors',
6969
'Hooks',
@@ -82,8 +82,8 @@ const preview = {
8282
['*', 'Playground', /Playground$/, 'Features', 'Examples'],
8383
],
8484
],
85-
]
86-
]
85+
],
86+
],
8787
],
8888
[
8989
'Private',
@@ -100,8 +100,8 @@ const preview = {
100100
['*', 'Playground', /Playground$/, 'Features', 'Examples'],
101101
],
102102
],
103-
]
104-
]
103+
],
104+
],
105105
],
106106
'*',
107107
]
@@ -257,14 +257,6 @@ export const globalTypes = {
257257
}
258258

259259
export const decorators = [
260-
(Story, context) => {
261-
const {featureFlags} = context.globals
262-
return (
263-
<FeatureFlags flags={featureFlags}>
264-
<Story {...context} />
265-
</FeatureFlags>
266-
)
267-
},
268260
(Story, context) => {
269261
const {colorScheme} = context.globals
270262

@@ -318,6 +310,14 @@ export const decorators = [
318310
</Profiler>
319311
)
320312
},
313+
(Story, context) => {
314+
const {featureFlags} = context.globals
315+
return (
316+
<FeatureFlags flags={featureFlags}>
317+
<Story {...context} />
318+
</FeatureFlags>
319+
)
320+
},
321321
]
322322

323323
export default preview

‎packages/react/src/BaseStyles.module.css

+26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ table {
1717
border-collapse: collapse;
1818
}
1919

20+
[data-color-mode='light'] input {
21+
color-scheme: light;
22+
}
23+
24+
[data-color-mode='dark'] input {
25+
color-scheme: dark;
26+
}
27+
28+
@media (prefers-color-scheme: light) {
29+
[data-color-mode='auto'][data-light-theme*='light'] {
30+
color-scheme: light;
31+
}
32+
}
33+
34+
@media (prefers-color-scheme: dark) {
35+
[data-color-mode='auto'][data-dark-theme*='dark'] {
36+
color-scheme: dark;
37+
}
38+
}
39+
2040
[role='button']:focus:not(:focus-visible):not(.focus-visible),
2141
[role='tabpanel'][tabindex='0']:focus:not(:focus-visible):not(.focus-visible),
2242
button:focus:not(:focus-visible):not(.focus-visible),
@@ -34,6 +54,12 @@ details-dialog:focus:not(:focus-visible):not(.focus-visible) {
3454
/* -------------------------------------------------------------------------- */
3555

3656
.BaseStyles {
57+
font-family: var(--BaseStyles-fontFamily, var(--fontStack-system));
58+
/* stylelint-disable-next-line primer/typography */
59+
line-height: var(--BaseStyles-lineHeight, 1.5);
60+
/* stylelint-disable-next-line primer/colors */
61+
color: var(--BaseStyles-fgColor, var(--fgColor-default));
62+
3763
/* Global styles for light mode */
3864
&:has([data-color-mode='light']) {
3965
input & {

‎packages/react/src/BaseStyles.tsx

+19-20
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,17 @@ export type BaseStylesProps = PropsWithChildren & {
5353
SxProp
5454

5555
function BaseStyles(props: BaseStylesProps) {
56-
const {
57-
children,
58-
color = 'var(--fgColor-default)',
59-
fontFamily = 'normal',
60-
lineHeight = 'default',
61-
className,
62-
as: Component = 'div',
63-
...rest
64-
} = props
65-
56+
const {children, color, fontFamily, lineHeight, className, as: Component = 'div', style, ...rest} = props
6657
const {colorScheme, dayScheme, nightScheme} = useTheme()
6758
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
6859

6960
if (enabled) {
7061
const newClassName = clsx(classes.BaseStyles, className)
62+
const baseStyles = {
63+
['--BaseStyles-fgColor']: color,
64+
['--BaseStyles-fontFamily']: fontFamily,
65+
['--BaseStyles-lineHeight']: lineHeight,
66+
}
7167

7268
// If props includes TYPOGRAPHY or COMMON props, pass them to the Box component
7369
if (includesSystemProps(props)) {
@@ -77,9 +73,6 @@ function BaseStyles(props: BaseStylesProps) {
7773
<Box
7874
as={Component}
7975
className={newClassName}
80-
color={color}
81-
fontFamily={fontFamily}
82-
lineHeight={lineHeight}
8376
data-portal-root
8477
/**
8578
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
@@ -89,7 +82,11 @@ function BaseStyles(props: BaseStylesProps) {
8982
data-color-mode={colorScheme?.includes('dark') ? 'dark' : 'light'}
9083
data-light-theme={dayScheme}
9184
data-dark-theme={nightScheme}
92-
style={systemProps}
85+
style={{
86+
...systemProps,
87+
...baseStyles,
88+
...style,
89+
}}
9390
{...rest}
9491
>
9592
{children}
@@ -100,9 +97,6 @@ function BaseStyles(props: BaseStylesProps) {
10097
return (
10198
<Component
10299
className={newClassName}
103-
color={color}
104-
fontFamily={fontFamily}
105-
lineHeight={lineHeight}
106100
data-portal-root
107101
/**
108102
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
@@ -112,6 +106,10 @@ function BaseStyles(props: BaseStylesProps) {
112106
data-color-mode={colorScheme?.includes('dark') ? 'dark' : 'light'}
113107
data-light-theme={dayScheme}
114108
data-dark-theme={nightScheme}
109+
style={{
110+
...baseStyles,
111+
...style,
112+
}}
115113
{...rest}
116114
>
117115
{children}
@@ -122,9 +120,9 @@ function BaseStyles(props: BaseStylesProps) {
122120
return (
123121
<StyledDiv
124122
className={className}
125-
color={color}
126-
fontFamily={fontFamily}
127-
lineHeight={lineHeight}
123+
color={color ?? 'var(--fgColor-default)'}
124+
fontFamily={fontFamily ?? 'normal'}
125+
lineHeight={lineHeight ?? 'default'}
128126
data-portal-root
129127
/**
130128
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
@@ -134,6 +132,7 @@ function BaseStyles(props: BaseStylesProps) {
134132
data-color-mode={colorScheme?.includes('dark') ? 'dark' : 'light'}
135133
data-light-theme={dayScheme}
136134
data-dark-theme={nightScheme}
135+
style={style}
137136
{...rest}
138137
>
139138
<GlobalStyle colorScheme={colorScheme?.includes('dark') ? 'dark' : 'light'} />
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React, {useMemo} from 'react'
1+
import React, {useContext, useMemo} from 'react'
22
import {FeatureFlagContext} from './FeatureFlagContext'
33
import {FeatureFlagScope, type FeatureFlags} from './FeatureFlagScope'
4-
import {DefaultFeatureFlags} from './DefaultFeatureFlags'
54

65
export type FeatureFlagsProps = React.PropsWithChildren<{
76
flags: FeatureFlags
87
}>
98

109
export function FeatureFlags({children, flags}: FeatureFlagsProps) {
10+
const parentFeatureFlags = useContext(FeatureFlagContext)
1111
const value = useMemo(() => {
12-
const scope = FeatureFlagScope.merge(DefaultFeatureFlags, FeatureFlagScope.create(flags))
12+
const scope = FeatureFlagScope.merge(parentFeatureFlags, FeatureFlagScope.create(flags))
1313
return scope
14-
}, [flags])
14+
}, [parentFeatureFlags, flags])
1515
return <FeatureFlagContext.Provider value={value}>{children}</FeatureFlagContext.Provider>
1616
}

0 commit comments

Comments
 (0)
Please sign in to comment.