File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed
packages/docs/src/components/theme-toggle Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -14,15 +14,12 @@ type ThemeName = 'dark' | 'light' | undefined;
14
14
15
15
export const getTheme = ( ) : ThemeName => {
16
16
let theme ;
17
+ const matchMedia = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ;
17
18
try {
18
19
theme = localStorage . getItem ( themeStorageKey ) ;
20
+ return ( theme as ThemeName ) || matchMedia ;
19
21
} catch {
20
- //
21
- }
22
- if ( theme ) {
23
- return theme as ThemeName ;
24
- } else {
25
- return window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ;
22
+ return matchMedia ;
26
23
}
27
24
} ;
28
25
@@ -41,6 +38,7 @@ export const getThemeSignal = () => {
41
38
} ;
42
39
43
40
export const setTheme = ( theme : ThemeName ) => {
41
+ console . log ( theme ) ;
44
42
if ( ! theme ) {
45
43
localStorage . removeItem ( themeStorageKey ) ;
46
44
theme = getTheme ( ) ;
You can’t perform that action at this time.
0 commit comments