forked from system-ui/theme-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypography-layout.js
More file actions
80 lines (75 loc) · 1.74 KB
/
typography-layout.js
File metadata and controls
80 lines (75 loc) · 1.74 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** @jsx jsx */
import { jsx, ThemeProvider, Flex } from 'theme-ui'
import { Themed } from "@theme-ui/mdx"
import { useState } from 'react'
import { toTheme } from '@theme-ui/typography'
import GoogleFonts from './google-fonts'
import Button from './button'
import themes from './typography-themes'
import typographyThemes from './typography-themes'
const themeNames = Object.keys(themes)
const ThemeSelect = (props) => (
<div>
<label
htmlFor={props.name}
sx={{
fontSize: 16,
mr: 2,
}}>
Theme
</label>
<select
id={props.name}
{...props}
sx={{
fontFamily: 'system-ui, sans-serif',
fontSize: 16,
p: 2,
}}>
{themeNames.map((name) => (
<option key={name} label={name} value={name}>
{name}
</option>
))}
</select>
</div>
)
export default (props) => {
const [themeName, setTheme] = useState(themeNames[0])
const typographyTheme = typographyThemes[themeName]
const theme = toTheme(typographyTheme)
theme.styles.h1 = {
fontSize: [5, 5],
}
return (
<div>
<Flex
sx={{
alignItems: 'center',
py: 4,
}}>
<ThemeSelect
name="theme"
value={themeName}
onChange={(e) => {
setTheme(e.target.value)
}}
/>
<Button
sx={{
ml: 2,
}}
onClick={(e) => {
const i = (themeNames.indexOf(themeName) + 1) % themeNames.length
setTheme(themeNames[i])
}}>
Next
</Button>
</Flex>
<ThemeProvider theme={theme}>
<GoogleFonts />
<Themed.root>{props.children}</Themed.root>
</ThemeProvider>
</div>
)
}