feat: add name editing
This commit is contained in:
1 parent
926af69ec5
commit
9c9e5dff76
4 files changed
+44
-6
No files matched your search
@@ -366,7 +366,11 @@
|
|||||||
"delete": {
|
"delete": {
|
||||||
"title": "Delete Theme",
|
"title": "Delete Theme",
|
||||||
"confirm": "Confirm"
|
"confirm": "Confirm"
|
||||||
}
|
},
|
||||||
|
"default": "Default",
|
||||||
|
"classic": "Classic",
|
||||||
|
"imported": "Your Theme",
|
||||||
|
"new": "New Theme"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"community": {
|
"community": {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import { getDefaultTheme, presets } from './presets'
|
import { getDefaultTheme, presets } from './presets'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
type ColorScheme = 'system' | 'light' | 'dark'
|
type ColorScheme = 'system' | 'light' | 'dark'
|
||||||
|
|
||||||
@@ -164,9 +165,11 @@ function loadColorScheme() {
|
|||||||
function loadTheme() {
|
function loadTheme() {
|
||||||
if (!browser) return
|
if (!browser) return
|
||||||
const localTheme = localStorage.getItem('themeData')
|
const localTheme = localStorage.getItem('themeData')
|
||||||
|
|
||||||
if (localTheme) {
|
if (localTheme) {
|
||||||
return JSON.parse(localTheme)
|
return JSON.parse(localTheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,4 +177,21 @@ if (browser) {
|
|||||||
try {
|
try {
|
||||||
loadColorScheme()
|
loadColorScheme()
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
try {
|
||||||
|
const oldColors = localStorage.getItem('colors')
|
||||||
|
if (oldColors) {
|
||||||
|
themeData.update((td) => ({
|
||||||
|
...td,
|
||||||
|
themes: [
|
||||||
|
...td.themes,
|
||||||
|
{
|
||||||
|
id: Math.max(...td.themes.map((t) => t.id)) + 1,
|
||||||
|
colors: JSON.parse(oldColors),
|
||||||
|
name: t.get('routes.theme.preset.imported') ?? 'Your Theme',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
localStorage.removeItem('colors')
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
@@ -61,14 +61,14 @@
|
|||||||
gap-4 overflow-auto max-h-72"
|
gap-4 overflow-auto max-h-72"
|
||||||
>
|
>
|
||||||
{#each $themeData.themes as theme}
|
{#each $themeData.themes as theme}
|
||||||
<ThemePreset {theme} />
|
<ThemePreset bind:theme />
|
||||||
{/each}
|
{/each}
|
||||||
<button
|
<button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
const newTheme = {
|
const newTheme = {
|
||||||
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
||||||
colors: getDefaultColors(),
|
colors: getDefaultColors(),
|
||||||
name: `New Theme`,
|
name: $t('routes.theme.preset.new'),
|
||||||
}
|
}
|
||||||
|
|
||||||
$themeData.themes = [...$themeData.themes, newTheme]
|
$themeData.themes = [...$themeData.themes, newTheme]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
|
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
|
||||||
import { action, Button, Material, modal } from 'mono-svelte'
|
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
|
||||||
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let theme: Theme
|
export let theme: Theme
|
||||||
|
|
||||||
let editing
|
let editingName = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button class="h-full" on:click={() => ($themeData.currentTheme = theme.id)}>
|
<button class="h-full" on:click={() => ($themeData.currentTheme = theme.id)}>
|
||||||
@@ -40,11 +40,25 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="px-4 py-2 flex items-center gap-1 justify-between">
|
<div class="px-4 py-2 flex items-center gap-1 justify-between">
|
||||||
<span class="font-medium text-lg font-display">{theme.name}</span>
|
{#if editingName}
|
||||||
|
<form on:submit|preventDefault={() => (editingName = false)}>
|
||||||
|
<TextInput bind:value={theme.name}></TextInput>
|
||||||
|
</form>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
if (theme.id > 0) editingName = true
|
||||||
|
}}
|
||||||
|
class="text-left font-medium text-lg font-display"
|
||||||
|
>
|
||||||
|
{theme.name}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
{#if theme.id > 0}
|
{#if theme.id > 0}
|
||||||
<Button
|
<Button
|
||||||
color="ghost"
|
color="ghost"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
|
class="flex-shrink-0"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
modal({
|
modal({
|
||||||
actions: [
|
actions: [
|
||||||
|
|||||||
Reference in new issue
Block a user