~james/core

core/web/src/lib/components/repo/PanelHeader.svelte -rw-r--r-- 1.3 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 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
43
44
45
46
<script lang="ts">
	import { resolve } from "$app/paths";
	import type { Component } from "svelte";
	import type { SvelteHTMLElements } from "svelte/elements";
	import { formatCount } from "#lib/format.ts";

	interface Props {
		title: string;
		href?: string;
		icon: Component<SvelteHTMLElements["svg"]>;
		count?: number;
		approximate?: boolean;
		compact?: boolean;
	}

	let { title, href, icon, count, approximate = false, compact = false }: Props = $props();
	const Glyph = $derived(icon);
	const formattedCount = $derived(
		count === undefined
			? undefined
			: approximate && count > 0
				? `${formatCount(count)}+`
				: formatCount(count)
	);
</script>

{#if compact}
	<a
		href={resolve(href as "/")}
		aria-label={title}
		class="hit-area-3 inline-flex items-center gap-2xs typography-paragraph-small font-bold text-foreground-default no-underline hover:underline"
	>
		<Glyph class="size-3.5 shrink-0" aria-hidden="true" />
		{formattedCount}
	</a>
{:else}
	<span class="flex items-center gap-xs font-medium text-foreground-default">
		<Glyph class="size-3.5 shrink-0" aria-hidden="true" />
		<span class="group-hover:underline">{title}</span>
		{#if count !== undefined}
			<span class="mt-px rounded-md bg-background-inset px-2xs typography-paragraph-small">
				{formattedCount}
			</span>
		{/if}
	</span>
{/if}