budibase/packages/builder/src/builderStore/store/theme.js

33 lines
858 B
JavaScript
Raw Normal View History

import { Constants, createLocalStorageStore } from "@budibase/frontend-core"
export const getThemeStore = () => {
const themeElement = document.documentElement
const initialValue = {
theme: "darkest",
}
const store = createLocalStorageStore("bb-theme", initialValue)
// Update theme class when store changes
2021-05-04 12:32:22 +02:00
store.subscribe(state => {
// Handle any old local storage values - this can be removed after the update
if (state.darkMode !== undefined) {
store.set(initialValue)
return
}
Constants.ThemeOptions.forEach(option => {
themeElement.classList.toggle(
`spectrum--${option}`,
option === state.theme
)
2022-03-15 12:20:06 +01:00
// Ensure darkest is always added as this is the base class for custom
// themes
themeElement.classList.add("spectrum--darkest")
})
})
return store
}