UNPKG

igniteui-webcomponents

Version:

Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.

41 lines 1.41 kB
import { isDefined } from '../components/common/util.js'; import { CHANGE_THEME_EVENT, } from './theming-event.js'; import { getAllCssVariables } from './utils.js'; let theme; let themeVariant; function dispatchThemingEvent(detail) { if (isDefined(globalThis.dispatchEvent)) { globalThis.dispatchEvent(new CustomEvent(CHANGE_THEME_EVENT, { detail })); } } function isOfTypeTheme(theme) { return ['bootstrap', 'material', 'indigo', 'fluent'].includes(theme); } function isOfTypeThemeVariant(variant) { return ['light', 'dark'].includes(variant); } export const getTheme = () => { if (!(theme && themeVariant)) { const [_theme, _variant] = Object.entries(getAllCssVariables()).filter(([v]) => v === 'igTheme' || v === 'igThemeVariant') || []; theme = _theme?.[1] && isOfTypeTheme(_theme[1]) ? _theme[1] : 'bootstrap'; themeVariant = _variant?.[1] && isOfTypeThemeVariant(_variant[1]) ? _variant[1] : 'light'; } return { theme, themeVariant }; }; export const setTheme = (value, variant) => { theme = value; themeVariant = variant; }; export const configureTheme = (t, v = 'light') => { if (isOfTypeTheme(t) && isOfTypeThemeVariant(v)) { setTheme(t, v); } dispatchThemingEvent({ theme, themeVariant }); }; //# sourceMappingURL=config.js.map