Update to use new shared-core location for theme utils

This commit is contained in:
Andrew Kingston 2024-10-24 09:35:55 +01:00
parent 4c112d51e6
commit ab0f81824d
No known key found for this signature in database
12 changed files with 39 additions and 45 deletions

View File

@ -23,6 +23,7 @@
import { themeStore } from "stores/portal" import { themeStore } from "stores/portal"
import { getContext } from "svelte" import { getContext } from "svelte"
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import { ThemeOptions } from "@budibase/shared-core"
const modalContext = getContext(Context.Modal) const modalContext = getContext(Context.Modal)
const commands = [ const commands = [
@ -141,13 +142,13 @@
icon: "ShareAndroid", icon: "ShareAndroid",
action: () => $goto(`./automation/${automation._id}`), action: () => $goto(`./automation/${automation._id}`),
})) ?? []), })) ?? []),
...Constants.ThemeOptions.map(theme => ({ ...ThemeOptions.map(themeMeta => ({
type: "Change Builder Theme", type: "Change Builder Theme",
name: theme.name, name: themeMeta.name,
icon: "ColorPalette", icon: "ColorPalette",
action: () => action: () =>
themeStore.update(state => { themeStore.update(state => {
state.theme = theme.id state.theme = themeMeta.id
return state return state
}), }),
})), })),

View File

@ -3,6 +3,7 @@
import { Label } from "@budibase/bbui" import { Label } from "@budibase/bbui"
import { onMount, createEventDispatcher } from "svelte" import { onMount, createEventDispatcher } from "svelte"
import { themeStore } from "stores/portal" import { themeStore } from "stores/portal"
import { Theme } from "@budibase/types"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -116,7 +117,7 @@
readOnly, readOnly,
autoCloseBrackets: true, autoCloseBrackets: true,
autoCloseTags: true, autoCloseTags: true,
theme: $themeStore.theme.includes("light") ? THEMES.LIGHT : THEMES.DARK, theme: $themeStore.theme === Theme.LIGHT ? THEMES.LIGHT : THEMES.DARK,
} }
if (!tab) if (!tab)

View File

@ -1,12 +1,12 @@
<script> <script>
import { ModalContent, Select } from "@budibase/bbui" import { ModalContent, Select } from "@budibase/bbui"
import { themeStore } from "stores/portal" import { themeStore } from "stores/portal"
import { Constants } from "@budibase/frontend-core" import { ThemeOptions } from "@budibase/shared-core"
</script> </script>
<ModalContent title="Theme"> <ModalContent title="Theme">
<Select <Select
options={Constants.ThemeOptions} options={ThemeOptions}
bind:value={$themeStore.theme} bind:value={$themeStore.theme}
placeholder={null} placeholder={null}
getOptionLabel={x => x.name} getOptionLabel={x => x.name}

View File

@ -1,7 +1,7 @@
<script> <script>
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { themeStore, appStore } from "stores/builder" import { themeStore, appStore } from "stores/builder"
import { Constants, getThemeClassNames } from "@budibase/frontend-core" import { ThemeOptions, getThemeClassNames } from "@budibase/shared-core"
const onChangeTheme = async theme => { const onChangeTheme = async theme => {
try { try {
@ -15,14 +15,14 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="container"> <div class="container">
{#each Constants.ThemeOptions as theme} {#each ThemeOptions as themeMeta}
<div <div
class="theme" class="theme"
class:selected={theme.id === $themeStore.theme} class:selected={themeMeta.id === $themeStore.theme}
on:click={() => onChangeTheme(theme.id)} on:click={() => onChangeTheme(themeMeta.id)}
> >
<div class="color {getThemeClassNames(theme.id)}" /> <div class="color {getThemeClassNames(themeMeta.id)}" />
{theme.name} {themeMeta.name}
</div> </div>
{/each} {/each}
</div> </div>

View File

@ -18,13 +18,10 @@
TooltipPosition, TooltipPosition,
TooltipType, TooltipType,
} from "@budibase/bbui" } from "@budibase/bbui"
import { sdk } from "@budibase/shared-core" import { sdk, getThemeClassNames } from "@budibase/shared-core"
import { API } from "api" import { API } from "api"
import ErrorSVG from "./ErrorSVG.svelte" import ErrorSVG from "./ErrorSVG.svelte"
import { import { ClientAppSkeleton } from "@budibase/frontend-core"
ClientAppSkeleton,
getThemeClassNames,
} from "@budibase/frontend-core"
import { contextMenuStore } from "stores/builder" import { contextMenuStore } from "stores/builder"
$: app = $enrichedApps.find(app => app.appId === $params.appId) $: app = $enrichedApps.find(app => app.appId === $params.appId)

View File

@ -1,16 +1,11 @@
import { writable, get } from "svelte/store" import { writable, get } from "svelte/store"
import { API } from "api" import { API } from "api"
import { Constants, ensureValidTheme } from "@budibase/frontend-core" import { ensureValidTheme, DefaultAppTheme } from "@budibase/shared-core"
const DefaultAppTheme = Constants.Themes.Light
const INITIAL_THEMES_STATE = {
theme: DefaultAppTheme,
customTheme: {},
}
export const createThemeStore = () => { export const createThemeStore = () => {
const store = writable({ const store = writable({
...INITIAL_THEMES_STATE, theme: DefaultAppTheme,
customTheme: {},
}) })
const syncAppTheme = app => { const syncAppTheme = app => {

View File

@ -1,28 +1,29 @@
import { createLocalStorageStore } from "@budibase/frontend-core"
import { derived } from "svelte/store"
import { import {
Constants, DefaultBuilderTheme,
createLocalStorageStore,
ensureValidTheme, ensureValidTheme,
getThemeClassNames, getThemeClassNames,
} from "@budibase/frontend-core" ThemeOptions,
import { derived } from "svelte/store" ThemeClassPrefix,
} from "@budibase/shared-core"
export const getThemeStore = () => { export const getThemeStore = () => {
const defaultBuilderTheme = Constants.Themes.Darkest
const themeElement = document.documentElement const themeElement = document.documentElement
const initialValue = { const initialValue = {
theme: defaultBuilderTheme, theme: DefaultBuilderTheme,
} }
const store = createLocalStorageStore("bb-theme", initialValue) const store = createLocalStorageStore("bb-theme", initialValue)
const derivedStore = derived(store, $store => ({ const derivedStore = derived(store, $store => ({
...$store, ...$store,
theme: ensureValidTheme($store.theme, defaultBuilderTheme), theme: ensureValidTheme($store.theme, DefaultBuilderTheme),
})) }))
// Update theme class when store changes // Update theme class when store changes
derivedStore.subscribe(({ theme }) => { derivedStore.subscribe(({ theme }) => {
const classNames = getThemeClassNames(theme).split(" ") const classNames = getThemeClassNames(theme).split(" ")
Constants.ThemeOptions.forEach(option => { ThemeOptions.forEach(option => {
const className = `${Constants.ThemeClassPrefix}${option.id}` const className = `${ThemeClassPrefix}${option.id}`
themeElement.classList.toggle(className, classNames.includes(className)) themeElement.classList.toggle(className, classNames.includes(className))
}) })
}) })

View File

@ -3,11 +3,8 @@
import { setContext, onMount } from "svelte" import { setContext, onMount } from "svelte"
import { Layout, Heading, Body } from "@budibase/bbui" import { Layout, Heading, Body } from "@budibase/bbui"
import ErrorSVG from "@budibase/frontend-core/assets/error.svg" import ErrorSVG from "@budibase/frontend-core/assets/error.svg"
import { import { Constants, CookieUtils } from "@budibase/frontend-core"
Constants, import { getThemeClassNames } from "@budibase/shared-core"
CookieUtils,
getThemeClassNames,
} from "@budibase/frontend-core"
import Component from "./Component.svelte" import Component from "./Component.svelte"
import SDK from "sdk" import SDK from "sdk"
import { import {

View File

@ -1,12 +1,11 @@
import { derived } from "svelte/store" import { derived } from "svelte/store"
import { appStore } from "./app" import { appStore } from "./app"
import { builderStore } from "./builder" import { builderStore } from "./builder"
import { Constants, ensureValidTheme } from "@budibase/frontend-core" import { ensureValidTheme, DefaultAppTheme } from "@budibase/shared-core"
// This is the good old acorn bug where having the word "g l o b a l" makes it // This is the good old acorn bug where having the word "g l o b a l" makes it
// think that this is not ES6 compatible and starts throwing errors when using // think that this is not ES6 compatible and starts throwing errors when using
// optional chaining. Piss off acorn. // optional chaining. Piss off acorn.
const defaultTheme = Constants.Themes.Light
const defaultCustomTheme = { const defaultCustomTheme = {
primaryColor: "var(--spectrum-glo" + "bal-color-blue-600)", primaryColor: "var(--spectrum-glo" + "bal-color-blue-600)",
primaryColorHover: "var(--spectrum-glo" + "bal-color-blue-500)", primaryColorHover: "var(--spectrum-glo" + "bal-color-blue-500)",
@ -27,7 +26,7 @@ const createThemeStore = () => {
} }
// Ensure theme is set // Ensure theme is set
theme = ensureValidTheme(theme, defaultTheme) theme = ensureValidTheme(theme, DefaultAppTheme)
// Delete and nullish keys from the custom theme // Delete and nullish keys from the custom theme
if (customTheme) { if (customTheme) {

View File

@ -9,7 +9,6 @@ export * as SchemaUtils from "./schema"
export { memo, derivedMemo } from "./memo" export { memo, derivedMemo } from "./memo"
export { createWebsocket } from "./websocket" export { createWebsocket } from "./websocket"
export * from "./download" export * from "./download"
export * from "./theme"
export * from "./settings" export * from "./settings"
export * from "./relatedColumns" export * from "./relatedColumns"
export * from "./table" export * from "./table"

View File

@ -3,6 +3,7 @@ export * from "./api"
export * from "./fields" export * from "./fields"
export * from "./rows" export * from "./rows"
export * from "./colors" export * from "./colors"
export * from "./themes"
export const OperatorOptions = { export const OperatorOptions = {
Equals: { Equals: {

View File

@ -1,5 +1,10 @@
import { ThemeMeta, Theme } from "@budibase/types" import { ThemeMeta, Theme } from "@budibase/types"
export const ThemeClassPrefix = "spectrum--"
export const DefaultBuilderTheme = Theme.DARKEST
export const DefaultAppTheme = Theme.LIGHT
// Currently available theme options for builder and apps
export const ThemeOptions: ThemeMeta[] = [ export const ThemeOptions: ThemeMeta[] = [
{ {
id: Theme.LIGHT, id: Theme.LIGHT,
@ -21,5 +26,3 @@ export const ThemeOptions: ThemeMeta[] = [
base: Theme.DARKEST, base: Theme.DARKEST,
}, },
] ]
export const ThemeClassPrefix = "spectrum--"