UNPKG

nice-ui

Version:

React design system, components, and utilities

34 lines (33 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NiceUiServices = void 0; const rxjs_1 = require("rxjs"); const NiceUiContentService_1 = require("./NiceUiContentService"); const NiceUiNavService_1 = require("./NiceUiNavService"); const isClient = typeof window === 'object'; const storage = isClient ? localStorage : {}; class NiceUiServices { constructor(opts = {}) { this.theme$ = new rxjs_1.BehaviorSubject('light'); this.setTheme = (theme) => { this.theme$.next(theme); if (theme) storage['nice-ui/theme'] = theme; else delete storage['nice-ui/theme']; }; this.nav = opts.nav ?? new NiceUiNavService_1.NiceUiNavService(); this.content = opts.content ?? new NiceUiContentService_1.NiceUiContentService({ root: { name: 'home', slug: '', }, }); const theme = storage['nice-ui/theme']; if (theme && this.theme$.value !== theme) this.theme$.next(theme); } } exports.NiceUiServices = NiceUiServices;