feat: add basic theming support
This commit is contained in:
1 parent
2d991fc4a2
commit
81ac6accf4
7 files changed
+299
-72
No files matched your search
@@ -8,7 +8,7 @@
|
||||
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
|
||||
// @ts-ignore
|
||||
import { pwaInfo } from 'virtual:pwa-info'
|
||||
import { inDarkTheme, theme } from '$lib/ui/colors.js'
|
||||
import { inDarkLegacyTheme, legacyTheme } from '$lib/ui/colors.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { Button, Spinner, ToastContainer } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
|
||||
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
|
||||
$: darkTheme = $theme && inDarkTheme()
|
||||
$: darklegacyTheme = $legacyTheme && inDarkLegacyTheme()
|
||||
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
@@ -55,7 +55,7 @@
|
||||
window
|
||||
.matchMedia('(prefers-color-scheme: dark)')
|
||||
.addEventListener('change', (event) => {
|
||||
darkTheme = inDarkTheme()
|
||||
darklegacyTheme = inDarkLegacyTheme()
|
||||
})
|
||||
document.body.querySelector('.loader')?.classList.add('hidden')
|
||||
}
|
||||
@@ -64,7 +64,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta name="theme-color" content={darkTheme ? '#09090b' : '#f8fafc'} />
|
||||
<meta name="theme-color" content={darklegacyTheme ? '#09090b' : '#f8fafc'} />
|
||||
{#if $site}
|
||||
<title>{$site.site_view.site.name}</title>
|
||||
{#if LINKED_INSTANCE_URL}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<script lang="ts">
|
||||
import { Button, Material, Modal, TextArea, toast } from 'mono-svelte'
|
||||
import { defaultColors, type Colors, colors } from '$lib/ui/colors'
|
||||
import { ArrowDownTray, ArrowUpTray, Bookmark, Icon } from 'svelte-hero-icons'
|
||||
|
||||
const c = defaultColors
|
||||
|
||||
const svelteIntellisenseSucks = (): (keyof Colors)[] =>
|
||||
Object.keys(c) as (keyof Colors)[]
|
||||
|
||||
let importing = false
|
||||
let importText = ''
|
||||
</script>
|
||||
|
||||
{#if importing}
|
||||
<Modal
|
||||
bind:open={importing}
|
||||
on:action={() => {
|
||||
try {
|
||||
if (importText == '') {
|
||||
throw new Error('Import is empty')
|
||||
}
|
||||
$colors = JSON.parse(importText)
|
||||
toast({ content: 'Import successful', type: 'success' })
|
||||
importing = false
|
||||
} catch (err) {
|
||||
// @ts-ignore
|
||||
toast({ content: err, type: 'error' })
|
||||
}
|
||||
}}
|
||||
title="Import"
|
||||
action="Import"
|
||||
>
|
||||
<TextArea bind:value={importText} style="font-family: monospace;" />
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<h1 class="font-bold text-3xl">Theme</h1>
|
||||
<div class="flex items-center gap-4">
|
||||
<Button
|
||||
on:click={() => {
|
||||
importing = !importing
|
||||
}}
|
||||
size="lg"
|
||||
>
|
||||
<Icon src={ArrowUpTray} size="16" mini />
|
||||
Import
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
navigator.clipboard.writeText(JSON.stringify($colors))
|
||||
toast({ content: 'Copied theme to clipboard.' })
|
||||
}}
|
||||
size="lg"
|
||||
>
|
||||
<Icon src={ArrowDownTray} size="16" mini />
|
||||
Export
|
||||
</Button>
|
||||
<Button on:click={() => {}} size="lg">
|
||||
<Icon src={Bookmark} size="16" mini />
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
{#each svelteIntellisenseSucks() as category}
|
||||
<Material class="flex flex-col gap-2">
|
||||
<h1 class="capitalize font-semibold text-lg">{category}</h1>
|
||||
<div class="flex flex-row gap-1 flex-wrap items-center justify-between">
|
||||
{#each Object.keys(c[category]) as shade}
|
||||
<div class="flex flex-col gap-0.5 w-10 group">
|
||||
<div
|
||||
class="w-full h-8 relative rounded-md border dark:border-zinc-600 hover:dark:border-zinc-400
|
||||
transition-colors"
|
||||
style="background-color: {defaultColors[category][shade]}"
|
||||
>
|
||||
<input
|
||||
class="rounded-md border cursor-pointer absolute top-0 left-0 w-full h-full opacity-0"
|
||||
type="color"
|
||||
bind:value={$colors[category][shade]}
|
||||
/>
|
||||
</div>
|
||||
<span class="font-medium capitalize">{shade}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</Material>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user