blob: 8ef3a19d50da4472c8244543230558eab2db10a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/**
* Check if the user prefers dark color scheme.
*
* @returns {boolean|undefined} True if `prefers-color-scheme` is set to `dark`.
*/
export const prefersDarkScheme = (): boolean | undefined => {
if (typeof window === 'undefined') return undefined;
return window.matchMedia('(prefers-color-scheme: dark)').matches;
};
/**
* Retrieve the theme to use depending on the user system theme.
*/
export const getThemeFromSystem = () => {
if (prefersDarkScheme()) return 'dark';
return 'light';
};
|