Styled Components
The Styled preset is a polished, CSS-only comment section with zero Tailwind or Radix. Use it when you want a drop-in UI without adding Tailwind or Radix to your project. Import one stylesheet and theme via CSS variables.
Styled component
Live preview of StyledCommentSection. Add a comment, reply, react, edit, or delete to try it.
Quick start
Import the preset CSS and render StyledCommentSection. All data callbacks are synchronous: update your state and return the new comment.
import '@hasthiya_/headless-comments-react/presets/styled/styles.css';
import { StyledCommentSection, generateUniqueId, type Comment, type CommentUser } from '@hasthiya_/headless-comments-react';
const currentUser: CommentUser = {
id: 'user-1',
name: 'John Doe',
avatarUrl: 'https://api.dicebear.com/7.x/pixel-art/svg?seed=JohnDoe',
isVerified: true,
};
function App() {
const [comments, setComments] = useState<Comment[]>([]);
const handleSubmit = (content: string): Comment => {
const newComment: Comment = {
id: generateUniqueId(),
content,
author: currentUser,
createdAt: new Date(),
reactions: [{ id: 'like', label: 'Like', emoji: '👍', count: 0, isActive: false }],
replies: [],
};
setComments((prev) => [newComment, ...prev]);
return newComment;
};
return (
<StyledCommentSection
comments={comments}
currentUser={currentUser}
onSubmitComment={handleSubmit}
/>
);
}CSS variables
Override these custom properties in :root or a wrapper element to theme the Styled preset. All variable names use the --cs-* prefix to avoid clashes.
| Variable | Default | Description |
|---|---|---|
| --cs-primary-color | #f97316 | Primary accent (buttons, links, focus) |
| --cs-secondary-color | #6b7280 | Muted / avatar fallback |
| --cs-bg-color | #ffffff | Background |
| --cs-hover-bg-color | #f9fafb | Hover background |
| --cs-text-color | #1f2937 | Main text |
| --cs-secondary-text-color | #6b7280 | Secondary text |
| --cs-border-color | #e5e7eb | Borders |
| --cs-border-radius | 8px | Border radius |
| --cs-font-family | system | Font family |
| --cs-font-size | 14px | Base font size |
| --cs-avatar-size | 36px | Avatar size |
| --cs-comment-spacing | 16px | Vertical spacing |
| --cs-animation-duration | 200ms | Transitions |
| --cs-destructive-color | #dc2626 | Delete / danger |
| --cs-success-color | #16a34a | Success state |
:root {
--cs-primary-color: #8b5cf6;
--cs-bg-color: #0f172a;
--cs-text-color: #f8fafc;
--cs-border-color: #334155;
}Dark mode
The same stylesheet supports light and dark. Use one of these so the preset switches correctly:
- Add the class
cs-root--darkto an ancestor of the comment section. - Set
data-cs-theme="dark"on the wrapper element. - If your app uses a global
.darkclass (e.g. next-themes withattribute="class"), the Styled preset will follow it automatically.
<!-- Option 1: class on a wrapper -->
<div className="cs-root--dark">
<StyledCommentSection ... />
</div>
<!-- Option 2: data attribute -->
<div data-cs-theme="dark">
<StyledCommentSection ... />
</div>StyledCommentSection props
StyledCommentSection accepts all standard CommentSection props (see the main docs Component API). In addition, these display props control the Styled preset UI:
showSortBar(defaulttrue) — Show sort bar (newest / oldest / top)showReactions(defaulttrue) — Show reaction buttonsshowMoreOptions(defaulttrue) — More menu (reply, edit, delete, share, report)showVerifiedBadge(defaulttrue) — Verified badge next to authormaxCommentLines— Max lines before truncating comment bodyinputPlaceholder,maxCharLimit,showCharCount,autoFocusmaxDepth(default3) — Reply nesting depth
Live demo
Try the Styled preset on the homepage: open the live demo and use the preset switcher to select "Styled".