Add button to reset theme to default and fix determination of theme

This commit is contained in:
Andrew Kingston 2021-09-06 16:51:40 +01:00
parent 363998a2af
commit 7b919cb2e7
3 changed files with 28 additions and 17 deletions

View File

@ -24,7 +24,6 @@
<div>
<Select
autoWidth
value={$store.theme}
options={themeOptions}
placeholder={null}

View File

@ -8,6 +8,7 @@
ColorPicker,
Label,
Select,
Button,
} from "@budibase/bbui"
import { store } from "builderStore"
import AppThemeSelect from "./AppThemeSelect.svelte"
@ -49,6 +50,10 @@
})
}
}
const resetTheme = () => {
store.actions.customTheme.save(null)
}
</script>
<div class="container">
@ -68,14 +73,16 @@
</div>
<div class="setting">
<Label size="L">Button roundness</Label>
<div class="select-wrapper">
<Select
autoWidth
placeholder={null}
value={$store.customTheme?.buttonBorderRadius ||
defaultTheme.buttonBorderRadius}
on:change={updateProperty("buttonBorderRadius")}
options={buttonBorderRadiusOptions}
/>
</div>
</div>
<div class="setting">
<Label size="L">Primary color</Label>
<ColorPicker
@ -111,6 +118,9 @@
/>
</div>
</Layout>
<div slot="footer">
<Button secondary quiet on:click={resetTheme}>Reset</Button>
</div>
</ModalContent>
</Modal>
@ -123,11 +133,8 @@
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-bottom: var(--spectrum-global-dimension-static-size-200);
border-bottom: var(--border-light);
}
.setting:last-child {
padding-bottom: 0;
border-bottom: none;
.select-wrapper {
width: 100px;
}
</style>

View File

@ -18,12 +18,17 @@ const createThemeStore = () => {
const store = derived(
[builderStore, appStore],
([$builderStore, $appStore]) => {
const theme =
$builderStore.theme || $appStore.application?.theme || defaultTheme
let theme = $appStore.application?.theme
let customTheme = $appStore.application?.customTheme
if ($builderStore.inBuilder) {
theme = $builderStore.theme
customTheme = $builderStore.customTheme
}
// Ensure theme is set
theme = theme || defaultTheme
// Delete and nullish keys from the custom theme
let customTheme =
$builderStore.customTheme || $appStore.application?.customTheme
if (customTheme) {
Object.entries(customTheme).forEach(([key, value]) => {
if (value == null || value === "") {