Comment Thread
One conversation on a piece of content: the first comment and its replies, a reply box, edit and delete on your own comments, and Resolve.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
comments | ThreadComment[] | [] | The thread, oldest first. As an attribute, a JSON array of { id, author, body, time, edited?, reactions? }. |
current-user | CommentAuthor | null | null | Who is writing, as { id?, name, avatar? }. Their comments can be edited and deleted. Without one, the thread is
read-only. As an attribute, a JSON object: a template that writes attributes (server rendering, or Svelte before the
element is registered) must pass JSON.stringify(user), since an object written as an attribute arrives as
[object Object]. |
quote | string | — | The text the thread is about, shown as a quote above the first comment. |
resolved | boolean | false | Whether the thread is resolved: it folds down to its first comment. |
reactions | boolean | false | Shows a reaction bar under each comment. |
collapse-after | number | 4 | Past this many replies (at least 3), only the first and the last two show until "Show N earlier replies" is pressed. |
readonly | boolean | false | No reply box, edit, delete or resolve. |
no-resolve | boolean | false | No Resolve button, for a page that resolves the thread through controls of its own. resolved still folds it. |
label | string | — | The accessible name of the thread. |
Events
| Name | Type | Description |
|---|---|---|
comment-add | CustomEvent<{ body: string }> | Cancelable. The user sends a reply (the Reply button, or Ctrl/⌘+Enter). |
comment-edit | CustomEvent<{ id: string | number; body: string }> | Cancelable. The user saves an edited comment. |
comment-delete | CustomEvent<{ id: string | number }> | Cancelable. The user confirms deleting a comment. Deleting the first one is left to the app. |
resolve-change | CustomEvent<{ resolved: boolean }> | Cancelable. The user resolves or reopens the thread. |
reaction-change | CustomEvent<{ id: string | number; emoji: string; reacted: boolean; count: number }> | Cancelable. The user adds or removes a reaction on a comment. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
quote | The quoted text the thread is about. |
comment | One comment. |
author | A comment's author name. |
time | A comment's time. |
body | A comment's text. |
mention | An @mention in a comment's text. |
action | Every small button (Resolve, Edit, Delete, Cancel, Show earlier replies). |
resolve-action | The Resolve / Reopen button on the first comment. |
edit-action | The Edit button (a pencil icon) on one's own comment. |
delete-action | The Delete button (a trash icon) on one's own comment. |
cancel-action | The Cancel button of the reply box and of a comment being edited. |
more-action | The "Show N earlier replies" button. |
composer | The reply box with its buttons. |
submit | The Reply and Save buttons. |
add | Shadow DOM styling hook for the add element. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-comment-thread--font-size | font-size | 14px | |
--c2-comment-thread--color | color | #18181b | |
--c2-comment-thread--background | color | #ffffff | |
--c2-comment-thread--border | border | 1px solid #e4e4e7 | |
--c2-comment-thread--border-radius | border-radius | 8px | |
--c2-comment-thread--padding | padding | 12px | |
--c2-comment-thread--gap | pixel | 12px | Space between the comments. |
--c2-comment-thread__quote--color | color | #52525b | |
--c2-comment-thread__quote--border | border | 3px solid #f59e0b | The bar beside the quote. |
--c2-comment-thread__quote--background | color | transparent | |
--c2-comment-thread__author--font-weight | font-weight | 600 | |
--c2-comment-thread__time--color | color | #71717a | |
--c2-comment-thread__time--font-size | font-size | 12px | |
--c2-comment-thread__mention--color | color | #0265dc | |
--c2-comment-thread__mention--background | color | #edf1fe | |
--c2-comment-thread__action--color | color | #52525b | |
--c2-comment-thread__action__hover--background | color | #f4f4f5 | |
--c2-comment-thread__submit--background | color | #0265dc | |
--c2-comment-thread__submit--color | color | #ffffff | |
--c2-comment-thread__resolved--color | color | #15803d | The Resolved line and its check. |
--c2-comment-thread__avatar--size | pixel | 28px | |
--c2-comment-thread__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under comment-thread, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Comment thread | — |
commentBy | {0}, {1} | {0} name {1} time |
edited | edited | — |
resolve | Resolve | — |
reopen | Reopen | — |
resolvedLine | Resolved · {0} replies | {0} replies |
showEarlier | Show {0} earlier replies | {0} count |
edit | Edit | — |
editLabel | Edit {0}'s comment | {0} name |
delete | Delete | — |
deleteLabel | Delete {0}'s comment | {0} name |
deleteQuestion | Delete this comment? | — |
deleteThreadQuestion | Delete this thread? | — |
save | Save | — |
cancel | Cancel | — |
reply | Reply | — |
replyPlaceholder | Reply… | — |
editPlaceholder | Edit comment | — |
quoteLabel | Commenting on | — |
replyAdded | Reply added | — |
commentEdited | Comment edited | — |
commentDeleted | Comment deleted | — |
threadResolved | Thread resolved | — |
threadReopened | Thread reopened | — |