mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2025-04-26 15:09:53 +03:00
feat(theme): add support to auto
theme whith media query
This commit is contained in:
parent
8c402442c2
commit
e4369f4ec9
1 changed files with 11 additions and 1 deletions
|
@ -31,8 +31,18 @@ const normalizeKey = (k) =>
|
|||
.toLowerCase()
|
||||
.replace(/^theme-/, '');
|
||||
|
||||
const preferDarkMode = ({ theme }) => {
|
||||
if (theme === 'auto') {
|
||||
if (typeof window.matchMedia === 'function') {
|
||||
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
return prefersDarkScheme && prefersDarkScheme.matches;
|
||||
}
|
||||
}
|
||||
return theme === 'dark';
|
||||
};
|
||||
|
||||
export const loadTheme = (props, style) => {
|
||||
THEME = props.theme == 'dark' ? DARK_THEME : LIGHT_THEME;
|
||||
THEME = preferDarkMode(props) ? DARK_THEME : LIGHT_THEME;
|
||||
Object.entries(props)
|
||||
.filter(([k, v]) => v && /^theme[A-Z]/.test(k))
|
||||
.map(([k, v]) => [normalizeKey(k), v])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue