# Thread

One comment thread for any subject: replies, person and agent authors, resolve, a canvas pin and labels you can translate.

Section: Blocks / Work
Page: https://ui.heyramzi.com/components/thread
Import path: `@heyramzi/ui/thread`

## Import

```ts
import { Thread, type ThreadComment, type ThreadLabels, type ThreadPost, } from "@heyramzi/ui/thread";
import { Button } from "@heyramzi/ui/shadcn/button";
```

## Usage

```svelte
<Thread
  {comments}
  {onPost}
  {onEdit}
  {onDelete}
  {onResolve}
  canEdit={(comment) => comment.author.kind === "user"}
/>
```

## Demo

```svelte
<script lang="ts">
	import {
		Thread,
		type ThreadComment,
		type ThreadLabels,
		type ThreadPost,
	} from "@heyramzi/ui/thread";
	import { Button } from "@heyramzi/ui/shadcn/button";

	const ada = { kind: "user", name: "Ada Okafor" } as const;
	const scribe = { kind: "agent", name: "Scribe" } as const;

	let comments = $state<ThreadComment[]>([
		{
			id: "c1",
			author: ada,
			body: "The three plans fit one screen on a laptop. Can we cut the table under it?",
			createdAt: "2026-10-22T08:40:00Z",
		},
		{
			id: "c2",
			author: scribe,
			body: "Cut it. The comparison now sits in the plan cards, 4 rows each.",
			createdAt: "2026-10-22T08:52:00Z",
			parentId: "c1",
		},
		{
			id: "c3",
			author: ada,
			body: "",
			content: {
				type: "doc",
				content: [
					{
						type: "paragraph",
						content: [
							{ type: "text", text: "Pin this on the pricing node: " },
							{ type: "text", text: "the headline", marks: [{ type: "bold" }] },
							{ type: "text", text: " still says per seat." },
						],
					},
				],
			},
			createdAt: "2026-10-22T09:10:00Z",
			anchor: { nodeId: "pricing", dx: 12, dy: -8 },
		},
		{
			id: "c4",
			author: scribe,
			body: "Footer links checked, none are broken.",
			createdAt: "2026-10-21T16:00:00Z",
			resolved: true,
		},
	]);

	const french: Partial<ThreadLabels> = {
		title: "Activité",
		placeholder: "Écrire un commentaire",
		replyPlaceholder: "Répondre",
		send: "Commenter",
		sending: "Envoi",
		reply: "Répondre",
		resolve: "Résoudre",
		unresolve: "Rouvrir",
		resolved: "Résolu",
		showResolved: "Afficher {count} résolu",
		hideResolved: "Masquer les résolus",
		edit: "Modifier le commentaire",
		delete: "Supprimer le commentaire",
		edited: "modifié",
		save: "Enregistrer",
		cancel: "Annuler",
		pinned: "Épinglé",
	};

	let fr = $state(false);

	function onPost({ body, parentId }: ThreadPost) {
		comments = [
			...comments,
			{ id: crypto.randomUUID(), author: ada, body, parentId, createdAt: new Date().toISOString() },
		];
	}

	function onEdit(comment: ThreadComment, body: string) {
		comments = comments.map((c) => (c.id === comment.id ? { ...c, body, edited: true } : c));
	}

	function onDelete(comment: ThreadComment) {
		comments = comments.filter((c) => c.id !== comment.id);
	}

	function onResolve(comment: ThreadComment, resolved: boolean) {
		comments = comments.map((c) => (c.id === comment.id ? { ...c, resolved } : c));
	}
</script>

<div class="mx-auto flex max-w-xl flex-col gap-3">
	<div class="flex justify-end">
		<Button size="sm" variant="outline" aria-pressed={fr} onclick={() => (fr = !fr)}>FR</Button>
	</div>
	<Thread
		{comments}
		labels={fr ? french : undefined}
		{onPost}
		{onEdit}
		{onDelete}
		{onResolve}
		onAnchor={() => {}}
		canEdit={(comment) => comment.author.kind === "user"}
	/>
</div>
```

## API

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `comments` | `ThreadComment[]` |  | required |
| `events` | `ThreadEvent[]` | `[]` | Status moves, assignments and the like, one quiet line each between the comments. |
| `loading` | `boolean` | `false` | Rows still on their way. Draws skeleton rows in place of the thread. |
| `labels` | `Partial<ThreadLabels>` |  |  |
| `avatar` | `Snippet<[ThreadComment]>` |  | Replaces the default avatar for a person or an agent, drawn in a 24px slot. |
| `attachments` | `Snippet<[ThreadComment]>` |  | Content under a comment's body, such as files. |
| `anchorChip` | `Snippet<[ThreadComment]>` |  | Replaces the default "Pinned" chip on a comment that has an anchor. |
| `when` | `(comment: ThreadComment) => string` | `(comment) => shortDate(comment.createdAt, { locale })` | How a timestamp reads. Defaults to a short date. |
| `whenEvent` | `(event: ThreadEvent) => string` | `(event) => shortDate(event.at, { locale })` | How an event's time reads. Defaults to a short date. |
| `locale` | `string` | `"en-GB"` | The locale the default times read in. |
| `onPost` | `(post: ThreadPost) => void \| boolean \| Promise<void \| boolean>` |  | Returns false to keep the draft. Without it no composer shows. |
| `onEdit` | `(comment: ThreadComment, body: string) => void \| Promise<void>` |  |  |
| `onDelete` | `(comment: ThreadComment) => void \| Promise<void>` |  |  |
| `onResolve` | `(comment: ThreadComment, resolved: boolean) => void \| Promise<void>` |  | Without it a root has no resolve button. |
| `onAnchor` | `(comment: ThreadComment) => void` |  | A click on a pinned comment's chip, to move a canvas to its node. |
| `canEdit` | `(comment: ThreadComment) => boolean` | `() => false` | Whose comments carry the edit and delete buttons. A rich comment can't be edited here. |
| `heading` | `boolean` | `true` | False hides the visible title, for a thread already named by its tab. Screen readers still get it. |
| `footer` | `Snippet` |  | Drawn above the composer, such as a question waiting on an answer. |
| `class` | `string` |  |  |
