~james/core

core/web/src/lib/components/repo/DiffStatPill.svelte -rw-r--r-- 1.5 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script module lang="ts">
	import { tv, type VariantProps } from "tailwind-variants";

	export const diffStatPill = tv({
		slots: {
			root: "flex items-center overflow-clip rounded-md",
			insertions: "text-foreground-success select-none",
			deletions: "text-foreground-danger select-none"
		},
		variants: {
			variant: {
				flat: {
					insertions: "p-3xs",
					deletions: "p-3xs"
				},
				background: {
					insertions: "bg-background-success-subtle px-2xs py-3xs",
					deletions: "bg-background-danger-subtle px-2xs py-3xs"
				}
			},
			size: {
				small: { root: "typography-monospace-small" },
				regular: { root: "typography-monospace-regular" }
			}
		},
		defaultVariants: {
			variant: "background",
			size: "regular"
		}
	});

	export type DiffStatPillVariants = VariantProps<typeof diffStatPill>;
</script>

<script lang="ts">
	import type { LineStat } from "#lib/api/diff.ts";

	interface Props {
		stat: LineStat;
		class?: string;
		size?: DiffStatPillVariants["size"];
		variant?: DiffStatPillVariants["variant"];
	}

	let { stat, class: className = "", size, variant }: Props = $props();

	const style = $derived(diffStatPill({ variant, size }));
</script>

{#if stat.insertions > 0 || stat.deletions > 0}
	<div class={style.root({ class: className })}>
		{#if stat.insertions > 0}
			<span class={style.insertions()}>
				+{stat.insertions}
			</span>
		{/if}
		{#if stat.deletions > 0}
			<span class={style.deletions()}>
				-{stat.deletions}
			</span>
		{/if}
	</div>
{/if}