feat(theme): add support for custom themes

This commit is contained in:
Joxit
2023-01-05 22:29:37 +01:00
parent 5983935f84
commit 367ca0380c
8 changed files with 67 additions and 31 deletions

29
src/scripts/theme.js Normal file
View File

@@ -0,0 +1,29 @@
const LIGHT_THEME = {
'primary-text': '#25313b',
'neutral-text': '#777',
'background': '#fff',
'hover-background': '#eee',
};
const DARK_THEME = {
'primary-text': '#8A9EBA',
'neutral-text': '#36527A',
'background': '#22272e',
'hover-background': '#30404D',
};
let THEME;
const normalizeKey = (k) =>
k
.replace(/([A-Z])/g, '-$1')
.toLowerCase()
.replace(/^theme-/, '');
export const loadTheme = (props, style) => {
THEME = props.theme == 'dark' ? DARK_THEME : LIGHT_THEME;
Object.entries(props)
.filter(([k, v]) => v && /^theme[A-Z]/.test(k))
.map(([k, v]) => [normalizeKey(k), v])
.forEach(([k, v]) => (THEME[k] = v));
Object.entries(THEME).forEach(([k, v]) => style.setProperty(`--${k}`, v));
};