@@ -27,17 +27,17 @@ function useMediaQuery(setThemeState: SetStateAction<ThemeState>) {
27
27
} , [ setThemeState ] ) ;
28
28
}
29
29
30
- interface LoadSyncedStateProps extends ThemeSwitcherProps {
30
+ export interface LoadSyncedStateProps extends ThemeSwitcherProps {
31
31
setThemeState : SetStateAction < ThemeState > ;
32
32
}
33
33
34
- function parseState ( str ?: string | null ) {
35
- const [ theme , colorSchemePreference , systemColorScheme ] = ( str ?? ",system,light" ) . split ( "," ) as [
34
+ function parseState ( str ?: string | null ) : ThemeState {
35
+ const parts = ( str ?? ",system,light" ) . split ( "," ) as [
36
36
string ,
37
37
ColorSchemePreference ,
38
38
"light" | "dark" ,
39
39
] ;
40
- return { theme, colorSchemePreference, systemColorScheme } ;
40
+ return { theme : parts [ 0 ] , colorSchemePreference : parts [ 1 ] , systemColorScheme : parts [ 2 ] } ;
41
41
}
42
42
43
43
function useLoadSyncedState ( { dontSync, targetId, setThemeState } : LoadSyncedStateProps ) {
@@ -76,7 +76,7 @@ function modifyTransition(themeTransition = "none") {
76
76
} ;
77
77
}
78
78
79
- interface UpdateDOMProps {
79
+ export interface UpdateDOMProps {
80
80
targetId ?: string ;
81
81
themeState : ThemeState ;
82
82
}
@@ -113,6 +113,7 @@ export function ThemeSwitcher({ targetId, dontSync, themeTransition }: ThemeSwit
113
113
114
114
useLoadSyncedState ( { dontSync, targetId, setThemeState } ) ;
115
115
116
+ /** update DOM and storage */
116
117
React . useEffect ( ( ) => {
117
118
const restoreTransitions = modifyTransition ( themeTransition ) ;
118
119
const shoulCreateCookie = updateDOM ( { targetId, themeState } ) ;
0 commit comments