~james/core

core/web/src/lib/components/comment/CommentBox.svelte -rw-r--r-- 1.5 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script lang="ts">
	import MessageSquarePlus from "$icon/message-square-plus";
	import type { KnotOrigin } from "#lib/api/syntax.ts";
	import Reply from "$icon/reply";
	import { type MarkupContext } from "#lib/markup/index.ts";
	import CommentEditor from "#lib/components/comment/CommentEditor.svelte";
	import type { ThreadInput } from "#lib/components/comment/comments.ts";

	interface Props {
		subjectUri: string;
		subjectCid?: string;
		replyToUri?: string;
		replyToCid?: string;
		authorDid: string;
		authorHandle: string;
		markup: MarkupContext;
		knot?: KnotOrigin;
		// "thread" tucks the box into a comment card, matching its canvas background
		variant?: "default" | "thread";
		onsubmitted?: (submitted: ThreadInput) => void;
	}

	let {
		subjectUri,
		subjectCid,
		replyToUri,
		replyToCid,
		authorDid,
		authorHandle,
		markup,
		knot,
		variant = "default",
		onsubmitted
	}: Props = $props();

	const isThread = $derived(variant === "thread");
</script>

{#snippet editor()}
	<CommentEditor
		{subjectUri}
		{subjectCid}
		{replyToUri}
		{replyToCid}
		{authorDid}
		{authorHandle}
		{markup}
		{knot}
		placeholder={isThread
			? "Leave a reply..."
			: "Add to the discussion. Markdown is supported."}
		submitLabel={isThread ? "Reply" : "Comment"}
		submitIcon={isThread ? Reply : MessageSquarePlus}
		compact={isThread}
		layered={!isThread}
		{onsubmitted}
	/>
{/snippet}

{#if isThread}
	<div class="rounded-b-md bg-background-default/50 py-2xs pr-2xs pl-xl">
		{@render editor()}
	</div>
{:else}
	{@render editor()}
{/if}