Adds a theme selector
This commit is contained in:
20
src/lib/components/ThemeVariantButton.svelte
Normal file
20
src/lib/components/ThemeVariantButton.svelte
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { themeVariant, type ThemeVariant } from '$lib/themeVariant';
|
||||||
|
|
||||||
|
const variants: Array<ThemeVariant> = ['default', 'dark', 'light'];
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
const newVariant = (variants.findIndex((v) => v == $themeVariant) + 1) % 3;
|
||||||
|
themeVariant.set(variants[newVariant]);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={next}>
|
||||||
|
{#if $themeVariant == 'default'}
|
||||||
|
<i class="fa fa-circle-half-stroke" />
|
||||||
|
{:else if $themeVariant == 'light'}
|
||||||
|
<i class="fa-regular fa-circle" />
|
||||||
|
{:else if $themeVariant == 'dark'}
|
||||||
|
<i class="fa-solid fa-circle" />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
5
src/lib/themeVariant.ts
Normal file
5
src/lib/themeVariant.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { persistentWritable } from './persistentStore';
|
||||||
|
|
||||||
|
export type ThemeVariant = 'default' | 'dark' | 'light';
|
||||||
|
|
||||||
|
export const themeVariant = persistentWritable<ThemeVariant>('theme-variant', 'default');
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '@fortawesome/fontawesome-free/css/all.min.css';
|
import '@fortawesome/fontawesome-free/css/all.min.css';
|
||||||
|
import { themeVariant } from '$lib/themeVariant';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot />
|
<div class:is-light={$themeVariant == 'light'} class:is-dark={$themeVariant == 'dark'}>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,16 +1,39 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Brand from '$lib/components/Brand.svelte';
|
import Brand from '$lib/components/Brand.svelte';
|
||||||
import ServiceGroup from '$lib/components/ServiceGroup.svelte';
|
import ServiceGroup from '$lib/components/ServiceGroup.svelte';
|
||||||
|
import ThemeVariantButton from '$lib/components/ThemeVariantButton.svelte';
|
||||||
|
import type { ColorConfig } from '$lib/config';
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
function renderColorVariables(): string {
|
function cssVariables(colors: ColorConfig): string {
|
||||||
const cssVars: Array<string> = [];
|
const cssVars: Array<string> = [];
|
||||||
for (const [key, value] of Object.entries(data.config.colors.dark)) {
|
for (const [key, value] of Object.entries(colors)) {
|
||||||
cssVars.push(`--${key}:${value}`);
|
cssVars.push(`--${key}:${value}`);
|
||||||
}
|
}
|
||||||
return '<style>:root{' + cssVars.join(';') + '}</style>';
|
return cssVars.join(';');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderColorVariables() {
|
||||||
|
return `<style>
|
||||||
|
:root, body .is-light {
|
||||||
|
${cssVariables(data.config.colors.light)}
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: light), (prefers-color-scheme: no-preference) {
|
||||||
|
:root, body {
|
||||||
|
${cssVariables(data.config.colors.light)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
:root, body .is-dark {
|
||||||
|
${cssVariables(data.config.colors.dark)}
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root, body {
|
||||||
|
${cssVariables(data.config.colors.dark)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>`;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -26,6 +49,7 @@
|
|||||||
{#if data.config.subtitle}
|
{#if data.config.subtitle}
|
||||||
<h2>{data.config.subtitle}</h2>
|
<h2>{data.config.subtitle}</h2>
|
||||||
{/if}
|
{/if}
|
||||||
|
<ThemeVariantButton />
|
||||||
</header>
|
</header>
|
||||||
{#each data.config.services as group, i}
|
{#each data.config.services as group, i}
|
||||||
<ServiceGroup {group} groupData={data.serviceData[i]} />
|
<ServiceGroup {group} groupData={data.serviceData[i]} />
|
||||||
|
|||||||
Reference in New Issue
Block a user