-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathThemeSetter.js
58 lines (51 loc) · 1.31 KB
/
ThemeSetter.js
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, { useContext } from 'react'
import T from 'prop-types'
import { createGlobalStyle, ThemeProvider } from 'styled-components'
import { Normalize } from 'styled-normalize'
import fontFaces from '../../theme/fontFaces'
import defaultTheme from '../../theme/theme.js'
function ThemeSetter({ theme = defaultTheme, children }) {
// Ensure we don't add global styles twice
if (useContext(ThemeProvider)) {
throw new Error(
'ThemeSetter cannot be nested inside another ThemeProvider or itself'
)
}
const GlobalFontFaceStyles = createGlobalStyle`
${fontFaces.join('')}
`
// TODO: make line height smarter
const GlobalDefaults = createGlobalStyle`
* {
box-sizing: border-box;
}
body {
font-family: 'plex-sans, sans-serif';
}
p, li, h1, h2, h3, h4, h5, h6 {
color: ${({ theme }) => theme.color('text', 1)};
}
button {
padding: 0;
margin : 0;
border: none;
background: transparent;
line-height: inherit;
color: inherit;
text-align: inherit;
}
`
return (
<ThemeProvider theme={theme}>
<Normalize />
<GlobalFontFaceStyles />
<GlobalDefaults />
{children}
</ThemeProvider>
)
}
ThemeSetter.propTypes = {
children: T.node,
theme: T.object,
}
export default ThemeSetter