Skip to content
Organisms

Comments

A thread with replies and likes.

Primitive

Installation

Primitive
  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/, installs radix-ui@base-ui/react and the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.

    $ pnpm dlx asta-ui@latest add comments --radix

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/comments.json

  2. Or install the package

    Don’t want the file? Import from asta-uiasta-ui/base and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui radix-ui @base-ui/react
    import { Comments } from "asta-ui";
    import { Comments } from "asta-ui/base";
  3. Or copy it by hand

    Install radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useId, useRef, useState } from "react";
    import { Avatar } from "@/components/kit/avatar";
    import { Button } from "@/components/kit/button";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    const CURVE = "cubic-bezier(.16,1,.3,1)";
    
    export interface CommentAuthor {
      name: string;
      src?: string;
    }
    export interface CommentItem {
      id: string;
      author: CommentAuthor;
      /** Already formatted, e.g. "2h" or "Yesterday". */
      time: string;
      body: string;
      likes?: number;
      liked?: boolean;
      /** One level only. Replying to a reply adds to the same list. */
      replies?: CommentItem[];
    }
    export interface CommentsProps {
      defaultComments: CommentItem[];
      currentUser: CommentAuthor;
      title?: string;
      /** Called after a comment is added. `parentId` is set for replies. */
      onPost?: (body: string, parentId?: string) => void;
      className?: string;
    }
    
    /* ---------- composer ---------- */
    
    function Composer({
      user,
      label,
      placeholder,
      initial = "",
      autoFocus,
      onSubmit,
      onCancel,
    }: {
      user: CommentAuthor;
      label: string;
      placeholder: string;
      initial?: string;
      autoFocus?: boolean;
      onSubmit: (body: string) => void;
      onCancel?: () => void;
    }) {
      const [text, setText] = useState(initial);
      const id = useId();
      const area = useRef<HTMLTextAreaElement>(null);
      const empty = !text.trim();
      const send = () => {
        if (empty) return;
        onSubmit(text.trim());
        setText("");
        area.current?.focus();
      };
    
      return (
        <div className="flex gap-3">
          <Avatar name={user.name} src={user.src} size="sm" />
          <div className="min-w-0 flex-1 rounded-[10px] bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent)] transition-shadow duration-200 focus-within:shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_3px_color-mix(in_srgb,var(--color-brand)_14%,transparent)]">
            <label htmlFor={id} className="sr-only">
              {label}
            </label>
            {/* field-sizing lets the box grow with its text, no JS needed. */}
            <textarea
              ref={area}
              id={id}
              name="body"
              rows={1}
              value={text}
              autoFocus={autoFocus}
              placeholder={placeholder}
              onChange={(e) => setText(e.target.value)}
              onFocus={(e) => e.currentTarget.setSelectionRange(e.currentTarget.value.length, e.currentTarget.value.length)}
              onKeyDown={(e) => {
                if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
                  e.preventDefault();
                  send();
                } else if (e.key === "Escape" && onCancel) {
                  e.preventDefault();
                  onCancel();
                }
              }}
              className="block max-h-40 min-h-[44px] w-full resize-none bg-transparent px-3 pt-2.5 text-[16px] sm:text-[14px] leading-relaxed text-ink outline-none [field-sizing:content] placeholder:text-mute"
            />
            <div className="flex items-center justify-end gap-1.5 px-2 pb-2">
              {onCancel && (
                <Button variant="ghost" size="xs" onClick={onCancel}>
                  Cancel
                </Button>
              )}
              <Button variant="accent" size="xs" disabled={empty} onClick={send} kbd="⌘↵">
                {label}
              </Button>
            </div>
          </div>
        </div>
      );
    }
    
    /* ---------- one comment ---------- */
    
    function Like({ count, liked, pop, onToggle }: { count: number; liked: boolean; pop: boolean; onToggle: () => void }) {
      return (
        <button
          type="button"
          aria-pressed={liked}
          aria-label={`Like, ${count}`}
          onClick={onToggle}
          className={cx(
            "inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 text-[12px] tabular-nums outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-brand/50",
            liked ? "bg-[color-mix(in_srgb,var(--color-brand)_10%,transparent)] text-brand" : "text-mute hover:bg-paper-2 hover:text-ink",
          )}
        >
          <svg
            key={liked ? "on" : "off"}
            viewBox="0 0 24 24"
            className="h-3.5 w-3.5"
            fill={liked ? "currentColor" : "none"}
            stroke="currentColor"
            strokeWidth="2.25" strokeLinecap="round"
            strokeLinejoin="round"
            aria-hidden
            style={pop && liked ? { animation: `kit-cm-pop .45s ${CURVE}` } : undefined}
          >
            <path d="M12 19.5s-7.5-4.4-7.5-10A4.2 4.2 0 0 1 12 7a4.2 4.2 0 0 1 7.5 2.5c0 5.6-7.5 10-7.5 10Z" />
          </svg>
          <span className="relative inline-flex overflow-hidden">
            <span key={count} style={pop ? { animation: `kit-cm-roll .35s ${CURVE}` } : undefined}>
              {count}
            </span>
          </span>
        </button>
      );
    }
    
    /**
     * A discussion thread: avatar, name and time on each comment, replies one level deep, a like pill that
     * pops, and a composer that grows with its text. New comments slide in. ⌘/Ctrl + Enter posts and
     * Escape closes a reply box.
     */
    export function Comments({ defaultComments, currentUser, title = "Discussion", onPost, className }: CommentsProps) {
      const [comments, setComments] = useState(defaultComments);
      const [replyTo, setReplyTo] = useState<{ parent: string; mention?: string } | null>(null);
      const [fresh, setFresh] = useState<string[]>([]);
      const [popped, setPopped] = useState<string | null>(null);
      const replyButtons = useRef(new Map<string, HTMLButtonElement>());
      const seq = useRef(0);
    
      const total = comments.reduce((n, c) => n + 1 + (c.replies?.length ?? 0), 0);
    
      const post = (body: string, parent?: string) => {
        const item: CommentItem = { id: `new-${++seq.current}`, author: currentUser, time: "Just now", body, likes: 0 };
        setComments((list) => (parent ? list.map((c) => (c.id === parent ? { ...c, replies: [...(c.replies ?? []), item] } : c)) : [...list, item]));
        setFresh((f) => [...f, item.id]);
        onPost?.(body, parent);
      };
    
      const toggleLike = (id: string) => {
        const flip = (c: CommentItem): CommentItem =>
          c.id === id ? { ...c, liked: !c.liked, likes: (c.likes ?? 0) + (c.liked ? -1 : 1) } : { ...c, replies: c.replies?.map(flip) };
        setComments((list) => list.map(flip));
        setPopped(id);
      };
    
      const closeReply = () => {
        const parent = replyTo?.parent;
        setReplyTo(null);
        if (parent) replyButtons.current.get(parent)?.focus();
      };
    
      const row = (c: CommentItem, parent: string) => (
        <article key={c.id} className="flex gap-3" style={fresh.includes(c.id) ? { animation: `kit-cm-in .5s ${CURVE} both` } : undefined}>
          <Avatar name={c.author.name} src={c.author.src} size="sm" />
          <div className="min-w-0 flex-1">
            <header className="flex items-baseline gap-2">
              <span className="text-[13.5px] font-medium text-ink">{c.author.name}</span>
              <span className="text-[12px] text-mute">{c.time}</span>
            </header>
            <p className="mt-0.5 whitespace-pre-wrap break-words text-[14px] leading-relaxed text-ink-2">{c.body}</p>
            <div className="-ml-2.5 mt-1.5 flex items-center gap-0.5">
              <Like count={c.likes ?? 0} liked={!!c.liked} pop={popped === c.id} onToggle={() => toggleLike(c.id)} />
              <button
                ref={(el) => {
                  if (el && c.id === parent) replyButtons.current.set(parent, el);
                }}
                type="button"
                onClick={() => setReplyTo({ parent, mention: c.id === parent ? undefined : c.author.name.split(" ")[0] })}
                className="inline-flex h-7 items-center rounded-full px-2.5 text-[12px] text-mute outline-none transition-colors hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50"
              >
                Reply
              </button>
            </div>
          </div>
        </article>
      );
    
      return (
        <section aria-label={title} className={cx("kit-cm w-full max-w-[560px]", className)}>
          <style href="asta-comments" precedence="asta">{`
            @keyframes kit-cm-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
            @keyframes kit-cm-pop { 0% { transform: scale(.6); } 55% { transform: scale(1.25); } 100% { transform: none; } }
            @keyframes kit-cm-roll { from { opacity: 0; transform: translateY(70%); } to { opacity: 1; transform: none; } }
            @media (prefers-reduced-motion: reduce) { .kit-cm, .kit-cm * { animation: none !important; transition-duration: 0s !important; } }
          `}</style>
    
          <h3 className="mb-5 flex items-baseline gap-2 text-[15px] font-medium tracking-[-0.01em] text-ink">
            {title}
            <span className="text-[12.5px] font-normal tabular-nums text-mute">{total}</span>
          </h3>
    
          <div className="flex flex-col gap-6">
            {comments.map((c) => (
              <div key={c.id}>
                {row(c, c.id)}
                {(!!c.replies?.length || replyTo?.parent === c.id) && (
                  <div className="relative mt-4 flex flex-col gap-4 pl-11">
                    <span aria-hidden className="absolute bottom-1 left-4 top-0 w-px bg-[color-mix(in_srgb,var(--color-ink)_9%,transparent)]" />
                    {c.replies?.map((r) => row(r, c.id))}
                    {replyTo?.parent === c.id && (
                      <div style={{ animation: `kit-cm-in .4s ${CURVE} both` }}>
                        <Composer
                          key={replyTo.mention ?? "reply"}
                          user={currentUser}
                          label="Reply"
                          placeholder={`Reply to ${c.author.name.split(" ")[0]}…`}
                          initial={replyTo.mention ? `@${replyTo.mention} ` : ""}
                          autoFocus
                          onSubmit={(body) => {
                            post(body, c.id);
                            closeReply();
                          }}
                          onCancel={closeReply}
                        />
                      </div>
                    )}
                  </div>
                )}
              </div>
            ))}
          </div>
    
          <div className="mt-8">
            <Composer user={currentUser} label="Comment" placeholder="Add a comment…" onSubmit={(body) => post(body)} />
          </div>
        </section>
      );
    }
    
    export default Comments;
    
    "use client";
    
    import { useId, useRef, useState } from "react";
    import { Avatar } from "@/components/kit/base/avatar";
    import { Button } from "@/components/kit/base/button";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    const CURVE = "cubic-bezier(.16,1,.3,1)";
    
    export interface CommentAuthor {
      name: string;
      src?: string;
    }
    export interface CommentItem {
      id: string;
      author: CommentAuthor;
      /** Already formatted, e.g. "2h" or "Yesterday". */
      time: string;
      body: string;
      likes?: number;
      liked?: boolean;
      /** One level only. Replying to a reply adds to the same list. */
      replies?: CommentItem[];
    }
    export interface CommentsProps {
      defaultComments: CommentItem[];
      currentUser: CommentAuthor;
      title?: string;
      /** Called after a comment is added. `parentId` is set for replies. */
      onPost?: (body: string, parentId?: string) => void;
      className?: string;
    }
    
    /* ---------- composer ---------- */
    
    function Composer({
      user,
      label,
      placeholder,
      initial = "",
      autoFocus,
      onSubmit,
      onCancel,
    }: {
      user: CommentAuthor;
      label: string;
      placeholder: string;
      initial?: string;
      autoFocus?: boolean;
      onSubmit: (body: string) => void;
      onCancel?: () => void;
    }) {
      const [text, setText] = useState(initial);
      const id = useId();
      const area = useRef<HTMLTextAreaElement>(null);
      const empty = !text.trim();
      const send = () => {
        if (empty) return;
        onSubmit(text.trim());
        setText("");
        area.current?.focus();
      };
    
      return (
        <div className="flex gap-3">
          <Avatar name={user.name} src={user.src} size="sm" />
          <div className="min-w-0 flex-1 rounded-[10px] bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent)] transition-shadow duration-200 focus-within:shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_3px_color-mix(in_srgb,var(--color-brand)_14%,transparent)]">
            <label htmlFor={id} className="sr-only">
              {label}
            </label>
            {/* field-sizing lets the box grow with its text, no JS needed. */}
            <textarea
              ref={area}
              id={id}
              name="body"
              rows={1}
              value={text}
              autoFocus={autoFocus}
              placeholder={placeholder}
              onChange={(e) => setText(e.target.value)}
              onFocus={(e) => e.currentTarget.setSelectionRange(e.currentTarget.value.length, e.currentTarget.value.length)}
              onKeyDown={(e) => {
                if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
                  e.preventDefault();
                  send();
                } else if (e.key === "Escape" && onCancel) {
                  e.preventDefault();
                  onCancel();
                }
              }}
              className="block max-h-40 min-h-[44px] w-full resize-none bg-transparent px-3 pt-2.5 text-[16px] sm:text-[14px] leading-relaxed text-ink outline-none [field-sizing:content] placeholder:text-mute"
            />
            <div className="flex items-center justify-end gap-1.5 px-2 pb-2">
              {onCancel && (
                <Button variant="ghost" size="xs" onClick={onCancel}>
                  Cancel
                </Button>
              )}
              <Button variant="accent" size="xs" disabled={empty} onClick={send} kbd="⌘↵">
                {label}
              </Button>
            </div>
          </div>
        </div>
      );
    }
    
    /* ---------- one comment ---------- */
    
    function Like({ count, liked, pop, onToggle }: { count: number; liked: boolean; pop: boolean; onToggle: () => void }) {
      return (
        <button
          type="button"
          aria-pressed={liked}
          aria-label={`Like, ${count}`}
          onClick={onToggle}
          className={cx(
            "inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 text-[12px] tabular-nums outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-brand/50",
            liked ? "bg-[color-mix(in_srgb,var(--color-brand)_10%,transparent)] text-brand" : "text-mute hover:bg-paper-2 hover:text-ink",
          )}
        >
          <svg
            key={liked ? "on" : "off"}
            viewBox="0 0 24 24"
            className="h-3.5 w-3.5"
            fill={liked ? "currentColor" : "none"}
            stroke="currentColor"
            strokeWidth="2.25" strokeLinecap="round"
            strokeLinejoin="round"
            aria-hidden
            style={pop && liked ? { animation: `kit-cm-pop .45s ${CURVE}` } : undefined}
          >
            <path d="M12 19.5s-7.5-4.4-7.5-10A4.2 4.2 0 0 1 12 7a4.2 4.2 0 0 1 7.5 2.5c0 5.6-7.5 10-7.5 10Z" />
          </svg>
          <span className="relative inline-flex overflow-hidden">
            <span key={count} style={pop ? { animation: `kit-cm-roll .35s ${CURVE}` } : undefined}>
              {count}
            </span>
          </span>
        </button>
      );
    }
    
    /**
     * A discussion thread: avatar, name and time on each comment, replies one level deep, a like pill that
     * pops, and a composer that grows with its text. New comments slide in. ⌘/Ctrl + Enter posts and
     * Escape closes a reply box.
     */
    export function Comments({ defaultComments, currentUser, title = "Discussion", onPost, className }: CommentsProps) {
      const [comments, setComments] = useState(defaultComments);
      const [replyTo, setReplyTo] = useState<{ parent: string; mention?: string } | null>(null);
      const [fresh, setFresh] = useState<string[]>([]);
      const [popped, setPopped] = useState<string | null>(null);
      const replyButtons = useRef(new Map<string, HTMLButtonElement>());
      const seq = useRef(0);
    
      const total = comments.reduce((n, c) => n + 1 + (c.replies?.length ?? 0), 0);
    
      const post = (body: string, parent?: string) => {
        const item: CommentItem = { id: `new-${++seq.current}`, author: currentUser, time: "Just now", body, likes: 0 };
        setComments((list) => (parent ? list.map((c) => (c.id === parent ? { ...c, replies: [...(c.replies ?? []), item] } : c)) : [...list, item]));
        setFresh((f) => [...f, item.id]);
        onPost?.(body, parent);
      };
    
      const toggleLike = (id: string) => {
        const flip = (c: CommentItem): CommentItem =>
          c.id === id ? { ...c, liked: !c.liked, likes: (c.likes ?? 0) + (c.liked ? -1 : 1) } : { ...c, replies: c.replies?.map(flip) };
        setComments((list) => list.map(flip));
        setPopped(id);
      };
    
      const closeReply = () => {
        const parent = replyTo?.parent;
        setReplyTo(null);
        if (parent) replyButtons.current.get(parent)?.focus();
      };
    
      const row = (c: CommentItem, parent: string) => (
        <article key={c.id} className="flex gap-3" style={fresh.includes(c.id) ? { animation: `kit-cm-in .5s ${CURVE} both` } : undefined}>
          <Avatar name={c.author.name} src={c.author.src} size="sm" />
          <div className="min-w-0 flex-1">
            <header className="flex items-baseline gap-2">
              <span className="text-[13.5px] font-medium text-ink">{c.author.name}</span>
              <span className="text-[12px] text-mute">{c.time}</span>
            </header>
            <p className="mt-0.5 whitespace-pre-wrap break-words text-[14px] leading-relaxed text-ink-2">{c.body}</p>
            <div className="-ml-2.5 mt-1.5 flex items-center gap-0.5">
              <Like count={c.likes ?? 0} liked={!!c.liked} pop={popped === c.id} onToggle={() => toggleLike(c.id)} />
              <button
                ref={(el) => {
                  if (el && c.id === parent) replyButtons.current.set(parent, el);
                }}
                type="button"
                onClick={() => setReplyTo({ parent, mention: c.id === parent ? undefined : c.author.name.split(" ")[0] })}
                className="inline-flex h-7 items-center rounded-full px-2.5 text-[12px] text-mute outline-none transition-colors hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50"
              >
                Reply
              </button>
            </div>
          </div>
        </article>
      );
    
      return (
        <section aria-label={title} className={cx("kit-cm w-full max-w-[560px]", className)}>
          <style href="asta-comments" precedence="asta">{`
            @keyframes kit-cm-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
            @keyframes kit-cm-pop { 0% { transform: scale(.6); } 55% { transform: scale(1.25); } 100% { transform: none; } }
            @keyframes kit-cm-roll { from { opacity: 0; transform: translateY(70%); } to { opacity: 1; transform: none; } }
            @media (prefers-reduced-motion: reduce) { .kit-cm, .kit-cm * { animation: none !important; transition-duration: 0s !important; } }
          `}</style>
    
          <h3 className="mb-5 flex items-baseline gap-2 text-[15px] font-medium tracking-[-0.01em] text-ink">
            {title}
            <span className="text-[12.5px] font-normal tabular-nums text-mute">{total}</span>
          </h3>
    
          <div className="flex flex-col gap-6">
            {comments.map((c) => (
              <div key={c.id}>
                {row(c, c.id)}
                {(!!c.replies?.length || replyTo?.parent === c.id) && (
                  <div className="relative mt-4 flex flex-col gap-4 pl-11">
                    <span aria-hidden className="absolute bottom-1 left-4 top-0 w-px bg-[color-mix(in_srgb,var(--color-ink)_9%,transparent)]" />
                    {c.replies?.map((r) => row(r, c.id))}
                    {replyTo?.parent === c.id && (
                      <div style={{ animation: `kit-cm-in .4s ${CURVE} both` }}>
                        <Composer
                          key={replyTo.mention ?? "reply"}
                          user={currentUser}
                          label="Reply"
                          placeholder={`Reply to ${c.author.name.split(" ")[0]}…`}
                          initial={replyTo.mention ? `@${replyTo.mention} ` : ""}
                          autoFocus
                          onSubmit={(body) => {
                            post(body, c.id);
                            closeReply();
                          }}
                          onCancel={closeReply}
                        />
                      </div>
                    )}
                  </div>
                )}
              </div>
            ))}
          </div>
    
          <div className="mt-8">
            <Composer user={currentUser} label="Comment" placeholder="Add a comment…" onSubmit={(body) => post(body)} />
          </div>
        </section>
      );
    }
    
    export default Comments;
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Comments component to my project.
    
    A thread with replies and likes.
    It includes: thread, replies, composer, reactions.
    
    Install it (Radix build):
    ```sh
    pnpm dlx asta-ui@latest add comments --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/comments.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Comments, type CommentItem } from "@/components/astabyte/comments";
    ```
    
    Usage example and props: https://ui.astabyte.com/comments
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package).
    - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
    Add the Astabyte UI Comments component to my project.
    
    A thread with replies and likes.
    It includes: thread, replies, composer, reactions.
    
    Install it (Base UI build):
    ```sh
    pnpm dlx asta-ui@latest add comments
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/comments.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Comments, type CommentItem } from "@/components/astabyte/comments";
    ```
    
    Usage example and props: https://ui.astabyte.com/comments
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package).
    - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <!-- Needs asta.js for likes, reply boxes and the submit shortcut; posting needs a server endpoint. -->
    <section id="discussion" class="asta-comments asta-comments-root" data-asta-comments aria-label="Discussion"><h3 class="asta-comments-title">Discussion <span class="asta-comments-total" data-asta-comments-total>3</span></h3><div id="comments-list" class="asta-comments-list">
    <div data-asta-comment-thread="c1"><article class="asta-comments-item" data-asta-comment="c1"><span class="asta-avatar asta-avatar-sm " role="img" aria-label="Maya Chen"><span class="asta-avatar-face asta-avatar-soft">MC</span></span><div class="asta-comments-main"><header class="asta-comments-meta"><span class="asta-comments-author">Maya Chen</span><span class="asta-comments-time">2h</span></header><p class="asta-comments-text">The new pricing table reads much better. Can we try the yearly toggle on the left?</p><div class="asta-comments-actions"><button type="button" class="asta-comments-like" data-asta-comment-like name="liked" value="true" aria-pressed="true" aria-label="Like, 4"><svg class="asta-comment-heart" viewBox="0 0 16 16" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M8 13.5S2.5 10.3 2.5 6.4A2.9 2.9 0 0 1 8 5a2.9 2.9 0 0 1 5.5 1.4c0 3.9-5.5 7.1-5.5 7.1Z"/></svg><span class="asta-comments-likes"><span data-asta-comment-likes>4</span></span></button><button type="button" class="asta-comments-reply" data-asta-comment-reply="c1" data-name="Maya">Reply</button></div></div></article><div class="asta-comments-replies" data-asta-comment-replies><span aria-hidden="true" class="asta-comments-line"></span><div class="asta-comments-reply-list" data-asta-comment-list><article class="asta-comments-item" data-asta-comment="c2"><span class="asta-avatar asta-avatar-sm " role="img" aria-label="Leo Park"><span class="asta-avatar-face asta-avatar-soft">LP</span></span><div class="asta-comments-main"><header class="asta-comments-meta"><span class="asta-comments-author">Leo Park</span><span class="asta-comments-time">1h</span></header><p class="asta-comments-text">Agreed. I'll push a version with it on the left today.</p><div class="asta-comments-actions"><button type="button" class="asta-comments-like" data-asta-comment-like name="liked" value="false" aria-pressed="false" aria-label="Like, 1"><svg class="asta-comment-heart" viewBox="0 0 16 16" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M8 13.5S2.5 10.3 2.5 6.4A2.9 2.9 0 0 1 8 5a2.9 2.9 0 0 1 5.5 1.4c0 3.9-5.5 7.1-5.5 7.1Z"/></svg><span class="asta-comments-likes"><span data-asta-comment-likes>1</span></span></button><button type="button" class="asta-comments-reply" data-asta-comment-reply="c1" data-name="Leo" data-mention="Leo">Reply</button></div></div></article></div></div></div>
    <div data-asta-comment-thread="c3"><article class="asta-comments-item" data-asta-comment="c3"><span class="asta-avatar asta-avatar-sm " role="img" aria-label="Ana Ruiz"><span class="asta-avatar-face asta-avatar-soft">AR</span></span><div class="asta-comments-main"><header class="asta-comments-meta"><span class="asta-comments-author">Ana Ruiz</span><span class="asta-comments-time">35m</span></header><p class="asta-comments-text">Dark mode screenshots are in the Astabyte drive.</p><div class="asta-comments-actions"><button type="button" class="asta-comments-like" data-asta-comment-like name="liked" value="false" aria-pressed="false" aria-label="Like, 0"><svg class="asta-comment-heart" viewBox="0 0 16 16" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" aria-hidden="true"><path d="M8 13.5S2.5 10.3 2.5 6.4A2.9 2.9 0 0 1 8 5a2.9 2.9 0 0 1 5.5 1.4c0 3.9-5.5 7.1-5.5 7.1Z"/></svg><span class="asta-comments-likes"><span data-asta-comment-likes>0</span></span></button><button type="button" class="asta-comments-reply" data-asta-comment-reply="c3" data-name="Ana">Reply</button></div></div></article><div class="asta-comments-replies" data-asta-comment-replies><span aria-hidden="true" class="asta-comments-line"></span><div class="asta-comments-reply-list" data-asta-comment-list></div></div></div>
    </div><div class="asta-comments-footer"><form class="asta-comments-form" data-asta-comment-form><span class="asta-avatar asta-avatar-sm " role="img" aria-label="Sam Lee"><span class="asta-avatar-face asta-avatar-brand">SL</span></span><div class="asta-comments-box"><label style="display:block"><span class="asta-sr-only">Comment</span><textarea class="asta-comments-input" name="body" rows="1" required placeholder="Add a comment…"></textarea></label><div class="asta-comments-submit"><button type="submit" class="asta-btn asta-btn-accent asta-btn-xs" disabled><span class="asta-btn-label">Comment<kbd class="asta-btn-kbd">⌘↵</kbd></span></button></div></div></form></div><template data-asta-comments-replybox><div data-asta-comment-replybox class="asta-comment-new"><form class="asta-comments-form" data-asta-comment-form data-reply><span class="asta-avatar asta-avatar-sm " role="img" aria-label="Sam Lee"><span class="asta-avatar-face asta-avatar-brand">SL</span></span><div class="asta-comments-box"><input type="hidden" name="parent" value=""><label style="display:block"><span class="asta-sr-only">Reply</span><textarea class="asta-comments-input" name="body" rows="1" required placeholder="Reply…"></textarea></label><div class="asta-comments-submit"><button type="button" class="asta-btn asta-btn-ghost asta-btn-xs" data-asta-comment-cancel><span class="asta-btn-label">Cancel</span></button><button type="submit" class="asta-btn asta-btn-accent asta-btn-xs" disabled><span class="asta-btn-label">Reply<kbd class="asta-btn-kbd">⌘↵</kbd></span></button></div></div></form></div></template></section>

Usage

The demo above, as code.

"use client";

import { Comments, type CommentItem } from "@/components/astabyte/comments";

const THREAD: CommentItem[] = [
  {
    id: "1",
    author: { name: "Sekar Ayu" },
    time: "2h",
    body: "The new pricing layout reads much better. Could we move the yearly toggle above the cards?",
    likes: 3,
    replies: [
      { id: "1a", author: { name: "Dimas Arya" }, time: "1h", body: "Agreed. I'll try it on the staging build.", likes: 1 },
      { id: "1b", author: { name: "Rani Pratama" }, time: "45m", body: "Keep it sticky on mobile too, please.", likes: 0 },
    ],
  },
  {
    id: "2",
    author: { name: "Bima Santoso" },
    time: "20m",
    body: "Copy is final from my side. Shipping Thursday.",
    likes: 5,
    liked: true,
  },
];

export default function CommentsDemo() {
  return (
    <div className="flex min-h-[480px] w-full items-center justify-center p-4 sm:p-8">
      <Comments defaultComments={THREAD} currentUser={{ name: "Rani Pratama" }} />
    </div>
  );
}