Skip to Content
Delta ui
Components

Comment

A flexible React component for building a comment section. Add comments, replies, and thread lines without writing the layout yourself.

Installation

bash pnpm dlx shadcn@latest add harishravit/delta-ui/comment

Usage

src/comment.tsx
import {
  formatCommentTime,
  getAvatar,
} from "@/components/comment/lib/utils/helpers";
import {
  Comment,
  CommentAvatar,
  CommentAvatarBadge,
  CommentAvatarImage,
  CommentBody,
  CommentContent,
  CommentFooter,
  CommentHeader,
  CommentHeaderItem,
  CommentHeaderItemGroup,
  CommentMain,
  CommentMessageContent,
  CommentMessageText,
  CommentReplyItem,
  CommentReplyList,
  CommentSide,
} from "@/components/comment/ui";
import {
  Ellipsis,
  MessageCircle,
  Share2,
  ThumbsDown,
  ThumbsUp,
} from "lucide-react";

const Comment = () => {
  return (
    <div className="container mx-auto max-w-xl flex items-center justify-center h-screen px-2">
      <div className="w-full overflow-y-auto scrollbar-thin">
        <Comment>
          <CommentMain>
            <CommentContent>
              <CommentSide>
                <CommentAvatar className="bg-red-500">
                  <CommentAvatarImage
                    src={getAvatar("olivia-rhye")}
                    alt="olivia"
                  />
                </CommentAvatar>
              </CommentSide>
              <CommentBody>
                <CommentHeader>
                  <CommentHeaderItemGroup>
                    <CommentHeaderItem>
                      <h3 className="text-sm text-primary font-semibold">
                        olivia
                      </h3>
                      <a className="text-accent/90 font-medium cursor-pointer hover:text-primary">
                        @Olivia Rhye
                      </a>
                      <span className="text-accent/90">&bull;</span>
                      <span className="text-accent/90">
                        {formatCommentTime("2026-11-11T10:30:00Z")}
                      </span>
                    </CommentHeaderItem>
                    <span className="font-medium text-accent/90">
                      Software Engineer @Zoho
                    </span>
                  </CommentHeaderItemGroup>
                  <CommentHeaderItem>
                    <Ellipsis
                      aria-label="more action"
                      className="size-4 cursor-pointer text-accent/85 hover:text-primary"
                    />
                  </CommentHeaderItem>
                </CommentHeader>

                <CommentMessageContent>
                  <CommentMessageText>
                    <p className="min-w-0 wrap-break-word text-base w-fit">
                      I really like this design! The overall layout feels clean
                      and intuitive.
                    </p>
                    <button
                      role="readmore text"
                      className="text-accent/90 w-max max-w-full h-max p-0 text-xs! flex items-baseline"
                    >
                      <Ellipsis
                        aria-roledescription="show more text"
                        className="size-4 translate-y-1.25"
                      />
                      Readmore
                    </button>
                  </CommentMessageText>
                </CommentMessageContent>

                <CommentFooter className="[&_button]:gap-x-1 [&_button]:text-accent/80">
                  <button
                    data-item="reply"
                    className="text-accent/90 w-max max-w-full h-max p-0 text-sm flex items-baseline"
                  >
                    <MessageCircle className="size-4 translate-y-0.75" />
                    <span className="hidden lg:block">Reply</span>
                  </button>
                  <button
                    data-item="like"
                    className="text-accent/90 w-max max-w-full h-max p-0 text-sm flex items-baseline"
                  >
                    <ThumbsUp className="size-4 translate-y-0.5" />
                    24
                  </button>
                  <button className="bg-transparent">
                    <CommentAvatar className="bg-red-400">
                      <CommentAvatarImage
                        src={getAvatar("olivia-rhye")}
                        alt="olivia"
                      />
                      <CommentAvatarBadge>❤️</CommentAvatarBadge>
                    </CommentAvatar>
                  </button>
                </CommentFooter>
              </CommentBody>
            </CommentContent>
          </CommentMain>
          <CommentReplyList>
            <CommentReplyItem>
              <CommentContent>
                <CommentSide>
                  <CommentAvatar className="bg-red-500">
                    <CommentAvatarImage
                      src={getAvatar("phoenix-baker")}
                      alt="phoenix"
                    />
                  </CommentAvatar>
                </CommentSide>
                <CommentBody>
                  <CommentHeader>
                    <CommentHeaderItemGroup className="pr-2">
                      <CommentHeaderItem>
                        <h3 className="text-sm text-primary font-semibold">
                          phoenix
                        </h3>
                        <a className="text-accent/70 font-medium cursor-pointer hover:text-primary truncate">
                          @Phoenix Baker
                        </a>
                        <span className="text-accent/70 text-sm">&bull;</span>
                        <span className="text-accent/70 text-xs truncate">
                          {formatCommentTime("2026-11-11T11:00:00Z")}
                        </span>
                      </CommentHeaderItem>
                      <span className="font-medium text-accent/70 truncate">
                        Product Designer @Figma
                      </span>
                    </CommentHeaderItemGroup>
                    <CommentHeaderItem>
                      <Ellipsis className="size-4 cursor-pointer text-accent/85 hover:text-primary" />
                    </CommentHeaderItem>
                  </CommentHeader>
                  <CommentMessageContent>
                    <CommentMessageText
                      render={() => (
                        <button className="text-accent/90 w-max max-w-full h-max p-0 text-xs! flex items-baseline">
                          <Ellipsis className="size-4 translate-y-1.25" />
                          Readmore
                        </button>
                      )}
                    >
                      <p className="min-w-0 wrap-break-word text-base w-fit">
                        Agreed! The spacing and typography are really well
                        balanced.
                      </p>
                    </CommentMessageText>
                  </CommentMessageContent>

                  <CommentFooter className="[&_button]:gap-x-1 [&_button]:text-accent/80">
                    <button
                      data-item="dislike"
                      className="text-accent/90 w-max max-w-full h-max p-0 text-sm flex items-baseline"
                    >
                      <ThumbsDown className="size-4 translate-y-1" />0
                    </button>
                    <button
                      data-item="share"
                      className="text-accent/90 w-max max-w-full h-max p-0 text-sm flex items-baseline"
                    >
                      <Share2 className="size-4 translate-y-1" />
                      share
                    </button>
                    <button>
                      <CommentAvatar className="bg-red-400">
                        <CommentAvatarImage
                          src={getAvatar("phoenix-baker")}
                          alt="phoenix"
                        />
                        <CommentAvatarBadge>🤣</CommentAvatarBadge>
                      </CommentAvatar>
                    </button>
                  </CommentFooter>
                </CommentBody>
              </CommentContent>
            </CommentReplyItem>
          </CommentReplyList>
        </Comment>
      </div>
    </div>
  );
};

export default Comment;
comment.tsx
<Comment>
  <CommentMain>
    <CommentContent>
      <CommentSide>
        <CommentAvatar>
          <CommentAvatarImage></CommentAvatarImage>
        </CommentAvatar>
      </CommentSide>
      <CommentBody>
        <CommentHeader>
          <CommentHeaderItemGroup>
            <CommentHeaderItem />
            <CommentHeaderItem />
          </CommentHeaderItemGroup>
          <CommentHeaderItem />
        </CommentHeader>
        <CommentMessageContent>
          <CommentMessageMedia />
          <CommentMessageText />
        </CommentMessageContent>
        <CommentFooter />
      </CommentBody>
    </CommentContent>
  </CommentMain>
  <CommentReplyList>
    <CommentReplyItem>
      <CommentContent>
        <CommentSide>
          <CommentAvatar>
            <CommentAvatarImage />
          </CommentAvatar>
        </CommentSide>
        <CommentBody>
          <CommentHeader>
            <CommentHeaderItemGroup>
              <CommentHeaderItem />
              <CommentHeaderItem />
            </CommentHeaderItemGroup>
            <CommentHeaderItem />
          </CommentHeader>
          <CommentMessageContent>
            <CommentMessageMedia />
            <CommentMessageText />
          </CommentMessageContent>
          <CommentFooter />
        </CommentBody>
      </CommentContent>
    </CommentReplyItem>
  </CommentReplyList>
</Comment>

Sample output

Comment sample

Component composition

Following composition to build your comment component.

Comment
├── CommentMain
├── CommentContent
│   ├── CommentSide
│   │   └── CommentAvatar
│   │       ├── CommentAvatarImage
│   │       └── CommentAvatarBadge
│   └── CommentBody
│       ├── CommentHeader
│       │   ├── CommentHeaderItemGroup
│       │   │   └── CommentHeaderItem
│       │   └── CommentHeaderItem
│       ├── CommentMessageContent
│       │   ├── CommentMessageMedia
│       │   └── CommentMessageText
│       └── CommentFooter
├── CommentReplyList
│   ├── CommentReplyItem
│   └── CommentReplyToggle
└── CommentReplyToggle

Components purpose

Comment

  • The box for one full conversation: the main comment and all its replies.

Props and its usage

PropTypeDefaultValuesUse case
disableBendbooleanfalsetrue, falseDon't want the curved lines? Set it to true. The straight vertical lines stay.
disableThreadsbooleanfalsetrue, falseWant a clean look with no lines at all? Set it to true. Both the curved and straight lines go away.

Note

These props only hide the lines. The bend container is still in the DOM, so the tree layout does not break.

  • Comment — The root component that wraps a comment and its replies.
  • CommentMain — The first comment in a conversation, displayed at the top.
  • CommentContent — Holds the two halves of a comment: the avatar side and the text side. Shared by the main comment and replies.
  • CommentSide — The left side of a comment, containing the user's avatar and thread line.
  • CommentAvatar — The frame for the user's photo. The image inside accepts src and alt. Customize its size using className.
  • CommentAvatarImage — Displays the user's profile image.
  • CommentAvatarBadge — Displays a small badge at the bottom-right corner of the avatar, typically used for reactions such as ❤️. following structure for build avatar component
CommentAvatar
├── CommentAvatarImage
└── CommentAvatarBadge
  • CommentBody — The right side of a comment, containing the header, message, and footer.
  • CommentHeader — The top section of a comment, displaying user information and actions.
  • CommentHeaderItem — Arranges items horizontally in a single line, such as username, handle, date, or action icons.
  • CommentHeaderItemGroup — Groups header items vertically, such as username and handle on the first line and role on the second.
  • CommentMessageContent — Groups the comment's media and text together below the header.
  • CommentMessageMedia — Displays images or GIFs attached to a comment. Accepts src and alt.
  • CommentMessageText — Displays the comment text and optionally supports a Read More button for long content.
  • CommentFooter — The bottom section of a comment, typically containing reply, like, dislike, and share actions.
  • CommentReplyList — Holds the collection of replies belonging to a comment.
  • CommentReplyItem — Represents an individual reply, using the same content layout as the main comment.
  • CommentReplyToggle — Controls the visibility of a comment's replies by expanding or collapsing the reply list.
CommentReplyList
├── CommentReplyItem
│ └── CommentContent
│ └── CommentReplyList
│ ├── CommentReplyItem
│ └── CommentReplyToggle
└── CommentReplyToggle

Note

  • You don't need to draw or import the thread lines. They come built into the components.
  • Every component renders a div, so you can pass any normal div prop like className. Two are different:
    • CommentAvatarImage renders an img and takes img props.
    • CommentReplyToggle renders a button and takes button props.

On this page