11import React from 'react'
2+ import { clsx } from 'clsx'
23import styled , { createGlobalStyle } from 'styled-components'
4+ import type { ComponentProps } from './utils/types'
35import type { SystemCommonProps , SystemTypographyProps } from './constants'
46import { COMMON , TYPOGRAPHY } from './constants'
57import { 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'
711
812// load polyfill for :focus-visible
913import 'focus-visible'
1014
15+ const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'
16+
1117const GlobalStyle = createGlobalStyle < { colorScheme ?: 'light' | 'dark' } > `
1218 * { box-sizing: border-box; }
1319 body { margin: 0; }
@@ -29,27 +35,34 @@ const GlobalStyle = createGlobalStyle<{colorScheme?: 'light' | 'dark'}>`
2935 }
3036`
3137
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+ )
3646
3747export type BaseStylesProps = ComponentProps < typeof Base >
3848
3949function 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
4151
4252 const { colorScheme, dayScheme, nightScheme} = useTheme ( )
53+ const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
54+
55+ const stylingProps = enabled ? { className : clsx ( classes . BaseStyles , className ) } : { className}
4356
4457 /**
4558 * We need to map valid primer/react color modes onto valid color modes for primer/primitives
4659 * valid color modes for primer/primitives: auto | light | dark
4760 * valid color modes for primer/primer: auto | day | night | light | dark
4861 */
49-
5062 return (
5163 < Base
5264 { ...rest }
65+ { ...stylingProps }
5366 color = { color }
5467 fontFamily = { fontFamily }
5568 lineHeight = { lineHeight }
@@ -58,7 +71,7 @@ function BaseStyles(props: BaseStylesProps) {
5871 data-light-theme = { dayScheme }
5972 data-dark-theme = { nightScheme }
6073 >
61- < GlobalStyle colorScheme = { colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' } />
74+ { ! enabled && < GlobalStyle colorScheme = { colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' } /> }
6275 { children }
6376 </ Base >
6477 )
0 commit comments