Browse Source

Add custom theme options for button roundedness and header color

pull/2561/head
Andrew Kingston 5 years ago
parent
commit
5568ab084b
  1. 2
      packages/builder/src/components/design/AppPreview/AppThemeSelect.svelte
  2. 54
      packages/builder/src/components/design/AppPreview/ThemeEditor.svelte
  3. 5
      packages/builder/src/pages/builder/app/[application]/design/[assetType]/_layout.svelte
  4. 1
      packages/client/src/components/CustomThemeWrapper.svelte
  5. 2
      packages/client/src/components/app/Layout.svelte
  6. 22
      packages/client/src/stores/theme.js

2
packages/builder/src/components/design/AppPreview/AppThemeSelect.svelte

@ -24,6 +24,7 @@
<div>
<Select
autoWidth
value={$store.theme}
options={themeOptions}
placeholder={null}
@ -34,6 +35,5 @@
<style>
div {
width: 100px;
padding-right: 8px;
}
</style>

54
packages/builder/src/components/design/AppPreview/ThemeEditor.svelte

@ -7,16 +7,39 @@
Layout,
ColorPicker,
Label,
Select,
} from "@budibase/bbui"
import { store } from "builderStore"
import AppThemeSelect from "./AppThemeSelect.svelte"
let modal
const defaultTheme = {
primaryColor: "var(--spectrum-global-color-blue-600)",
primaryColorHover: "var(--spectrum-global-color-blue-500)",
buttonBorderRadius: "16px",
navBackground: "var(--spectrum-global-color-gray-100)",
}
const buttonBorderRadiusOptions = [
{
label: "None",
value: "0",
},
{
label: "Small",
value: "4px",
},
{
label: "Medium",
value: "8px",
},
{
label: "Large",
value: "16px",
},
]
const updateProperty = property => {
return e => {
store.actions.customTheme.save({
@ -28,7 +51,7 @@
</script>
<div class="container">
<ActionButton icon="Brush" on:click={modal.show}>Edit</ActionButton>
<ActionButton icon="Brush" on:click={modal.show}>Theme</ActionButton>
</div>
<Modal bind:this={modal}>
<ModalContent
@ -37,9 +60,23 @@
showCloseIcon={false}
title="Theme settings"
>
<Layout noPadding gap="XS">
<Layout noPadding gap="S">
<div class="setting">
<Label size="L">Theme</Label>
<AppThemeSelect />
</div>
<div class="setting">
<Label size="L">Button roundness</Label>
<Select
autoWidth
value={$store.customTheme?.buttonBorderRadius ||
defaultTheme.buttonBorderRadius}
on:change={updateProperty("buttonBorderRadius")}
options={buttonBorderRadiusOptions}
/>
</div>
<div class="setting">
<Label size="L">Primary Color</Label>
<Label size="L">Primary color</Label>
<ColorPicker
spectrumTheme={$store.theme}
value={$store.customTheme?.primaryColor || defaultTheme.primaryColor}
@ -47,7 +84,7 @@
/>
</div>
<div class="setting">
<Label size="L">Primary Color (Hover)</Label>
<Label size="L">Primary color (hover)</Label>
<ColorPicker
spectrumTheme={$store.theme}
value={$store.customTheme?.primaryColorHover ||
@ -55,6 +92,15 @@
on:change={updateProperty("primaryColorHover")}
/>
</div>
<div class="setting">
<Label size="L">Navigation bar background</Label>
<ColorPicker
spectrumTheme={$store.theme}
value={$store.customTheme?.navBackground ||
defaultTheme.navBackground}
on:change={updateProperty("navBackground")}
/>
</div>
</Layout>
</ModalContent>
</Modal>

5
packages/builder/src/pages/builder/app/[application]/design/[assetType]/_layout.svelte

@ -151,11 +151,10 @@
{#if $currentAsset}
<div class="preview-header">
<ComponentSelectionList />
{#if $store.clientFeatures.spectrumThemes}
<AppThemeSelect />
{/if}
{#if $store.clientFeatures.customThemes}
<ThemeEditor />
{:else if $store.clientFeatures.spectrumThemes}
<AppThemeSelect />
{/if}
</div>
<div class="preview-content">

1
packages/client/src/components/CustomThemeWrapper.svelte

@ -16,6 +16,7 @@
/* Buttons */
--spectrum-semantic-cta-color-background-default: var(--primaryColor);
--spectrum-semantic-cta-color-background-hover: var(--primaryColorHover);
--spectrum-alias-item-rounded-border-radius-m: var(--buttonBorderRadius);
/* Loading spinners */
--spectrum-progresscircle-medium-track-fill-color: var(--primaryColor);

2
packages/client/src/components/app/Layout.svelte

@ -142,7 +142,7 @@
flex-direction: row;
justify-content: center;
align-items: stretch;
background: var(--spectrum-alias-background-color-primary);
background: var(--navBackground);
z-index: 2;
border-bottom: 1px solid var(--spectrum-global-color-gray-300);
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.05);

22
packages/client/src/stores/theme.js

@ -9,6 +9,8 @@ const defaultTheme = "spectrum--light"
const defaultCustomTheme = {
primaryColor: "var(--spectrum-glo" + "bal-color-blue-600)",
primaryColorHover: "var(--spectrum-glo" + "bal-color-blue-500)",
buttonBorderRadius: "16px",
navBackground: "var(--spectrum-glo" + "bal-color-gray-100)",
}
const createThemeStore = () => {
@ -17,14 +19,30 @@ const createThemeStore = () => {
([$builderStore, $appStore]) => {
const theme =
$builderStore.theme || $appStore.application?.theme || defaultTheme
const customTheme = {
// 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 === "") {
delete customTheme[key]
}
})
}
// Merge custom theme with defaults
customTheme = {
...defaultCustomTheme,
...($builderStore.customTheme || $appStore.application?.customTheme),
...customTheme,
}
// Build CSS string setting all custom variables
let customThemeCss = ""
Object.entries(customTheme).forEach(([key, value]) => {
customThemeCss += `--${key}:${value};`
})
return {
theme,
customTheme,

Loading…
Cancel
Save