cleanup: switch to $state for themes

This commit is contained in:
James Xylight committed 2025-02-10 17:34:40 -08:00
1 parent a5ba6d66f6
commit 80df5c5409
19 files changed
+169 -349

No files matched your search

+28 -23
View File
@@ -21,7 +21,7 @@
import ColorSwatch from './ColorSwatch.svelte'
import { t } from '$lib/translations'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { calculateVars, hexToRgb, theme, themeData } from '$lib/ui/colors'
import { theme as themeData } from '$lib/ui/colors.svelte'
import { getDefaultColors } from '$lib/ui/presets'
import ThemePreset from './ThemePreset.svelte'
@@ -39,7 +39,7 @@
if (importText == '') {
throw new Error('Import is empty')
}
$theme.colors = JSON.parse(importText)
themeData.current.colors = JSON.parse(importText)
toast({ content: $t('message.success'), type: 'success' })
importing = false
} catch (err) {
@@ -70,20 +70,20 @@
class="grid grid-cols-1 @md:grid-cols-2 @xl:grid-cols-3 @3xl:grid-cols-4
gap-2"
>
{#each $themeData.themes as theme, index}
<ThemePreset bind:theme={$themeData.themes[index]} />
{#each themeData.data.themes as theme, index}
<ThemePreset bind:theme={themeData.data.themes[index]} />
{/each}
<button
onclick={() => {
const newTheme = {
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
id: Math.max(...themeData.data.themes.map((t) => t.id)) + 1,
colors: getDefaultColors(),
name: $t('routes.theme.preset.new'),
}
$themeData.themes = [...$themeData.themes, newTheme]
themeData.data.themes = [...themeData.data.themes, newTheme]
$themeData.currentTheme = newTheme.id
themeData.data.currentTheme = newTheme.id
}}
>
<Material
@@ -105,14 +105,14 @@
importing = !importing
}}
size="lg"
disabled={$theme.id <= 0}
disabled={themeData.current.id <= 0}
>
<Icon src={ArrowUpTray} size="16" mini />
{$t('routes.theme.import')}
</Button>
<Button
onclick={() => {
navigator.clipboard.writeText(JSON.stringify($theme.colors))
navigator.clipboard.writeText(JSON.stringify(themeData.current.colors))
toast({ content: 'Copied theme to clipboard.' })
}}
size="lg"
@@ -121,7 +121,7 @@
{$t('routes.theme.export')}
</Button>
<Button
disabled={$theme.id <= 0}
disabled={themeData.current.id <= 0}
onclick={() => {
modal({
actions: [
@@ -131,7 +131,12 @@
}),
action({
action: () => {
$theme.colors = { other: {}, primary: {}, zinc: {}, slate: {} }
themeData.current.colors = {
other: {},
primary: {},
zinc: {},
slate: {},
}
},
content: $t('routes.theme.reset'),
close: true,
@@ -148,15 +153,15 @@
{$t('routes.theme.reset')}
</Button>
</div>
{#if $theme.id <= 0}
{#if themeData.current.id <= 0}
<Note>
{$t('routes.theme.preset.description')}
</Note>
{/if}
<div
class="relative"
class:opacity-50={$theme.id <= 0}
class:pointer-events-none={$theme.id <= 0}
class:opacity-50={themeData.current.id <= 0}
class:pointer-events-none={themeData.current.id <= 0}
>
<Material
color="transparent"
@@ -164,13 +169,13 @@
>
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
<ColorSwatch
value={$theme.colors.primary?.[900]}
value={themeData.current.colors.primary?.[900]}
onchange={(e) => {
$theme.colors.primary[900] = e
themeData.current.colors.primary[900] = e
}}
oncontextmenu={(e) => {
e.preventDefault()
$theme.colors.primary[900] =
themeData.current.colors.primary[900] =
// @ts-ignore
defaultColors.primary[900]
@@ -179,13 +184,13 @@
class="!w-12 !h-12 col-span-1"
/>
<ColorSwatch
value={$theme.colors.primary?.[100]}
value={themeData.current.colors.primary?.[100]}
onchange={(e) => {
$theme.colors.primary[100] = e
themeData.current.colors.primary[100] = e
}}
oncontextmenu={(e) => {
e.preventDefault()
$theme.colors.primary[100] =
themeData.current.colors.primary[100] =
// @ts-ignore
defaultColors.primary[100]
@@ -209,13 +214,13 @@
<div class="flex flex-col gap-0.5 w-10 group">
<!--@ts-ignore-->
<ColorSwatch
bind:value={$theme.colors[category][shade]}
bind:value={themeData.current.colors[category][shade]}
onchange={(e) => {
$theme.colors[category][shade] = e
themeData.current.colors[category][shade] = e
}}
oncontextmenu={(e) => {
e.preventDefault()
$theme.colors[category][shade] =
themeData.current.colors[category][shade] =
// @ts-ignore
defaultColors[category][shade]
+1 -4
View File
@@ -1,8 +1,5 @@
<script lang="ts">
import { createBubbler } from 'svelte/legacy'
import { hexToRgb } from '$lib/ui/colors'
import { createEventDispatcher } from 'svelte'
import { hexToRgb } from '$lib/ui/colors.svelte'
interface Props {
value: string
+15 -8
View File
@@ -2,7 +2,11 @@
import { preventDefault } from 'svelte/legacy'
import { t } from '$lib/translations'
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
import {
calculateVars,
theme as themeData,
type Theme,
} from '$lib/ui/colors.svelte'
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
@@ -15,10 +19,10 @@
let editingName = $state(false)
</script>
<button class="h-full" onclick={() => ($themeData.currentTheme = theme.id)}>
<button class="h-full" onclick={() => (themeData.data.currentTheme = theme.id)}>
<Material
padding="none"
class="{theme.id == $themeData.currentTheme
class="{theme.id == themeData.data.currentTheme
? 'ring-2 ring-inset ring-primary-900 dark:ring-primary-100'
: ''} flex relative cursor-pointer h-full flex-col text-left p-0.5"
rounding="xl"
@@ -38,7 +42,7 @@
class="w-3 h-3 bg-primary-900 dark:bg-primary-100 rounded-full ml-auto"
></div>
</div>
{#if theme.id == $themeData.currentTheme}
{#if theme.id == themeData.data.currentTheme}
<Icon
src={CheckCircle}
size="20"
@@ -79,13 +83,16 @@
content: $t('routes.theme.preset.delete.confirm'),
type: 'danger',
action: () => {
const index = $themeData.themes
const index = themeData.data.themes
.map((t) => t.id)
.indexOf(theme.id)
$themeData.themes = $themeData.themes.toSpliced(index, 1)
if (theme.id == $themeData.currentTheme) {
$themeData.currentTheme = 0
themeData.data.themes = themeData.data.themes.toSpliced(
index,
1,
)
if (theme.id == themeData.data.currentTheme) {
themeData.data.currentTheme = 0
}
},
}),