feat(theme): implement custom state for theme creator colour picker

This commit is contained in:
sethburkart123
2024-10-02 09:39:06 +10:00
parent 2d325f820d
commit 278a085286
3 changed files with 16 additions and 10 deletions
@@ -5,10 +5,12 @@
import { animate, spring } from 'motion'; import { animate, spring } from 'motion';
import { delay } from '@/seqta/utils/delay.ts' import { delay } from '@/seqta/utils/delay.ts'
const { hidePicker, standalone = false, savePresets = true } = $props<{ const { hidePicker, standalone = false, savePresets = true, customOnChange = null, customState = null } = $props<{
hidePicker?: () => void, hidePicker?: () => void,
standalone?: boolean, standalone?: boolean,
savePresets?: boolean savePresets?: boolean,
customOnChange?: (color: string) => void,
customState?: string
}>(); }>();
let background = $state<HTMLDivElement | null>(null); let background = $state<HTMLDivElement | null>(null);
@@ -72,7 +74,7 @@
{#if standalone} {#if standalone}
<div class="h-auto rounded-xl overflow-clip"> <div class="h-auto rounded-xl overflow-clip">
<ReactAdapter savePresets={savePresets} el={ColourPicker} /> <ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPicker} />
</div> </div>
{:else} {:else}
<!-- svelte-ignore a11y_no_static_element_interactions --> <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -86,7 +88,7 @@
bind:this={content} bind:this={content}
class="h-auto p-4 bg-white border shadow-lg cursor-auto rounded-xl dark:bg-zinc-800 border-zinc-100 dark:border-zinc-700" class="h-auto p-4 bg-white border shadow-lg cursor-auto rounded-xl dark:bg-zinc-800 border-zinc-100 dark:border-zinc-700"
> >
<ReactAdapter savePresets={savePresets} el={ColourPicker} /> <ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPicker} />
</div> </div>
</div> </div>
{/if} {/if}
@@ -41,6 +41,7 @@ export default function Picker({
const latestValuesRef = useRef({ customThemeColor, customOnChange, savePresets, presets }); const latestValuesRef = useRef({ customThemeColor, customOnChange, savePresets, presets });
useEffect(() => { useEffect(() => {
console.log(customState)
if (customState !== undefined) { if (customState !== undefined) {
setCustomThemeColor(customState) setCustomThemeColor(customState)
} else { } else {
@@ -32,13 +32,16 @@
}) })
onMount(async () => { onMount(async () => {
if (themeID) { if (themeID) {
const tempTheme = await getTheme(themeID) const tempTheme = await getTheme(themeID)
if (tempTheme) theme = tempTheme if (tempTheme) theme = tempTheme
} }
}); });
$effect(() => {
console.log(theme)
})
type SettingType = 'switch' | 'button' | 'slider' | 'colourPicker' | 'select' | 'codeEditor'; type SettingType = 'switch' | 'button' | 'slider' | 'colourPicker' | 'select' | 'codeEditor';
type SwitchProps = { state: boolean; onChange: (value: boolean) => void }; type SwitchProps = { state: boolean; onChange: (value: boolean) => void };
@@ -119,7 +122,7 @@
description: 'Useful when your cover image contains text', description: 'Useful when your cover image contains text',
props: { props: {
state: theme.hideThemeName, state: theme.hideThemeName,
onChange: (value) => theme.hideThemeName = value onChange: (value: boolean) => theme = { ...theme, hideThemeName: value }
} }
}, },
{ {
@@ -128,7 +131,7 @@
description: 'Force users to use either dark or light mode', description: 'Force users to use either dark or light mode',
props: { props: {
state: theme.forceDark !== undefined, state: theme.forceDark !== undefined,
onChange: (value) => theme.forceDark = value ? false : undefined onChange: (value: boolean) => theme = { ...theme, forceDark: value ? false : undefined }
} }
}, },
{ {
@@ -137,8 +140,8 @@
description: 'Set the default color for your theme', description: 'Set the default color for your theme',
direction: 'vertical', direction: 'vertical',
props: { props: {
color: theme.defaultColour, customState: theme.defaultColour,
onChange: (color) => theme.defaultColour = color customOnChange: (color: string) => theme = { ...theme, defaultColour: color }
} }
}, },
{ {
@@ -148,7 +151,7 @@
direction: 'vertical', direction: 'vertical',
props: { props: {
value: theme.CustomCSS, value: theme.CustomCSS,
onChange: (value) => { theme.CustomCSS = value; console.log(theme.CustomCSS) } onChange: (value: string) => { theme = { ...theme, CustomCSS: value } }
} }
} }
] as SettingItem[] as setting} ] as SettingItem[] as setting}