blob: 1ae7c3251a200906f2ea478557910ad29ede6ae2 (
plain) (
blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<script lang="ts" module>
import { getContext, setContext } from 'svelte';
type Tab = string;
type Tabs = Record<Tab, { title: string }>;
class TabContext {
tabs: Tabs = $state({});
current: Tab = $state('');
}
export function getTabContext() {
return getContext<TabContext>('tabs');
}
function initTabContext() {
return setContext('tabs', new TabContext());
}
</script>
<script lang="ts">
import { fadeFast } from '$lib/Transitions';
import type { Snippet } from 'svelte';
import { fade } from 'svelte/transition';
let { badges = {}, children }: { badges?: Record<Tab, boolean>; children?: Snippet } = $props();
const context = initTabContext();
</script>
<div class="flex h-full max-h-full flex-col">
<nav>
<ul class="me-3 ms-1 flex border-b-2 border-slate-700 text-sm">
{#each Object.entries(context.tabs) as [id, { title }]}
<li class="-mb-0.5">
<button
type="button"
class:active={context.current === id}
class="focus-background relative flex gap-1 p-1 px-3 hover:border-b-2 hover:border-slate-200"
onclick={() => (context.current = id)}
>
{#if badges[id]}
<div
class="absolute right-0 top-1 h-2 w-2 rounded-full bg-emerald-400"
title="There are pending changes"
transition:fade={fadeFast}
></div>
{/if}
<span>{title}</span>
</button>
</li>
{/each}
</ul>
</nav>
{@render children?.()}
</div>
<style lang="postcss">
button.active {
@apply border-b-2 border-indigo-500;
}
</style>
|