Skip to content

Commit

Permalink
feat(): Allow default setting of mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanCQ committed Dec 20, 2023
1 parent 82bf8eb commit 5a58bf2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/molecules/theme-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof _theme['get']>>({mode: 'system', isDark: false});
type Mode = ReturnType<typeof _theme['get']>['mode']
export const useTheme = (props: {defaultMode?: Mode }) => {
const mode = props.defaultMode ?? "dark"
const [theme, _setTheme] = React.useState<ReturnType<typeof _theme['get']>>({mode, isDark: _theme.isDark(mode)});
React.useEffect(() => {
_theme.subscribe(() => {
_setTheme(_theme.get());
Expand Down
1 change: 1 addition & 0 deletions src/utils/darkMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ export const theme = {
get: getTheme,
set: setTheme,
subscribe: subscribeToTheme,
isDark,
syncTheme: () => subscribeToTheme(syncDOMClass),
};

0 comments on commit 5a58bf2

Please sign in to comment.