11import React , { type CSSProperties , type PropsWithChildren } from 'react'
22import { clsx } from 'clsx'
3- import styled , { createGlobalStyle } from 'styled-components'
43import type { SystemCommonProps , SystemTypographyProps } from './constants'
5- import { COMMON , TYPOGRAPHY } from './constants'
64import { useTheme } from './ThemeProvider'
7- import { useFeatureFlag } from './FeatureFlags'
8- import Box from './Box'
95import type { SxProp } from './sx'
10- import { includesSystemProps , getTypographyAndCommonProps } from './utils/includeSystemProps'
116
127import classes from './BaseStyles.module.css'
138
14- // load polyfill for :focus-visible
159import 'focus-visible'
16-
17- const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'
18-
19- const GlobalStyle = createGlobalStyle < { colorScheme ?: 'light' | 'dark' } > `
20- * { box-sizing: border-box; }
21- body { margin: 0; }
22- table { border-collapse: collapse; }
23- input { color-scheme: ${ props => props . colorScheme } ; }
24-
25- [role="button"]:focus:not(:focus-visible):not(.focus-visible),
26- [role="tabpanel"][tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
27- button:focus:not(:focus-visible):not(.focus-visible),
28- summary:focus:not(:focus-visible):not(.focus-visible),
29- a:focus:not(:focus-visible):not(.focus-visible) {
30- outline: none;
31- box-shadow: none;
32- }
33-
34- [tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
35- details-dialog:focus:not(:focus-visible):not(.focus-visible) {
36- outline: none;
37- }
38- `
39-
40- const StyledDiv = styled . div < SystemTypographyProps & SystemCommonProps > `
41- ${ TYPOGRAPHY } ;
42- ${ COMMON } ;
43- `
10+ import { BoxWithFallback } from './internal/components/BoxWithFallback'
4411
4512export type BaseStylesProps = PropsWithChildren & {
4613 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -52,77 +19,29 @@ export type BaseStylesProps = PropsWithChildren & {
5219 SystemCommonProps &
5320 SxProp
5421
55- function BaseStyles ( props : BaseStylesProps ) {
56- const { children, color, fontFamily, lineHeight, className, as : Component = 'div' , style, ...rest } = props
22+ function BaseStyles ( {
23+ children,
24+ color,
25+ fontFamily,
26+ lineHeight,
27+ className,
28+ as : Component = 'div' ,
29+ style,
30+ ...rest
31+ } : BaseStylesProps ) {
5732 const { colorMode, colorScheme, dayScheme, nightScheme} = useTheme ( )
58- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
59-
60- if ( enabled ) {
61- const newClassName = clsx ( classes . BaseStyles , className )
62- const baseStyles = {
63- [ '--BaseStyles-fgColor' ] : color ,
64- [ '--BaseStyles-fontFamily' ] : fontFamily ,
65- [ '--BaseStyles-lineHeight' ] : lineHeight ,
66- }
67-
68- // If props includes TYPOGRAPHY or COMMON props, pass them to the Box component
69- if ( includesSystemProps ( props ) ) {
70- const systemProps = getTypographyAndCommonProps ( props )
71- return (
72- // @ts -ignore shh
73- < Box
74- as = { Component }
75- className = { newClassName }
76- data-portal-root
77- /**
78- * We need to map valid primer/react color modes onto valid color modes for primer/primitives
79- * valid color modes for primer/primitives: auto | light | dark
80- * valid color modes for primer/primer: auto | day | night | light | dark
81- */
82- data-color-mode = { colorMode === 'auto' ? 'auto' : colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' }
83- data-light-theme = { dayScheme }
84- data-dark-theme = { nightScheme }
85- style = { {
86- ...systemProps ,
87- ...baseStyles ,
88- ...style ,
89- } }
90- { ...rest }
91- >
92- { children }
93- </ Box >
94- )
95- }
9633
97- return (
98- < Component
99- className = { newClassName }
100- data-portal-root
101- /**
102- * We need to map valid primer/react color modes onto valid color modes for primer/primitives
103- * valid color modes for primer/primitives: auto | light | dark
104- * valid color modes for primer/primer: auto | day | night | light | dark
105- */
106- data-color-mode = { colorMode === 'auto' ? 'auto' : colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' }
107- data-light-theme = { dayScheme }
108- data-dark-theme = { nightScheme }
109- style = { {
110- ...baseStyles ,
111- ...style ,
112- } }
113- { ...rest }
114- >
115- { children }
116- </ Component >
117- )
34+ const newClassName = clsx ( classes . BaseStyles , className )
35+ const baseStyles = {
36+ [ '--BaseStyles-fgColor' ] : color ,
37+ [ '--BaseStyles-fontFamily' ] : fontFamily ,
38+ [ '--BaseStyles-lineHeight' ] : lineHeight ,
11839 }
11940
12041 return (
121- < StyledDiv
122- className = { className }
123- color = { color ?? 'var(--fgColor-default)' }
124- fontFamily = { fontFamily ?? 'normal' }
125- lineHeight = { lineHeight ?? 'default' }
42+ < BoxWithFallback
43+ as = { Component }
44+ className = { newClassName }
12645 data-portal-root
12746 /**
12847 * We need to map valid primer/react color modes onto valid color modes for primer/primitives
@@ -132,12 +51,14 @@ function BaseStyles(props: BaseStylesProps) {
13251 data-color-mode = { colorMode === 'auto' ? 'auto' : colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' }
13352 data-light-theme = { dayScheme }
13453 data-dark-theme = { nightScheme }
135- style = { style }
54+ style = { {
55+ ...baseStyles ,
56+ ...style ,
57+ } }
13658 { ...rest }
13759 >
138- < GlobalStyle colorScheme = { colorScheme ?. includes ( 'dark' ) ? 'dark' : 'light' } />
13960 { children }
140- </ StyledDiv >
61+ </ BoxWithFallback >
14162 )
14263}
14364
0 commit comments