diff --git a/src/molecules/theme-selector.tsx b/src/molecules/theme-selector.tsx index fbe0e1a..cbbd0f3 100644 --- a/src/molecules/theme-selector.tsx +++ b/src/molecules/theme-selector.tsx @@ -4,8 +4,10 @@ import React from "react"; import { Button } from "src/atoms/button"; import { theme as _theme } from "src/utils"; -export const useTheme = () => { - const [theme, _setTheme] = React.useState>({mode: 'system', isDark: false}); +type Mode = ReturnType['mode'] +export const useTheme = (props: {defaultMode?: Mode }) => { + const mode = props.defaultMode ?? "dark" + const [theme, _setTheme] = React.useState>({mode, isDark: _theme.isDark(mode)}); React.useEffect(() => { _theme.subscribe(() => { _setTheme(_theme.get()); diff --git a/src/utils/darkMode.ts b/src/utils/darkMode.ts index c3d15e4..c6febe4 100644 --- a/src/utils/darkMode.ts +++ b/src/utils/darkMode.ts @@ -58,5 +58,6 @@ export const theme = { get: getTheme, set: setTheme, subscribe: subscribeToTheme, + isDark, syncTheme: () => subscribeToTheme(syncDOMClass), };