~james/core

core/web/src/lib/components/settings/SettingsNav.svelte -rw-r--r-- 1.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script module lang="ts">
	import type { TabDef } from "#lib/components/ui/Tabs.svelte";

	export type SettingsNavItem = TabDef;
</script>

<script lang="ts">
	import { goto } from "$app/navigation";
	import { resolve } from "$app/paths";
	import Select from "#lib/components/ui/Select.svelte";
	import Tabs from "#lib/components/ui/Tabs.svelte";
	import Separator from "#lib/components/ui/Separator.svelte";

	interface Props {
		items: SettingsNavItem[];
		active: string;
		label?: string;
	}

	let { items, active, label = "Settings" }: Props = $props();

	const options = $derived(items.map((item) => ({ value: item.id, label: item.label })));
	const ActiveGlyph = $derived(items.find((i) => i.id === active)?.icon);

	const jump = (id: string) => {
		const item = items.find((i) => i.id === id);
		if (item) void goto(resolve(item.href as "/"));
	};
</script>

<div class="flex w-full flex-col gap-md md:hidden">
	<Select {options} value={active} onSelect={jump} {label} icon={ActiveGlyph} />
	<Separator />
</div>

<Tabs
	tabs={items}
	{active}
	{label}
	vertical
	class="hidden shrink-0 bg-background-navigation-frame p-xs md:flex md:w-44 md:self-stretch md:border-r md:border-border-default"
/>