forked from ebouJ/devhub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeSwitcher.tsx
More file actions
62 lines (52 loc) · 1.42 KB
/
ThemeSwitcher.tsx
File metadata and controls
62 lines (52 loc) · 1.42 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
import classNames from 'classnames'
import React from 'react'
import { useTheme } from '../../context/ThemeContext'
export interface ThemeSwitcherProps {}
export function ThemeSwitcher(props: ThemeSwitcherProps) {
const {} = props
const { theme, toggleTheme } = useTheme()
return (
<button
id="theme-switcher"
type="button"
className="theme-switcher relative flex-shrink-0 w-10 bg-less-2 rounded-full focus:outline-none"
onClick={() => {
toggleTheme()
}}
role="button"
aria-label="Toggle theme"
>
<div
className={classNames(
'theme-switcher-thumb absolute shadow rounded-full',
theme.isDark ? 'dark bg-purple' : 'light bg-yellow',
)}
>
<div className="absolute inset-0 flex items-center justify-center rounded-full bg-white opacity-25" />
</div>
<style jsx>
{`
.theme-switcher {
height: 1rem;
margin-left: 0.2rem;
margin-right: 0.2rem;
}
.theme-switcher-thumb {
top: -0.2rem;
bottom: -0.2rem;
width: 1.4rem;
}
.theme-switcher-thumb.light {
left: -0.2rem;
}
.theme-switcher-thumb.dark {
left: 1.3rem;
}
.theme-switcher-thumb > div {
margin: 2px;
}
`}
</style>
</button>
)
}