mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Extract themeEngine
This commit is contained in:
parent
eb8025791b
commit
c9f42e497a
5 changed files with 30 additions and 28 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import { useState, useCallback } from 'preact/hooks'
|
||||
|
||||
import '~/src/style/themes.css'
|
||||
|
||||
export const themeList = [
|
||||
const themes = [
|
||||
'default',
|
||||
'default-dark',
|
||||
'nord',
|
||||
|
|
@ -9,9 +11,20 @@ export const themeList = [
|
|||
'_raw'
|
||||
]
|
||||
|
||||
export const DEFAULT_THEME = themeList[0]
|
||||
const DEFAULT_THEME = themes[0]
|
||||
|
||||
export const assertTheme = theme =>
|
||||
themeList.includes(theme)
|
||||
const assertTheme = theme =>
|
||||
themes.includes(theme)
|
||||
? theme
|
||||
: DEFAULT_THEME
|
||||
|
||||
export const useThemeEngine = (defaultTheme = DEFAULT_THEME) => {
|
||||
const [currentTheme, setCurrentTheme] =
|
||||
useState(DEFAULT_THEME)
|
||||
|
||||
const setTheme = useCallback(theme => {
|
||||
setCurrentTheme(assertTheme(theme))
|
||||
}, [currentTheme]);
|
||||
|
||||
return { currentTheme, setTheme, themes };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue