-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeToggle.tsx
73 lines (65 loc) · 1.57 KB
/
ThemeToggle.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Mode } from '@mui/system/cssVars/useCurrentColorScheme'
import {
LightModeOutlined,
DarkModeOutlined,
LaptopOutlined,
} from '@mui/icons-material'
import { ToggleButtonGroup, Button, Box } from '@mui/joy'
import React from 'react'
import { getCurrentThemeMode, setThemeMode } from '@/constants/theme'
type ThemeToggleProps = object
interface ThemeToggleState {
mode: Mode
}
export class ThemeToggle extends React.Component<ThemeToggleProps, ThemeToggleState> {
constructor(props: ThemeToggleProps) {
super(props)
this.state = {
mode: getCurrentThemeMode(),
}
}
private onChange = (_: React.MouseEvent, newThemeMode: Mode | null) => {
if (!newThemeMode) {
return
}
setThemeMode(newThemeMode)
this.setState({
mode: newThemeMode,
})
}
render(): React.ReactNode {
const ELEMENTID = 'select-theme-mode'
const { mode } = this.state
return (
<Box sx={{
mt: 1,
}}>
<ToggleButtonGroup
id={ELEMENTID}
variant='outlined'
value={mode}
onChange={this.onChange}
>
<Button
startDecorator={<LightModeOutlined />}
value='light'
>
Light
</Button>
<Button
startDecorator={<DarkModeOutlined />}
value='dark'
>
Dark
</Button>
<Button
startDecorator={<LaptopOutlined />}
value='system'
>
System
</Button>
</ToggleButtonGroup>
</Box>
)
}
}