@@ -2,17 +2,24 @@ import React, { useState } from 'react'
2
2
import { Button } from './ui/button'
3
3
import { createRandomTheme } from '../lib/create-theme-config'
4
4
import { useTheme } from 'next-themes'
5
- import { getComputedHSLColor , setColorsProperties } from '../lib/utils'
5
+ import { getComputedHSLColor , saveTheme , setColorsProperties } from '../lib/utils'
6
6
import { Dices , Lock , UnLock } from './icons' ;
7
+ import { ReadonlyThemeWithHSLColor , SystemThemes , themeModes } from '../lib/theme'
7
8
8
9
function RandomBtn ( ) {
9
- const { systemTheme } = useTheme ( )
10
+ const { resolvedTheme = "" + undefined , systemTheme= "dark" } = useTheme ( ) ;
10
11
const [ lockPrimary , setLockPrimary ] = useState ( true ) ;
11
12
const onClickHandler = ( ) => {
12
- const themes = createRandomTheme ( lockPrimary ? getComputedHSLColor ( "--primary" ) : undefined )
13
- const theme = themes [ systemTheme ! ] ?? themes . dark
14
- // const theme = themes.dark
15
- console . log ( theme )
13
+ const themes = createRandomTheme ( lockPrimary ? getComputedHSLColor ( "--primary" ) : undefined )
14
+ let theme ;
15
+
16
+ if ( SystemThemes . includes ( resolvedTheme as any ) ) {
17
+ theme = themes [ resolvedTheme as themeModes ] as ReadonlyThemeWithHSLColor [ ] ;
18
+ SystemThemes . forEach ( theme => saveTheme ( resolvedTheme , themes [ theme ] ) ) // save both themes
19
+ } else {
20
+ theme = themes [ systemTheme ] as ReadonlyThemeWithHSLColor [ ] ;
21
+ saveTheme ( resolvedTheme , theme )
22
+ }
16
23
setColorsProperties ( theme )
17
24
}
18
25
const LockIcon = lockPrimary ? Lock : UnLock
0 commit comments