File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { Button } from '@blueprintjs/core'
2
2
3
3
import { useEffect , useState } from 'react'
4
4
5
+ const themeMedia = window . matchMedia ( '(prefers-color-scheme: light)' )
6
+
5
7
export const ThemeSwitchButton = ( ) => {
6
8
const [ theme , setTheme ] = useState ( localStorage . getItem ( 'theme' ) || '' )
7
9
const handleThemeSwitch = ( ) => {
@@ -10,7 +12,11 @@ export const ThemeSwitchButton = () => {
10
12
localStorage . setItem ( 'theme' , isCurrentDark ? 'light' : 'dark' )
11
13
}
12
14
useEffect ( ( ) => {
13
- if ( theme == 'dark' ) {
15
+ if ( ! themeMedia . matches && ! localStorage . getItem ( 'theme' ) ) {
16
+ handleThemeSwitch ( )
17
+ return
18
+ }
19
+ if ( theme === 'dark' ) {
14
20
document . body . classList . add ( 'bp4-dark' )
15
21
document . body . classList . add ( 'dark' )
16
22
} else {
@@ -22,6 +28,6 @@ export const ThemeSwitchButton = () => {
22
28
< Button
23
29
onClick = { handleThemeSwitch }
24
30
icon = { theme === 'dark' ? 'moon' : 'flash' }
25
- > </ Button >
31
+ / >
26
32
)
27
33
}
You can’t perform that action at this time.
0 commit comments