~james/core

core/web/src/lib/components/repo/CommitShaButton.svelte -rw-r--r-- 2.2 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
64
65
66
67
<script lang="ts">
	import ShieldCheck from "$icon/shield-check";
	import type { VerifiedSignature } from "#lib/components/repo/commitSignature.ts";
	import CopyButton from "#lib/components/ui/CopyButton.svelte";
	import Tooltip from "#lib/components/ui/Tooltip.svelte";
	import RevId from "#lib/components/repo/RevId.svelte";
	import { shiftKey } from "#lib/shiftKey.svelte.ts";

	interface Props {
		hash: string;
		shortHash: string;
		changeId?: string;
		changeIds?: string[];
		signature?: VerifiedSignature;
		full?: boolean;
	}

	let { hash, shortHash, changeId, changeIds = [], signature, full = false }: Props = $props();

	const shortChangeId = $derived(shiftKey.held ? changeId?.slice(0, 8) : undefined);
	const target = $derived(shortChangeId ? "change ID" : "SHA");
</script>

{#snippet signed()}
	<span class="flex flex-col gap-2xs">
		<span class="font-medium">Verified signature</span>
		{#if signature?.committer}
			<span>Signed by {signature.committer}</span>
		{/if}
		{#if signature?.fingerprint}
			<span class="typography-monospace-small break-all opacity-80"
				>{signature.fingerprint}</span
			>
		{/if}
		<span class="opacity-80">Click to copy {target}</span>
	</span>
{/snippet}

<Tooltip content={signature ? signed : `Copy ${target}`}>
	<CopyButton
		value={shortChangeId && changeId ? changeId : hash}
		aria-label={shortChangeId
			? `Copy change ID ${shortChangeId}`
			: `Copy SHA ${shortHash}${signature ? ", verified signature" : ""}`}
		class={signature
			? "min-h-5 bg-background-success-subtle py-0 typography-monospace-small text-foreground-success-strong hover:bg-background-success-subtle-hover"
			: "typography-monospace-small"}
	>
		<span class="flex items-center gap-2xs">
			{#if signature}
				<ShieldCheck class="size-3.5 shrink-0" aria-hidden="true" />
			{/if}
			{#if shortChangeId && changeId}
				<RevId id={changeId} kind="change-id" ids={changeIds} />
			{:else if full}
				<span class={["sm:hidden", shiftKey.held && "text-foreground-subtle"]}
					>{shortHash}</span
				>
				<span class={["hidden sm:inline", shiftKey.held && "text-foreground-subtle"]}
					>{hash}</span
				>
			{:else}
				<span class={[shiftKey.held && "text-foreground-subtle"]}>{shortHash}</span>
			{/if}
		</span>
	</CopyButton>
</Tooltip>