mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-04 06:00:38 +00:00
color scheme: Use the users prefered mode by default (#12227)
* color scheme: Use the users prefered colour scheme if one isn't defined in the store * fix style --------- Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
type MantineColorScheme,
|
|
||||||
type MantineColorSchemeManager,
|
type MantineColorSchemeManager,
|
||||||
isMantineColorScheme
|
isMantineColorScheme
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
@@ -21,10 +20,18 @@ export function localStorageColorSchemeManager({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (
|
const storedValue = window.localStorage.getItem(key);
|
||||||
(window.localStorage.getItem(key) as MantineColorScheme) ||
|
|
||||||
defaultValue
|
// If a value exists in storage, return it
|
||||||
);
|
if (storedValue && isMantineColorScheme(storedValue)) {
|
||||||
|
return storedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no value, check the system preference
|
||||||
|
const systemPrefersDark = window.matchMedia(
|
||||||
|
'(prefers-color-scheme: dark)'
|
||||||
|
).matches;
|
||||||
|
return systemPrefersDark ? 'dark' : 'light';
|
||||||
} catch {
|
} catch {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user