-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathindex.tsx
58 lines (50 loc) · 1.36 KB
/
index.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
57
58
import React from 'react'
import {
jsx,
useThemeUI,
ThemeProvider as CoreProvider,
ThemeProviderProps as CoreThemeProviderProps,
__themeUiDefaultContextValue,
} from '@theme-ui/core'
import { css, Theme } from '@theme-ui/css'
import { ColorModeProvider } from '@theme-ui/color-modes'
import { Global } from '@emotion/react'
const RootStyles = () =>
jsx(Global, {
styles: (emotionTheme: unknown) => {
const theme = emotionTheme as Theme
const { useRootStyles } = theme.config || theme
if (useRootStyles === false || (theme.styles && !theme.styles.root)) {
return null
}
const boxSizing =
theme.config?.useBorderBox === false ? undefined : 'border-box'
return css({
'*': {
boxSizing,
},
html: {
variant: 'styles.root',
},
body: {
margin: 0,
},
})(theme)
},
})
export interface ThemeProviderProps
extends Pick<CoreThemeProviderProps, 'theme'> {
children?: React.ReactNode
}
export const ThemeUIProvider = ({ theme, children }: ThemeProviderProps) => {
const outer = useThemeUI()
const isTopLevel = outer === __themeUiDefaultContextValue
return (
<CoreProvider theme={theme}>
<ColorModeProvider>
{isTopLevel && <RootStyles />}
{children}
</ColorModeProvider>
</CoreProvider>
)
}