feat: save themes to localStorage
This commit is contained in:
1 parent
6fd970320b
commit
1f08f04a0c
6 files changed
+339
-195
No files matched your search
@@ -82,7 +82,11 @@
|
|||||||
|
|
||||||
<svelte:window bind:innerWidth={$screenWidth} />
|
<svelte:window bind:innerWidth={$screenWidth} />
|
||||||
|
|
||||||
<div {...$$restProps} class="shell {$$props.class}" style={$themeVars}>
|
<div
|
||||||
|
{...$$restProps}
|
||||||
|
class="shell bg-slate-50 dark:bg-zinc-950 {$$props.class}"
|
||||||
|
style={$themeVars}
|
||||||
|
>
|
||||||
<slot />
|
<slot />
|
||||||
<div
|
<div
|
||||||
class="
|
class="
|
||||||
@@ -120,7 +124,7 @@
|
|||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
name="sidebar"
|
name="sidebar"
|
||||||
class="hidden md:flex sticky top-0 left-0 max-w-full h-max bg-slate-50 dark:bg-zinc-950
|
class="hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||||
z-40
|
z-40
|
||||||
{sidePadding.class}"
|
{sidePadding.class}"
|
||||||
style="grid-area: sidebar; width: 100% !important;"
|
style="grid-area: sidebar; width: 100% !important;"
|
||||||
@@ -128,7 +132,7 @@
|
|||||||
<slot
|
<slot
|
||||||
name="main"
|
name="main"
|
||||||
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||||
{$contentPadding.class}"
|
{$contentPadding.class} main"
|
||||||
style="grid-area: main"
|
style="grid-area: main"
|
||||||
/>
|
/>
|
||||||
<slot
|
<slot
|
||||||
@@ -159,6 +163,11 @@
|
|||||||
grid-template-areas: 'main';
|
grid-template-areas: 'main';
|
||||||
justify-items: start;
|
justify-items: start;
|
||||||
}
|
}
|
||||||
|
.content > * {
|
||||||
|
width: 100%; /* Full width for immediate children */
|
||||||
|
max-width: 100rem; /* Limit width */
|
||||||
|
padding: 0 1rem; /* Add some padding on smaller screens */
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
.content {
|
.content {
|
||||||
@@ -170,13 +179,25 @@
|
|||||||
|
|
||||||
@media (min-width: 1280px) {
|
@media (min-width: 1280px) {
|
||||||
.content {
|
.content {
|
||||||
grid-template-columns: 20% 1fr 20%;
|
grid-template-columns: 20% 60% 20%;
|
||||||
justify-items: end center start;
|
justify-items: end center start;
|
||||||
grid-template-areas: 'sidebar main suffix';
|
grid-template-areas: 'sidebar main suffix';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.limit-width {
|
.content:is(.limit-width) {
|
||||||
max-width: 100rem;
|
grid-template-columns: 1fr 2fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.content:is(.limit-width) > *:first-child) {
|
||||||
|
max-width: 20rem;
|
||||||
|
justify-self: end;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.content:is(.limit-width) > *:last-child) {
|
||||||
|
max-width: 20rem;
|
||||||
|
justify-self: start;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -359,6 +359,14 @@
|
|||||||
"resetWarning": {
|
"resetWarning": {
|
||||||
"title": "Reset Theme",
|
"title": "Reset Theme",
|
||||||
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
||||||
|
},
|
||||||
|
"preset": {
|
||||||
|
"title": "Can't be modified",
|
||||||
|
"description": "This is a default theme, and can't be modified.",
|
||||||
|
"delete": {
|
||||||
|
"title": "Delete Theme",
|
||||||
|
"confirm": "Confirm"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"community": {
|
"community": {
|
||||||
|
|||||||
+32
-59
@@ -9,11 +9,12 @@ import {
|
|||||||
type Readable,
|
type Readable,
|
||||||
} from 'svelte/store'
|
} from 'svelte/store'
|
||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import { presets } from './presets'
|
import { getDefaultTheme, presets } from './presets'
|
||||||
|
import { browser } from '$app/environment'
|
||||||
|
|
||||||
type ColorScheme = 'system' | 'light' | 'dark'
|
type ColorScheme = 'system' | 'light' | 'dark'
|
||||||
|
|
||||||
interface ThemeData {
|
export interface ThemeData {
|
||||||
scheme: ColorScheme
|
scheme: ColorScheme
|
||||||
themes: Theme[]
|
themes: Theme[]
|
||||||
currentTheme: number
|
currentTheme: number
|
||||||
@@ -25,63 +26,12 @@ export interface Theme {
|
|||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ThemeColors {
|
export interface ThemeColors {
|
||||||
[scheme: string]: {
|
[scheme: string]: {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultColors(): ThemeColors {
|
|
||||||
return env.PUBLIC_THEME
|
|
||||||
? JSON.parse(env.PUBLIC_THEME)
|
|
||||||
: {
|
|
||||||
slate: {
|
|
||||||
25: '252 253 254',
|
|
||||||
50: '248 250 252',
|
|
||||||
100: '241 245 249',
|
|
||||||
200: '226 232 240',
|
|
||||||
300: '203 213 225',
|
|
||||||
400: '148 163 184',
|
|
||||||
500: '100 116 139',
|
|
||||||
600: '71 85 105',
|
|
||||||
700: '51 65 85',
|
|
||||||
800: '30 41 59',
|
|
||||||
900: '15 23 42',
|
|
||||||
950: '2 6 23',
|
|
||||||
},
|
|
||||||
zinc: {
|
|
||||||
50: `249 250 251`,
|
|
||||||
100: `243 244 246`,
|
|
||||||
200: `229 231 235`,
|
|
||||||
300: `209 213 219`,
|
|
||||||
400: `156 163 175`,
|
|
||||||
500: `107 114 128`,
|
|
||||||
600: `75 85 99`,
|
|
||||||
700: '50 60 76',
|
|
||||||
800: '22 31 45',
|
|
||||||
900: '17 24 39',
|
|
||||||
925: '8 12 25',
|
|
||||||
950: `5 9 16`,
|
|
||||||
},
|
|
||||||
primary: {
|
|
||||||
100: 'var(--c-p-100,241 245 249)',
|
|
||||||
900: 'var(--c-p-900,15 23 42)',
|
|
||||||
},
|
|
||||||
other: {
|
|
||||||
black: `var(--c-o-black,0 0 0)`,
|
|
||||||
white: `var(--c-o-white,255 255 255)`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDefaultTheme(): Theme {
|
|
||||||
return {
|
|
||||||
id: 0,
|
|
||||||
colors: getDefaultColors(),
|
|
||||||
name: 'Default',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hexToRgb(value: string) {
|
export function hexToRgb(value: string) {
|
||||||
// Regular expression to match valid hex color codes
|
// Regular expression to match valid hex color codes
|
||||||
const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||||
@@ -129,10 +79,18 @@ function themeStore(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export let themeData = writable<ThemeData>({
|
export let themeData = writable<ThemeData>(
|
||||||
scheme: 'system',
|
loadTheme() ?? {
|
||||||
themes: presets,
|
scheme: 'system',
|
||||||
currentTheme: 0,
|
themes: presets,
|
||||||
|
currentTheme: 0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
themeData.subscribe((themeData) => {
|
||||||
|
if (browser) {
|
||||||
|
localStorage.setItem('themeData', JSON.stringify(themeData))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export let theme = themeStore(
|
export let theme = themeStore(
|
||||||
@@ -177,7 +135,7 @@ export const inDarkColorScheme = (): boolean => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof localStorage != 'undefined') {
|
function loadColorScheme() {
|
||||||
const localColorScheme: ColorScheme =
|
const localColorScheme: ColorScheme =
|
||||||
(localStorage.getItem('colorScheme') as ColorScheme) ||
|
(localStorage.getItem('colorScheme') as ColorScheme) ||
|
||||||
configuredColorScheme
|
configuredColorScheme
|
||||||
@@ -202,3 +160,18 @@ if (typeof localStorage != 'undefined') {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadTheme() {
|
||||||
|
if (!browser) return
|
||||||
|
const localTheme = localStorage.getItem('themeData')
|
||||||
|
if (localTheme) {
|
||||||
|
return JSON.parse(localTheme)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browser) {
|
||||||
|
try {
|
||||||
|
loadColorScheme()
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
+95
-2
@@ -1,4 +1,55 @@
|
|||||||
import { getDefaultColors, getDefaultTheme, type Theme } from './colors'
|
import { env } from '$env/dynamic/public'
|
||||||
|
import type { Theme, ThemeColors } from './colors'
|
||||||
|
|
||||||
|
export function getDefaultColors(): ThemeColors {
|
||||||
|
return env.PUBLIC_THEME
|
||||||
|
? JSON.parse(env.PUBLIC_THEME)
|
||||||
|
: {
|
||||||
|
slate: {
|
||||||
|
25: '252 253 254',
|
||||||
|
50: '248 250 252',
|
||||||
|
100: '241 245 249',
|
||||||
|
200: '226 232 240',
|
||||||
|
300: '203 213 225',
|
||||||
|
400: '148 163 184',
|
||||||
|
500: '100 116 139',
|
||||||
|
600: '71 85 105',
|
||||||
|
700: '51 65 85',
|
||||||
|
800: '30 41 59',
|
||||||
|
900: '15 23 42',
|
||||||
|
950: '2 6 23',
|
||||||
|
},
|
||||||
|
zinc: {
|
||||||
|
50: '250 253 255',
|
||||||
|
100: '243 244 246',
|
||||||
|
300: '209 213 219',
|
||||||
|
400: '156 163 175',
|
||||||
|
500: '107 114 128',
|
||||||
|
600: '75 85 99',
|
||||||
|
700: '55 65 81',
|
||||||
|
800: '31 41 55',
|
||||||
|
900: '17 24 39',
|
||||||
|
925: '8 12 25',
|
||||||
|
950: '3 7 18',
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: 'var(--c-p-100,241 245 249)',
|
||||||
|
900: 'var(--c-p-900,15 23 42)',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
black: `var(--c-o-black,0 0 0)`,
|
||||||
|
white: `var(--c-o-white,255 255 255)`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultTheme(): Theme {
|
||||||
|
return {
|
||||||
|
id: 0,
|
||||||
|
colors: getDefaultColors(),
|
||||||
|
name: 'Default',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const presets: Theme[] = [
|
export const presets: Theme[] = [
|
||||||
getDefaultTheme(),
|
getDefaultTheme(),
|
||||||
@@ -44,6 +95,48 @@ export const presets: Theme[] = [
|
|||||||
id: -1,
|
id: -1,
|
||||||
name: 'Classic',
|
name: 'Classic',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
colors: {
|
||||||
|
slate: {
|
||||||
|
25: '252 253 254',
|
||||||
|
50: '248 250 252',
|
||||||
|
100: '241 245 249',
|
||||||
|
200: '226 232 240',
|
||||||
|
300: '203 213 225',
|
||||||
|
400: '148 163 184',
|
||||||
|
500: '100 116 139',
|
||||||
|
600: '71 85 105',
|
||||||
|
700: '51 65 85',
|
||||||
|
800: '30 41 59',
|
||||||
|
900: '15 23 42',
|
||||||
|
950: '2 6 23',
|
||||||
|
},
|
||||||
|
zinc: {
|
||||||
|
50: `249 250 251`,
|
||||||
|
100: `243 244 246`,
|
||||||
|
200: `229 231 235`,
|
||||||
|
300: `209 213 219`,
|
||||||
|
400: `156 163 175`,
|
||||||
|
500: `107 114 128`,
|
||||||
|
600: `75 85 99`,
|
||||||
|
700: '30 30 30',
|
||||||
|
800: '22 22 22',
|
||||||
|
900: '10 10 10',
|
||||||
|
925: '0 0 0',
|
||||||
|
950: `0 0 0`,
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: 'var(--c-p-100,241 245 249)',
|
||||||
|
900: 'var(--c-p-900,15 23 42)',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
black: `var(--c-o-black,0 0 0)`,
|
||||||
|
white: `var(--c-o-white,255 255 255)`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: -2,
|
||||||
|
name: 'AMOLED',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
colors: {
|
colors: {
|
||||||
zinc: {
|
zinc: {
|
||||||
@@ -69,7 +162,7 @@ export const presets: Theme[] = [
|
|||||||
},
|
},
|
||||||
slate: {},
|
slate: {},
|
||||||
},
|
},
|
||||||
id: -2,
|
id: -3,
|
||||||
name: 'Catppuccin',
|
name: 'Catppuccin',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
+97
-127
@@ -3,6 +3,7 @@
|
|||||||
Button,
|
Button,
|
||||||
Material,
|
Material,
|
||||||
Modal,
|
Modal,
|
||||||
|
Note,
|
||||||
TextArea,
|
TextArea,
|
||||||
action,
|
action,
|
||||||
modal,
|
modal,
|
||||||
@@ -20,13 +21,9 @@
|
|||||||
import ColorSwatch from './ColorSwatch.svelte'
|
import ColorSwatch from './ColorSwatch.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import {
|
import { calculateVars, hexToRgb, theme, themeData } from '$lib/ui/colors'
|
||||||
calculateVars,
|
import { getDefaultColors } from '$lib/ui/presets'
|
||||||
getDefaultColors,
|
import ThemePreset from './ThemePreset.svelte'
|
||||||
hexToRgb,
|
|
||||||
theme,
|
|
||||||
themeData,
|
|
||||||
} from '$lib/ui/colors'
|
|
||||||
|
|
||||||
let importing = false
|
let importing = false
|
||||||
let importText = ''
|
let importText = ''
|
||||||
@@ -59,56 +56,21 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-4 h-full">
|
<div class="flex flex-col gap-4 h-full">
|
||||||
<Header>Theme</Header>
|
<Header>Theme</Header>
|
||||||
<div class="flex flex-row items-center gap-4 overflow-auto h-36">
|
<div class="grid grid-cols-4 items-center gap-4 overflow-auto max-h-72">
|
||||||
{#each $themeData.themes as theme}
|
{#each $themeData.themes as theme}
|
||||||
<button
|
<ThemePreset {theme} />
|
||||||
class="h-full"
|
|
||||||
on:click={() => ($themeData.currentTheme = theme.id)}
|
|
||||||
>
|
|
||||||
<Material
|
|
||||||
padding="none"
|
|
||||||
class="{theme.id == $themeData.currentTheme
|
|
||||||
? 'ring-2 ring-inset ring-primary-900 dark:ring-primary-100'
|
|
||||||
: ''} flex relative cursor-pointer h-full flex-col text-left"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style="{calculateVars(theme)}; --bg-dark: {hexToRgb(
|
|
||||||
theme.colors.zinc?.[925]
|
|
||||||
)}; --bg-light: {hexToRgb(theme.colors.slate?.[25])} margin: 2px;"
|
|
||||||
class="h-20 w-48 rounded-lg rounded-b-none flex flex-row flex-wrap p-4 gap-2
|
|
||||||
theme-bg"
|
|
||||||
>
|
|
||||||
<div class="text-slate-900 dark:text-zinc-100 text-xs">
|
|
||||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="bg-white dark:bg-zinc-900 w-8 h-4 rounded-sm border border-slate-200 dark:border-zinc-800"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{#if theme.id == $themeData.currentTheme}
|
|
||||||
<Icon
|
|
||||||
src={CheckCircle}
|
|
||||||
size="20"
|
|
||||||
solid
|
|
||||||
class="absolute top-0 right-0 m-2 text-primary-900 dark:text-primary-100"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
<div class="px-4 py-2">
|
|
||||||
<span class="font-medium text-lg font-display">{theme.name}</span>
|
|
||||||
</div>
|
|
||||||
</Material>
|
|
||||||
</button>
|
|
||||||
{/each}
|
{/each}
|
||||||
<button
|
<button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
$themeData.themes = [
|
const newTheme = {
|
||||||
...$themeData.themes,
|
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
||||||
{
|
colors: getDefaultColors(),
|
||||||
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
name: `New Theme`,
|
||||||
colors: getDefaultColors(),
|
}
|
||||||
name: `New Theme`,
|
|
||||||
},
|
$themeData.themes = [...$themeData.themes, newTheme]
|
||||||
]
|
|
||||||
|
$themeData.currentTheme = newTheme.id
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Material
|
<Material
|
||||||
@@ -129,6 +91,7 @@
|
|||||||
importing = !importing
|
importing = !importing
|
||||||
}}
|
}}
|
||||||
size="lg"
|
size="lg"
|
||||||
|
disabled={$theme.id <= 0}
|
||||||
>
|
>
|
||||||
<Icon src={ArrowUpTray} size="16" mini />
|
<Icon src={ArrowUpTray} size="16" mini />
|
||||||
{$t('routes.theme.import')}
|
{$t('routes.theme.import')}
|
||||||
@@ -144,6 +107,7 @@
|
|||||||
{$t('routes.theme.export')}
|
{$t('routes.theme.export')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
disabled={$theme.id <= 0}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
modal({
|
modal({
|
||||||
actions: [
|
actions: [
|
||||||
@@ -170,75 +134,89 @@
|
|||||||
{$t('routes.theme.reset')}
|
{$t('routes.theme.reset')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Material color="transparent" class="items-center gap-x-4 color-grid gap-y-2">
|
{#if $theme.id <= 0}
|
||||||
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
|
<Note>
|
||||||
<ColorSwatch
|
{$t('routes.theme.preset.description')}
|
||||||
value={$theme.colors.primary?.[900]}
|
</Note>
|
||||||
on:change={(e) => {
|
{/if}
|
||||||
$theme.colors.primary[900] = e.detail
|
<div
|
||||||
}}
|
class="relative"
|
||||||
backgroundColor={defaultColors.primary[900]}
|
class:opacity-50={$theme.id <= 0}
|
||||||
on:contextmenu={(e) => {
|
class:pointer-events-none={$theme.id <= 0}
|
||||||
e.preventDefault()
|
>
|
||||||
$theme.colors.primary[900] =
|
<Material
|
||||||
// @ts-ignore
|
color="transparent"
|
||||||
defaultColors.primary[900]
|
class="items-center gap-x-4 color-grid gap-y-2"
|
||||||
|
>
|
||||||
|
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
|
||||||
|
<ColorSwatch
|
||||||
|
value={$theme.colors.primary?.[900]}
|
||||||
|
on:change={(e) => {
|
||||||
|
$theme.colors.primary[900] = e.detail
|
||||||
|
}}
|
||||||
|
backgroundColor={defaultColors.primary[900]}
|
||||||
|
on:contextmenu={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
$theme.colors.primary[900] =
|
||||||
|
// @ts-ignore
|
||||||
|
defaultColors.primary[900]
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}}
|
}}
|
||||||
class="!w-12 !h-12 col-span-1"
|
class="!w-12 !h-12 col-span-1"
|
||||||
/>
|
/>
|
||||||
<ColorSwatch
|
<ColorSwatch
|
||||||
value={$theme.colors.primary?.[100]}
|
value={$theme.colors.primary?.[100]}
|
||||||
on:change={(e) => {
|
on:change={(e) => {
|
||||||
$theme.colors.primary[100] = e.detail
|
$theme.colors.primary[100] = e.detail
|
||||||
}}
|
}}
|
||||||
backgroundColor={defaultColors.primary[100]}
|
backgroundColor={defaultColors.primary[100]}
|
||||||
on:contextmenu={(e) => {
|
on:contextmenu={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
$theme.colors.primary[100] =
|
$theme.colors.primary[100] =
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
defaultColors.primary[100]
|
defaultColors.primary[100]
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}}
|
}}
|
||||||
class="!w-12 !h-12 col-span-1"
|
class="!w-12 !h-12 col-span-1"
|
||||||
/>
|
/>
|
||||||
<span class="font-semibold text-base">
|
<span class="font-semibold text-base">
|
||||||
{$t('nav.menu.colorscheme.light')}
|
{$t('nav.menu.colorscheme.light')}
|
||||||
</span>
|
</span>
|
||||||
<span class="font-semibold text-base">
|
<span class="font-semibold text-base">
|
||||||
{$t('nav.menu.colorscheme.dark')}
|
{$t('nav.menu.colorscheme.dark')}
|
||||||
</span>
|
</span>
|
||||||
</Material>
|
</Material>
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||||
{#each Object.entries(defaultColors) as [category, value]}
|
{#each Object.entries(defaultColors) as [category, value]}
|
||||||
<Material color="transparent" class="flex flex-col gap-2">
|
<Material color="transparent" class="flex flex-col gap-2">
|
||||||
<h1 class="capitalize font-semibold text-lg">{category}</h1>
|
<h1 class="capitalize font-semibold text-lg">{category}</h1>
|
||||||
<div class="flex flex-row gap-1 flex-wrap items-center space-evenly">
|
<div class="flex flex-row gap-1 flex-wrap items-center space-evenly">
|
||||||
{#each Object.entries(value) as [shade, color]}
|
{#each Object.entries(value) as [shade, color]}
|
||||||
<div class="flex flex-col gap-0.5 w-10 group">
|
<div class="flex flex-col gap-0.5 w-10 group">
|
||||||
<!--@ts-ignore-->
|
<!--@ts-ignore-->
|
||||||
<ColorSwatch
|
<ColorSwatch
|
||||||
bind:value={$theme.colors[category][shade]}
|
bind:value={$theme.colors[category][shade]}
|
||||||
on:change={(e) => {
|
on:change={(e) => {
|
||||||
$theme.colors[category][shade] = e.detail
|
$theme.colors[category][shade] = e.detail
|
||||||
}}
|
}}
|
||||||
on:contextmenu={(e) => {
|
on:contextmenu={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
$theme.colors[category][shade] =
|
$theme.colors[category][shade] =
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
defaultColors[category][shade]
|
defaultColors[category][shade]
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span class="font-medium capitalize">{shade}</span>
|
<span class="font-medium capitalize">{shade}</span>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</Material>
|
</Material>
|
||||||
{/each}
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="flex items-center gap-2 sm:gap-8 flex-col sm:flex-row mt-auto mx-auto text-sm text-slate-600 dark:text-zinc-400"
|
class="flex items-center gap-2 sm:gap-8 flex-col sm:flex-row mt-auto mx-auto text-sm text-slate-600 dark:text-zinc-400"
|
||||||
@@ -260,12 +238,4 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content;
|
grid-template-columns: min-content min-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-bg {
|
|
||||||
background-color: rgb(var(--bg-light));
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark .theme-bg {
|
|
||||||
background-color: rgb(var(--bg-dark));
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
|
||||||
|
import { Button, Material, modal } from 'mono-svelte'
|
||||||
|
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let theme: Theme
|
||||||
|
|
||||||
|
let editing
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="h-full" on:click={() => ($themeData.currentTheme = theme.id)}>
|
||||||
|
<Material
|
||||||
|
padding="none"
|
||||||
|
class="{theme.id == $themeData.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"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style="{calculateVars(theme)};"
|
||||||
|
class="h-20 w-full rounded-lg rounded-b-none flex flex-row flex-wrap p-3 gap-2
|
||||||
|
bg-slate-25 dark:bg-zinc-925"
|
||||||
|
>
|
||||||
|
<div class="text-slate-900 dark:text-zinc-100 text-xs">
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="bg-white dark:bg-zinc-900 w-8 h-4 rounded-sm border border-slate-200 dark:border-zinc-800"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="w-3 h-3 bg-primary-900 dark:bg-primary-100 rounded-full ml-auto"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{#if theme.id == $themeData.currentTheme}
|
||||||
|
<Icon
|
||||||
|
src={CheckCircle}
|
||||||
|
size="20"
|
||||||
|
solid
|
||||||
|
class="absolute top-0 right-0 m-2 text-primary-900 dark:text-primary-100"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
<div class="px-4 py-2 flex items-center gap-1 justify-between">
|
||||||
|
<span class="font-medium text-lg font-display">{theme.name}</span>
|
||||||
|
<Button
|
||||||
|
color="ghost"
|
||||||
|
size="square-md"
|
||||||
|
on:click={() => {
|
||||||
|
modal({
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
close: true,
|
||||||
|
content: $t('common.cancel'),
|
||||||
|
type: 'secondary',
|
||||||
|
action: () => {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
close: true,
|
||||||
|
content: $t('routes.theme.preset.delete.confirm'),
|
||||||
|
type: 'danger',
|
||||||
|
action: () => {
|
||||||
|
const index = $themeData.themes
|
||||||
|
.map((t) => t.id)
|
||||||
|
.indexOf(theme.id)
|
||||||
|
|
||||||
|
$themeData.themes = $themeData.themes.toSpliced(index, 1)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
type: 'error',
|
||||||
|
body: '',
|
||||||
|
title: $t('routes.theme.preset.delete.title'),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Material>
|
||||||
|
</button>
|
||||||
Reference in new issue
Block a user