Add a function to get the "base" theme for a theme
Useful for trying to load the right assets first. See https://github.com/vector-im/riot-web/pull/11381
This commit is contained in:
parent
eeebb0ee2f
commit
56ad164c69
1 changed files with 16 additions and 0 deletions
16
src/theme.js
16
src/theme.js
|
@ -60,6 +60,22 @@ function getCustomTheme(themeName) {
|
||||||
return customTheme;
|
return customTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the underlying theme name for the given theme. This is usually the theme or
|
||||||
|
* CSS resource that the theme relies upon to load.
|
||||||
|
* @param {string} theme The theme name to get the base of.
|
||||||
|
* @returns {string} The base theme (typically "light" or "dark").
|
||||||
|
*/
|
||||||
|
export function getBaseTheme(theme) {
|
||||||
|
if (!theme) return "light";
|
||||||
|
if (theme.startsWith("custom-")) {
|
||||||
|
const customTheme = getCustomTheme(theme.substr(7));
|
||||||
|
return customTheme.is_dark ? "dark-custom" : "light-custom";
|
||||||
|
}
|
||||||
|
|
||||||
|
return theme; // it's probably a base theme
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever someone changes the theme
|
* Called whenever someone changes the theme
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue