forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheme.tsx
More file actions
39 lines (34 loc) · 945 Bytes
/
Copy pathTheme.tsx
File metadata and controls
39 lines (34 loc) · 945 Bytes
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
/** @jsxRuntime classic */
/** @jsx jsx */
import { jsx, Global } from '@emotion/react';
import { useState, useEffect } from 'react';
import { COLORS, SPACE, TYPE, TYPESCALE } from '../lib/TOKENS';
export function Theme() {
const [theme, setTheme] = useState<keyof typeof COLORS>('light');
useEffect(() => {
// we duplicate the logic of DarkModeBtn here so the flash is shorter
const detectedTheme =
(localStorage.getItem('theme') ||
window.matchMedia('(prefers-color-scheme: dark)').matches ||
'light') === 'dark'
? 'dark'
: 'light';
localStorage.setItem('theme', detectedTheme);
if (detectedTheme !== 'light') {
setTheme(detectedTheme);
}
}, []);
return (
<Global
styles={{
':root': {
...COLORS[theme],
...SPACE,
...TYPE,
...TYPESCALE,
'--wrapper-width': '90rem',
},
}}
/>
);
}