1
0
Fork 0
mirror of synced 2024-06-29 03:20:34 +12:00

Add support for all 4 spectrum themes in builder!

This commit is contained in:
Andrew Kingston 2021-04-27 13:15:49 +01:00
parent 11dd3ddf7a
commit e89c51deef
2 changed files with 23 additions and 9 deletions

View file

@ -3,14 +3,25 @@ import { localStorageStore } from "./localStorage"
export const getThemeStore = () => {
const themeElement = document.documentElement
const initialValue = {
darkMode: true,
theme: "darkest",
options: ["lightest", "light", "dark", "darkest"],
}
const store = localStorageStore("bb-theme", initialValue)
// Update theme when store changes
store.subscribe(theme => {
themeElement.classList.toggle("spectrum--darkest", theme.darkMode)
themeElement.classList.toggle("spectrum--lightest", !theme.darkMode)
// Update theme class when store changes
store.subscribe(state => {
// Handle any old local storage values - this can be removed after the update
if (state.darkMode !== undefined) {
store.set(initialValue)
return
}
state.options.forEach(option => {
themeElement.classList.toggle(
`spectrum--${option}`,
option === state.theme
)
})
})
return store

View file

@ -1,8 +1,11 @@
<script>
import { themeStore } from "builderStore"
import { Toggle } from "@budibase/bbui"
let showAdvanced = false
import { Select } from "@budibase/bbui"
import { capitalise } from "../../helpers"
</script>
<Toggle text="Dark theme" bind:value={$themeStore.darkMode} />
<Select
options={$themeStore.options}
bind:value={$themeStore.theme}
placeholder={null}
getOptionLabel={capitalise} />