Skip to content

Commit

Permalink
feat(getCurrentTheme): auto detect prefered theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Aug 27, 2023
1 parent fd64e20 commit 2985773
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export const isOnlyOneBitIsSet = (b: number): number | boolean => {
}
const THEME_STORAGE_KEY = 'z2m-theme';

export const getCurrentTheme = (): Theme => local.getItem<Theme>(THEME_STORAGE_KEY) ?? 'light';
export const getCurrentTheme = (): Theme => {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
return local.getItem<Theme>(THEME_STORAGE_KEY) ?? prefersDark ? 'dark' : 'light';
};
export const saveCurrentTheme = (theme: string): void => local.setItem(THEME_STORAGE_KEY, theme);


Expand Down

0 comments on commit 2985773

Please sign in to comment.