Set default theme to the user's browser theme (#69)

This commit is contained in:
Nash 2022-11-09 20:25:30 +03:00 committed by GitHub
parent 544765af3e
commit b93be5a846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,8 @@ import { ThemeProvider as SCThemeProvider } from 'styled-components';
export const ThemeContext = createContext(); export const ThemeContext = createContext();
export const ThemeProvider = (props) => { export const ThemeProvider = (props) => {
const [storedTheme, setStoredTheme] = useLocalStorage('bruno.theme', 'light'); const isBrowserThemeLight = window.matchMedia("(prefers-color-scheme: light)").matches;
const [storedTheme, setStoredTheme] = useLocalStorage('bruno.theme', isBrowserThemeLight ? 'light' : 'dark');
const theme = themes[storedTheme]; const theme = themes[storedTheme];
const themeOptions = Object.keys(themes); const themeOptions = Object.keys(themes);