1
1
import React from 'react'
2
+ import { clsx } from 'clsx'
2
3
import styled , { createGlobalStyle } from 'styled-components'
4
+ import type { ComponentProps } from './utils/types'
3
5
import type { SystemCommonProps , SystemTypographyProps } from './constants'
4
6
import { COMMON , TYPOGRAPHY } from './constants'
5
7
import { useTheme } from './ThemeProvider'
6
- import type { ComponentProps } from './utils/types'
8
+ import { useFeatureFlag } from './FeatureFlags'
9
+ import { toggleStyledComponent } from './internal/utils/toggleStyledComponent'
10
+ import classes from './BaseStyles.module.css'
7
11
8
12
// load polyfill for :focus-visible
9
13
import 'focus-visible'
10
14
15
+ const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'
16
+
11
17
const GlobalStyle = createGlobalStyle < { colorScheme ?: 'light' | 'dark' } > `
12
18
* { box-sizing: border-box; }
13
19
body { margin: 0; }
@@ -29,27 +35,34 @@ const GlobalStyle = createGlobalStyle<{colorScheme?: 'light' | 'dark'}>`
29
35
}
30
36
`
31
37
32
- const Base = styled . div < SystemTypographyProps & SystemCommonProps > `
33
- ${ TYPOGRAPHY } ;
34
- ${ COMMON } ;
35
- `
38
+ const Base = toggleStyledComponent (
39
+ CSS_MODULES_FEATURE_FLAG ,
40
+ 'div' ,
41
+ styled . div < SystemTypographyProps & SystemCommonProps > `
42
+ ${ TYPOGRAPHY } ;
43
+ ${ COMMON } ;
44
+ ` ,
45
+ )
36
46
37
47
export type BaseStylesProps = ComponentProps < typeof Base >
38
48
39
49
function BaseStyles ( props : BaseStylesProps ) {
40
- const { children, color = 'fg.default' , fontFamily = 'normal' , lineHeight = 'default' , ...rest } = props
50
+ const { children, color = 'fg.default' , fontFamily = 'normal' , lineHeight = 'default' , className , ...rest } = props
41
51
42
52
const { colorScheme, dayScheme, nightScheme} = useTheme ( )
53
+ const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
54
+
55
+ const stylingProps = enabled ? { className : clsx ( classes . BaseStyles , className ) } : { className}
43
56
44
57
/**
45
58
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
46
59
* valid color modes for primer/primitives: auto | light | dark
47
60
* valid color modes for primer/primer: auto | day | night | light | dark
48
61
*/
49
-
50
62
return (
51
63
< Base
52
64
{ ...rest }
65
+ { ...stylingProps }
53
66
color = { color }
54
67
fontFamily = { fontFamily }
55
68
lineHeight = { lineHeight }
@@ -58,7 +71,7 @@ function BaseStyles(props: BaseStylesProps) {
58
71
data-light-theme = { dayScheme }
59
72
data-dark-theme = { nightScheme }
60
73
>
61
- < GlobalStyle colorScheme = { colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' } />
74
+ { ! enabled && < GlobalStyle colorScheme = { colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' } /> }
62
75
{ children }
63
76
</ Base >
64
77
)
0 commit comments