Skip to content
Klarhimmel UI

Comment thread

App, comment thread previewApp, comment thread preview

Install

npx shadcn add @klarhimmel/app-comments-thread
DetailsAbout, usage, props and more

A discussion between people: comments with author and time, replies one level deep, a Reply button that opens a form under its comment (focus moves in and back), and a…

States

comment thread in 4 forms: filled, empty, posting, error.

  • state: filled

    Discussion

    Name the discussion

    Say who can see this.

    3 comments

    1. Person one, 0 hours ago

      Person one0 hours ago

      Write a comment of one or two sentences, with a question for the team.

      1. Person two0 hour ago

        Write a short reply to the comment.

      2. Person one00 minutes ago

        Write a short answer back.

  • state: empty

    Discussion

    Name the discussion

    Say who can see this.

    No comments yet

    Say what starting the discussion does.

  • state: posting

    Discussion

    Name the discussion

    Say who can see this.

    3 comments

    1. Person one, 0 hours ago

      Person one0 hours ago

      Write a comment of one or two sentences, with a question for the team.

      1. Person two0 hour ago

        Write a short reply to the comment.

      2. Person one00 minutes ago

        Write a short answer back.

  • state: error

    Discussion

    Name the discussion

    Say who can see this.

    3 comments

    1. Person one, 0 hours ago

      Person one0 hours ago

      Write a comment of one or two sentences, with a question for the team.

      1. Person two0 hour ago

        Write a short reply to the comment.

      2. Person one00 minutes ago

        Write a short answer back.

Notes

When to use it

A discussion under a record: comments with replies one level deep and a field to write a new one. For a conversation with an assistant use app-assistant-thread; for a notification feed use app-notifications-inbox.

Writing for it

- Use 1 to 4 top-level comments with up to 3 replies each. Give every comment an author and time so the replies make sense without extra context. - replyLabel (20) is followed by the author's name for screen readers, so use just Reply rather than Reply to this comment. - composer.empty (80) is shown when someone posts an empty field. Say what to write, not that the field is invalid.

Watch out for

What a person posts lives only in this block and is not saved, and it starts over when the thread props change. Replies cannot be nested further, so a reply form on a reply is not offered.

Usage

The block in a page, with its default content (long lists shortened). Every prop is in the table below.

section.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { BlockSurface } from '@/components/klarhimmel/blocks/surface';
import AppCommentsThread from '@/components/klarhimmel/blocks/app-comments-thread';

export default function Section() {
  return (
    <Theme theme="brand">
      <BlockSurface>
        <AppCommentsThread props={{
          "eyebrow": "Discussion",
          "title": "Name the discussion",
          "description": "Say who can see this.",
          "summaryWord": "comments",
          "comments": [
            {
              "author": "Person one",
              "time": "0 hours ago",
              "body": "Write a comment of one or two sentences, with a question for the team.",
              "replies": [
                {
                  "author": "Person two",
                  "time": "0 hour ago",
                  "body": "Write a short reply to the comment."
                }
              ]
            }
          ],
          "replyLabel": "Reply",
          "replyForm": {
            "label": "Your reply",
            "submit": "Send reply",
            "cancel": "Cancel"
          },
          "composer": {
            "label": "Add a comment",
            "submit": "Post comment",
            "posting": "Posting…",
            "empty": "Say to write something first."
          },
          "you": "You",
          "justNow": "just now",
          "notices": {
            "posted": "Comment posted.",
            "replied": "Reply posted."
          },
          "state": "filled",
          "messages": {
            "emptyTitle": "No comments yet",
            "emptyBody": "Say what starting the discussion does.",
            "error": "Say the post failed and to retry."
          }
        }} />
      </BlockSurface>
    </Theme>
  );
}

Props

The type, default and text limit of every prop. On a real page, over-limit text is kept and checkSections flags it (Installation, Check a page before you ship); this live preview shows the default until it fits. The panel above edits all props.

PropTypeDefaultDescription
eyebrowstring'Discussion'Text, up to 60 characters. Optional; empty is not rendered.
titlestring'Name the discussion'Text, up to 120 characters.
descriptionstring'Say who can see this.'Text, up to 300 characters. Optional; empty is not rendered.
summaryWordstring'comments'Text, up to 20 characters.
comments{ author, time, body, replies }[]1 itemList of 1 to 4. Each item: author, time, body, replies.
replyLabelstring'Reply'Text, up to 20 characters.
replyForm{ label, submit, cancel }{…}Fields: label, submit, cancel.
composer{ label, submit, posting, empty }{…}Fields: label, submit, posting, empty.
youstring'You'Text, up to 24 characters.
justNowstring'just now'Text, up to 24 characters.
notices{ posted, replied }{…}Fields: posted, replied.
state'filled' | 'empty' | 'posting' | 'error''filled'One of 'filled', 'empty', 'posting', 'error'.
messages{ emptyTitle, emptyBody, error }{…}Fields: emptyTitle, emptyBody, error.
headingLevel'1' | '2'-One of '1', '2'. Optional; empty is not rendered.

Install

Installs

app-comments-thread
Uses
  • Avatar
  • Banner
  • Button
  • Textarea
  • EmptyState
About
A discussion between people: comments with author and time, replies one level deep, a Reply button that opens a form under its comment (focus moves in and back), and a composer.
States
Filled, empty, posting and error. Reply opens a form under its comment and names the author; Escape closes it. New project? Set it up once: /get-started/installation.