1
0
Fork 0
freesewing/sites/shared/hooks/use-theme.mjs

25 lines
737 B
JavaScript
Raw Normal View History

2023-09-29 16:01:27 +02:00
// __SDEFILE__ - This file is a dependency for the stand-alone environment
import { spectrum, rating, graph } from 'shared/themes/index.mjs'
import useLocalStorageState from 'use-local-storage-state'
2023-03-24 16:33:14 +01:00
2023-03-24 21:30:04 +01:00
const preferredTheme = () => {
const prefersDarkMode =
typeof window !== 'undefined' && typeof window.matchMedia === 'function'
? window.matchMedia(`(prefers-color-scheme: dark`).matches
: undefined
return prefersDarkMode ? 'dark' : 'light'
}
export const useTheme = () => {
const theme = useLocalStorageState('fs-theme', { defaultValue: preferredTheme })
return {
theme: theme[0],
setTheme: theme[1],
spectrum: spectrum[theme[0]],
rating: rating[theme[0]],
graph: graph[theme[0]],
}
}