Comment Leaf
plate/comment-nodeFreeComponent
A text component for displaying comments with visual indicators.
Live preview
live · rendered by the registry
Rendered by plate on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://platejs.org/r/comment-node.jsonSource
1'use client';23import * as React from 'react';45import type { TCommentText } from 'platejs';6import type { PlateLeafProps } from 'platejs/react';78import { getCommentCount } from '@platejs/comment';9import { PlateLeaf, useEditorPlugin, usePluginOption } from 'platejs/react';1011import { cn } from '@/lib/utils';12import { commentPlugin } from '@/registry/components/editor/plugins/comment-kit';1314export function CommentLeaf(props: PlateLeafProps<TCommentText>) {15 const { children, leaf } = props;1617 const { api, setOption } = useEditorPlugin(commentPlugin);18 const hoverId = usePluginOption(commentPlugin, 'hoverId');19 const activeId = usePluginOption(commentPlugin, 'activeId');2021 const isOverlapping = getCommentCount(leaf) > 1;22 const currentId = api.comment.nodeId(leaf);23 const isActive = activeId === currentId;24 const isHover = hoverId === currentId;2526 return (27 <PlateLeaf28 {...props}29 className={cn(30 'border-b-2 border-b-highlight/[.36] bg-highlight/[.13] transition-colors duration-200',31 (isHover || isActive) && 'border-b-highlight bg-highlight/25',32 isOverlapping && 'border-b-2 border-b-highlight/[.7] bg-highlight/25',33 (isHover || isActive) &&34 isOverlapping &&35 'border-b-highlight bg-highlight/45'36 )}37 attributes={{38 ...props.attributes,39 onClick: () => setOption('activeId', currentId ?? null),40 onMouseEnter: () => setOption('hoverId', currentId ?? null),41 onMouseLeave: () => setOption('hoverId', null),42 }}43 >44 {children}45 </PlateLeaf>46 );47}
What it pulls in
npm packages
Other registry items
Files it writes
More from plate
All 324 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-kitai-kit | plate | Components | Free | 1 dep | |
| AI Menuai-menu | plate | Components | Free | 5 deps · 2 files | |
| AI Leafai-node | plate | Components | Free | no deps | |
| AI Toolbar Buttonai-toolbar-button | plate | Components | Free | 1 dep | |
| align-base-kitalign-base-kit | plate | Components | Free | 1 dep | |
| align-kitalign-kit | plate | Components | Free | 1 dep | |
| Align Toolbar Buttonalign-toolbar-button | plate | Components | Free | 1 dep | |
| autoformat-classic-kitautoformat-classic-kit | plate | Components | Free | 2 deps |
