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 759f34626b
commit c72a65bc5f
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} />