feat(ui): add InputColor and custom theme
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import {
|
||||
Details,
|
||||
InputCheckbox,
|
||||
InputColor,
|
||||
InputNumber,
|
||||
InputSelect,
|
||||
InputShape,
|
||||
@@ -10,6 +11,8 @@
|
||||
ShortCut
|
||||
} from '$lib';
|
||||
import Section from './Section.svelte';
|
||||
import Theme from './Theme.svelte';
|
||||
import ThemeSelector from './ThemeSelector.svelte';
|
||||
|
||||
let intValue = $state(0);
|
||||
let floatValue = $state(0.2);
|
||||
@@ -19,61 +22,22 @@
|
||||
let selectValue = $state(0);
|
||||
const d = $derived(options[selectValue]);
|
||||
let checked = $state(false);
|
||||
let colorValue = $state<[number, number, number]>([59, 130, 246]);
|
||||
let mirrorShape = $state(true);
|
||||
let detailsOpen = $state(false);
|
||||
|
||||
let points = $state([]);
|
||||
|
||||
const themes = [
|
||||
'dark',
|
||||
'light',
|
||||
'solarized',
|
||||
'catppuccin',
|
||||
'high-contrast',
|
||||
'nord',
|
||||
'dracula'
|
||||
];
|
||||
let themeIndex = $state(0);
|
||||
$effect(() => {
|
||||
const classList = document.documentElement.classList;
|
||||
for (const c of classList) {
|
||||
if (c.startsWith('theme-')) document.documentElement.classList.remove(c);
|
||||
}
|
||||
document.documentElement.classList.add(`theme-${themes[themeIndex]}`);
|
||||
});
|
||||
|
||||
const colors = [
|
||||
'layer-0',
|
||||
'layer-1',
|
||||
'layer-2',
|
||||
'layer-3',
|
||||
'active',
|
||||
'selected',
|
||||
'outline',
|
||||
'connection',
|
||||
'text'
|
||||
];
|
||||
let theme = $state('dark');
|
||||
</script>
|
||||
|
||||
<main class="flex flex-col gap-8 py-8">
|
||||
<div class="flex gap-4">
|
||||
<h1 class="text-4xl">@nodarium/ui</h1>
|
||||
<InputSelect bind:value={themeIndex} options={themes}></InputSelect>
|
||||
<ThemeSelector bind:theme />
|
||||
</div>
|
||||
|
||||
<Section title="Colors">
|
||||
<table>
|
||||
<tbody>
|
||||
{#each colors as color (color)}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="w-6 h-6 mr-2 my-1 rounded-sm outline-1 bg-{color}"></div>
|
||||
</td>
|
||||
<td>{color}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<Section title="InputNumber">
|
||||
<Theme theme />
|
||||
</Section>
|
||||
|
||||
<Section title="InputNumber">
|
||||
@@ -99,6 +63,10 @@
|
||||
<InputCheckbox bind:value={checked} />
|
||||
</Section>
|
||||
|
||||
<Section title="Color" value={colorValue}>
|
||||
<InputColor bind:value={colorValue} />
|
||||
</Section>
|
||||
|
||||
<Section title="Shape">
|
||||
{#snippet header()}
|
||||
<label class="flex gap-2">
|
||||
|
||||
80
packages/ui/src/routes/Theme.svelte
Normal file
80
packages/ui/src/routes/Theme.svelte
Normal file
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
import { InputColor } from '$lib';
|
||||
|
||||
interface Props {
|
||||
theme?: string;
|
||||
}
|
||||
|
||||
let { theme }: Props = $props();
|
||||
|
||||
const colors = [
|
||||
'layer-0',
|
||||
'layer-1',
|
||||
'layer-2',
|
||||
'layer-3',
|
||||
'active',
|
||||
'selected',
|
||||
'outline',
|
||||
'connection',
|
||||
'text'
|
||||
];
|
||||
|
||||
let customColors = $state<CustomColors>({
|
||||
text: [205, 214, 244],
|
||||
outline: [62, 62, 79],
|
||||
'layer-0': [6, 6, 27],
|
||||
'layer-1': [23, 23, 46],
|
||||
'layer-2': [49, 50, 68],
|
||||
'layer-3': [168, 170, 200],
|
||||
active: [0, 0, 0],
|
||||
selected: [38, 139, 210],
|
||||
connection: [131, 148, 150]
|
||||
});
|
||||
|
||||
const themeCss = $derived.by(() => {
|
||||
return `<style>html.theme-custom{
|
||||
${
|
||||
Object.keys(customColors)
|
||||
.map((v) => {
|
||||
return `--color-${v}: rgb(${customColors[v].join(',')});`;
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
</style>`;
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
{@html themeCss}
|
||||
</svelte:head>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Color</th>
|
||||
<th>Name</th>
|
||||
<th>Custom</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each colors as color (color)}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="w-6 h-6 mr-2 my-1 rounded-sm outline-1 bg-{color}"></div>
|
||||
</td>
|
||||
<td>{color}</td>
|
||||
<td>
|
||||
<InputColor bind:value={customColors[color]} />
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<style>
|
||||
table {
|
||||
border-spacing: 5px;
|
||||
border-collapse: separate;
|
||||
text-align: left;
|
||||
margin-left: 5px;
|
||||
}
|
||||
27
packages/ui/src/routes/ThemeSelector.svelte
Normal file
27
packages/ui/src/routes/ThemeSelector.svelte
Normal file
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { InputSelect } from '$lib';
|
||||
const themes = [
|
||||
'dark',
|
||||
'light',
|
||||
'solarized',
|
||||
'catppuccin',
|
||||
'high-contrast',
|
||||
'nord',
|
||||
'dracula',
|
||||
'custom'
|
||||
];
|
||||
|
||||
let { theme = $bindable() } = $props();
|
||||
|
||||
let themeIndex = $state(0);
|
||||
$effect(() => {
|
||||
theme = themes[themeIndex];
|
||||
const classList = document.documentElement.classList;
|
||||
for (const c of classList) {
|
||||
if (c.startsWith('theme-')) document.documentElement.classList.remove(c);
|
||||
}
|
||||
document.documentElement.classList.add(`theme-${themes[themeIndex]}`);
|
||||
});
|
||||
</script>
|
||||
|
||||
<InputSelect bind:value={themeIndex} options={themes}></InputSelect>
|
||||
Reference in New Issue
Block a user