@trimble-oss/moduswebcomponents
Version:
Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust
46 lines (42 loc) • 1.72 kB
JavaScript
;
var index = require('./index-BwcuBgCv.js');
var theme_store = require('./theme.store-Cdx0UJwu.js');
const ThemeProvider = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
}
componentWillLoad() {
theme_store.initializeThemeStore(this.initialTheme);
this.cleanup = theme_store.watchSystemTheme();
// Subscribe to specific property changes
this.modeUnsubscribe = theme_store.themeStore.onChange('mode', () => {
this.updateThemeClasses();
});
this.themeUnsubscribe = theme_store.themeStore.onChange('theme', () => {
this.updateThemeClasses();
});
this.updateThemeClasses();
}
disconnectedCallback() {
var _a, _b, _c;
(_a = this.cleanup) === null || _a === void 0 ? void 0 : _a.call(this);
(_b = this.modeUnsubscribe) === null || _b === void 0 ? void 0 : _b.call(this);
(_c = this.themeUnsubscribe) === null || _c === void 0 ? void 0 : _c.call(this);
}
updateThemeClasses() {
const root = document.documentElement;
const { mode, theme } = theme_store.themeStore.state;
// Update theme and mode attributes
root.setAttribute('data-theme', `${theme}-${mode}`);
root.setAttribute('data-mode', mode);
// Remove old mode classes
root.classList.remove('light', 'dark');
root.classList.add(mode);
// Store preferences
localStorage.setItem('modus-theme-config', JSON.stringify({ mode, theme }));
}
render() {
return index.h("slot", { key: '31a6fe7bf24df84db254656752b555d275fe435e' });
}
};
exports.modus_wc_theme_provider = ThemeProvider;