Offer custom themes for client apps and improve theme panel

This commit is contained in:
Andrew Kingston 2022-07-29 11:53:07 +01:00
parent 4158513bf4
commit df759ac20a
3 changed files with 88 additions and 88 deletions

View File

@ -1,20 +1,11 @@
<script> <script>
import { notifications, Slider, Icon } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { store } from "builderStore" import { store } from "builderStore"
import { Constants } from "@budibase/frontend-core"
const ThemeOptions = [ const onChangeTheme = async theme => {
"spectrum--darkest",
"spectrum--dark",
"spectrum--light",
"spectrum--lightest",
]
$: themeIndex = ThemeOptions.indexOf($store.theme) ?? 2
const onChangeTheme = async e => {
try { try {
const theme = ThemeOptions[e.detail] ?? ThemeOptions[2] await store.actions.theme.save(`spectrum--${theme}`)
await store.actions.theme.save(theme)
} catch (error) { } catch (error) {
notifications.error("Error updating theme") notifications.error("Error updating theme")
} }
@ -22,26 +13,52 @@
</script> </script>
<div class="container"> <div class="container">
<Icon name="Moon" /> {#each Constants.Themes as theme}
<Slider <div
min={0} class="theme"
max={3} class:selected={`spectrum--${theme.class}` === $store.theme}
step={1} on:click={() => onChangeTheme(theme.class)}
value={themeIndex} >
on:change={onChangeTheme} <div
style="background: {theme.preview}"
class="color spectrum--{theme.class}"
/> />
<Icon name="Light" /> {theme.name}
</div>
{/each}
</div> </div>
<style> <style>
div { .container {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: var(--spacing-xs);
}
.color {
width: 20px;
height: 20px;
border-radius: 50px;
background: var(--spectrum-global-color-gray-200);
border: 1px solid rgba(0, 0, 0, 0.1);
}
.theme {
border-radius: 4px;
padding: var(--spacing-s) var(--spacing-m);
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: flex-start;
align-items: center; align-items: center;
gap: var(--spacing-m); gap: var(--spacing-xl);
transition: background 130ms ease-out;
font-weight: 600;
color: var(--spectrum-global-color-gray-900);
} }
div :global(.spectrum-Form-item) { .theme:hover {
flex: 1 1 auto; cursor: pointer;
}
.theme.selected,
.theme:hover {
background: var(--spectrum-global-color-gray-50);
} }
</style> </style>

View File

@ -0,0 +1,38 @@
<script>
import { createEventDispatcher } from "svelte"
import { Slider, Button } from "@budibase/bbui"
export let customTheme
const dispatch = createEventDispatcher()
const options = ["0", "4px", "8px", "16px"]
$: index = options.indexOf(customTheme.buttonBorderRadius) ?? 2
const onChange = async e => {
dispatch("change", options[e.detail])
}
</script>
<div class="container">
<Slider min={0} max={3} step={1} value={index} on:change={onChange} />
<div class="button" style="--radius: {customTheme.buttonBorderRadius};">
<Button primary newStyles>Button</Button>
</div>
</div>
<style>
.container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
gap: var(--spacing-xl);
}
.container :global(.spectrum-Form-item) {
flex: 1 1 auto;
}
.button :global(.spectrum-Button) {
border-radius: var(--radius) !important;
}
</style>

View File

@ -11,25 +11,7 @@
import { get } from "svelte/store" import { get } from "svelte/store"
import { DefaultAppTheme } from "constants" import { DefaultAppTheme } from "constants"
import AppThemeSelect from "./AppThemeSelect.svelte" import AppThemeSelect from "./AppThemeSelect.svelte"
import ButtonRoundnessSelect from "./ButtonRoundnessSelect.svelte"
const ButtonBorderRadiusOptions = [
{
label: "Square",
value: "0",
},
{
label: "Soft edge",
value: "4px",
},
{
label: "Curved",
value: "8px",
},
{
label: "Round",
value: "16px",
},
]
$: customTheme = $store.customTheme || {} $: customTheme = $store.customTheme || {}
@ -52,22 +34,11 @@
<AppThemeSelect /> <AppThemeSelect />
</Layout> </Layout>
<Layout noPadding gap="XS"> <Layout noPadding gap="XS">
<Label>Buttons</Label> <Label>Button roundness</Label>
<div class="buttons"> <ButtonRoundnessSelect
{#each ButtonBorderRadiusOptions as option} {customTheme}
<div on:change={e => update("buttonBorderRadius", e.detail)}
class:active={customTheme.buttonBorderRadius === option.value} />
style={`--radius: ${option.value}`}
>
<Button
secondary
on:click={() => update("buttonBorderRadius", option.value)}
>
{option.label}
</Button>
</div>
{/each}
</div>
</Layout> </Layout>
<Layout noPadding gap="XS"> <Layout noPadding gap="XS">
<Label>Accent color</Label> <Label>Accent color</Label>
@ -88,29 +59,3 @@
</Layout> </Layout>
</Layout> </Layout>
</Panel> </Panel>
<style>
.buttons {
display: grid;
grid-template-columns: 100px 100px;
gap: var(--spacing-m);
}
.buttons > div {
display: contents;
}
.buttons > div :global(.spectrum-Button) {
border-radius: var(--radius) !important;
border-width: 1px;
border-color: var(--spectrum-global-color-gray-400);
font-weight: 600;
}
.buttons > div:hover :global(.spectrum-Button) {
background: var(--spectrum-global-color-gray-700);
border-color: var(--spectrum-global-color-gray-700);
}
.buttons > div.active :global(.spectrum-Button) {
background: var(--spectrum-global-color-gray-200);
color: var(--spectrum-global-color-gray-800);
border-color: var(--spectrum-global-color-gray-600);
}
</style>