2023-09-29 16:01:27 +02:00
|
|
|
// __SDEFILE__ - This file is a dependency for the stand-alone environment
|
2023-11-17 19:44:07 +01:00
|
|
|
import { spectrum, rating, graph } from 'shared/themes/index.mjs'
|
2023-12-05 00:07:33 +02:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2023-07-29 14:21:59 +02:00
|
|
|
export const useTheme = () => {
|
2023-12-05 00:07:33 +02:00
|
|
|
const theme = useLocalStorageState('fs-theme', { defaultValue: preferredTheme })
|
2023-07-29 14:21:59 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
theme: theme[0],
|
|
|
|
setTheme: theme[1],
|
|
|
|
spectrum: spectrum[theme[0]],
|
|
|
|
rating: rating[theme[0]],
|
2023-11-17 19:44:07 +01:00
|
|
|
graph: graph[theme[0]],
|
2023-07-29 14:21:59 +02:00
|
|
|
}
|
|
|
|
}
|