forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseStyles.tsx
56 lines (46 loc) · 1.6 KB
/
BaseStyles.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react'
import styled, {createGlobalStyle} from 'styled-components'
import {COMMON, SystemCommonProps, SystemTypographyProps, TYPOGRAPHY} from './constants'
import {useTheme} from './ThemeProvider'
import {ComponentProps} from './utils/types'
const GlobalStyle = createGlobalStyle<{colorScheme?: 'light' | 'dark'}>`
* { box-sizing: border-box; }
body { margin: 0; }
table { border-collapse: collapse; }
input { color-scheme: ${props => props.colorScheme}; }
[role="button"]:focus:not(:focus-visible):not(.focus-visible),
[role="tabpanel"][tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
button:focus:not(:focus-visible):not(.focus-visible),
summary:focus:not(:focus-visible):not(.focus-visible),
a:focus:not(:focus-visible):not(.focus-visible) {
outline: none;
box-shadow: none;
}
[tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
details-dialog:focus:not(:focus-visible):not(.focus-visible) {
outline: none;
}
`
const Base = styled.div<SystemTypographyProps & SystemCommonProps>`
${TYPOGRAPHY};
${COMMON};
`
export type BaseStylesProps = ComponentProps<typeof Base>
function BaseStyles(props: BaseStylesProps) {
const {children, ...rest} = props
const {colorScheme} = useTheme()
// load polyfill for :focus-visible
require('focus-visible')
return (
<Base {...rest} data-portal-root>
<GlobalStyle colorScheme={colorScheme?.includes('dark') ? 'dark' : 'light'} />
{children}
</Base>
)
}
BaseStyles.defaultProps = {
color: 'fg.default',
fontFamily: 'normal',
lineHeight: 'default'
}
export default BaseStyles