Nested Comments
Threaded comment section with infinite nesting, animated expand/collapse, inline reply composer, and spring-physics like button.
npx uniqueui add nested-comments
Preview
3 Comments
⌘+Enter to post
AK
Alex Kim2 hours ago
This component is incredible! The spring animations feel so natural and snappy.
SC
Sarah Chen1 hour agoreply
Agreed! The collapse animation is especially smooth. Love the thread lines too.
AK
Alex Kim45 min agoreply
Thanks! Motion.dev's layout animations make nested content effortless to build.
JL
Jordan Lee3 hours ago
Love the inline reply box with ⌘+Enter shortcut. Very intuitive UX — try clicking Reply!
MP
Maya Patel4 hours ago
The like button spring animation is a nice touch. Small details make a big difference.
Usage
import { NestedComments } from "@/components/ui/nested-comments";
import type { Comment } from "@/components/ui/nested-comments";
const comments: Comment[] = [
{
id: "1",
author: "Alex Kim",
content: "This component is incredible! The animations feel so natural.",
timestamp: "2 hours ago",
likes: 14,
replies: [
{
id: "1-1",
author: "Sarah Chen",
content: "Agreed! The collapse animation is especially smooth.",
timestamp: "1 hour ago",
likes: 6,
replies: [
{
id: "1-1-1",
author: "Alex Kim",
content: "Thanks! Motion.dev's layout animations make it effortless.",
timestamp: "45 min ago",
likes: 3,
},
],
},
],
},
{
id: "2",
author: "Jordan Lee",
content: "Love the inline reply box with keyboard shortcuts. Very intuitive UX.",
timestamp: "3 hours ago",
likes: 9,
},
];
export default function Example() {
return (
<div className="p-6 bg-neutral-950 rounded-xl min-h-[400px]">
<NestedComments
comments={comments}
maxDepth={4}
accentColor="#8b5cf6"
onReply={(id, content) => console.log("Reply to", id, ":", content)}
onLike={(id) => console.log("Liked", id)}
/>
</div>
);
}Props
| Prop | Type | Description |
|---|---|---|
comments | Comment[] | Array of top-level comment objects, each optionally containing a `replies` array for nested threading. |
maxDepth | number | Maximum nesting depth allowed before disabling the Reply button to prevent infinite threading. |
className | string | Additional CSS classes applied to the root wrapper element. |
accentColor | string | Hex or CSS color used for reply badge highlights and interactive accent elements. |
onReply | (commentId: string, content: string) => void | Callback fired when a user submits a reply, receiving the parent comment ID and reply text. |
onLike | (commentId: string) => void | Callback fired when a user likes a comment, receiving the comment ID. |