forked from blocks/blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme-editor.js
More file actions
134 lines (128 loc) · 2.92 KB
/
Copy paththeme-editor.js
File metadata and controls
134 lines (128 loc) · 2.92 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/** @jsx jsx */
import { useState } from 'react'
import { ThemeProvider, css } from 'theme-ui'
import { jsx, Global } from '@emotion/core'
import { EditProvider, FieldSet } from '@styled-system/edit'
import ColorFillIcon from '@material-ui/icons/FormatColorFill'
import CloseIcon from '@material-ui/icons/Close'
const demoFonts = [
'system-ui, sans-serif',
'"Avenir Next", sans-serif',
'Georgia, serif',
'Baskerville, serif',
'Menlo, monospace',
'Roboto, sans-serif',
'"Roboto Condensed", sans-serif',
'Poppins, sans-serif',
'Montserrat, sans-serif',
'Merriweather, serif'
]
const IconButton = props => (
<button
{...props}
css={{
display: 'block',
position: 'fixed',
top: 0,
right: 0,
margin: 8,
color: 'inherit',
backgroundColor: 'transparent',
border: 0,
padding: 4,
'&:focus': {
outline: '2px solid',
color: 'primary'
}
}}
/>
)
const ThemeEditor = props => {
const [edit, setEdit] = useState(false)
if (!edit) {
return (
<IconButton
title="Edit Theme"
onClick={e => {
setEdit(true)
}}
>
<ColorFillIcon />
</IconButton>
)
}
return (
<div>
<div
css={css({
position: 'fixed',
top: 0,
right: 0,
bottom: 0,
overflowY: 'auto',
width: 256,
px: 16,
pt: 48,
color: 'black',
bg: '#f6f6fc'
})}
>
<FieldSet name="colors" type="color" />
<FieldSet name="fonts" type="select" options={demoFonts} />
<FieldSet
name="fontWeights"
type="number"
step="100"
min="100"
max="900"
/>
<FieldSet
name="lineHeights"
type="number"
step={1 / 16}
min={1}
max={2}
/>
</div>
<IconButton
title="Close Theme Editor"
onClick={e => {
setEdit(false)
}}
>
<CloseIcon />
</IconButton>
</div>
)
}
export default (opts = {}) => ({
renderEditor: (props, editor, next) => {
const children = next()
const { theme, components } = props
return (
<ThemeProvider components={components} theme={theme}>
<EditProvider>
{children}
{null && <ThemeEditor />}
<Global
styles={css({
'*': {
boxSizing: 'border-box'
},
body: {
m: 0,
fontFamily: 'system-ui, sans-serif',
lineHeight: 1.5,
color: 'text',
bg: 'background',
transitionProperty: 'background-color',
transitionTimingFunction: 'ease-out',
transitionDuration: '.4s'
}
})}
/>
</EditProvider>
</ThemeProvider>
)
}
})