-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththeme.tsx
58 lines (53 loc) · 1.29 KB
/
theme.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 { Box, Flex, Heading, Input, Label } from "@theme-ui/components";
import { useEffect, useState } from "react";
import PageTitle from "ui/PageTitle";
function VariableControl({ variable }: { variable: string }) {
const def = getComputedStyle(document.documentElement).getPropertyValue(
`--theme-ui-colors-${variable}`
);
const [value, setValue] = useState(null);
useEffect(() => {
const s = new Option().style;
s.color = value;
document.documentElement.style.setProperty(
`--theme-ui-colors-${variable}`,
s.color
);
}, [value]);
return (
<Flex
sx={{ alignItems: "center", justifyContent: "center", mb: "1rem" }}
>
<Box
sx={{
backgroundColor: value || def,
width: "3rem",
height: "3rem",
border: "1px #fff solid",
mr: ".5rem",
}}
/>
<Box>
<Label>{variable}</Label>
<Input
placeholder={def}
onChange={(event) => setValue(event.target.value)}
/>
</Box>
</Flex>
);
}
export default function ThemeEditor() {
return (
<Box>
<PageTitle title="Theme editor" />
<Heading mb="1rem" sx={{ textAlign: "center" }}>
Theme
</Heading>
<VariableControl variable="background" />
<VariableControl variable="text" />
<VariableControl variable="muted" />
<VariableControl variable="primary" />
</Box>
);
}