import type { ComponentType } from "react"; import { Toolbar } from "@base-ui/react/toolbar"; import { Button } from "../../ui/button"; import { cn } from "../../lib/utils"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../../ui/tooltip"; import { IconAttachMicro as AttachIcon, IconBoldMicro as BoldIcon, IconBulletListMicro as BulletIcon, IconCodeBlockMicro as CodeBlockIcon, IconCodeMicro as CodeIcon, IconEmojiMicro as EmojiIcon, IconItalicMicro as ItalicIcon, IconLinkMicro as LinkIcon, IconOrderedListMicro as OrderedIcon, IconQuoteMicro as BlockquoteIcon, IconStrikeMicro as StrikeIcon, IconUnderlineMicro as UnderlineIcon, } from "../../icons"; type Action = | "bold" | "italic" | "underline" | "strike" | "link" | "ordered" | "bullet" | "quote" | "code" | "pre" | "emoji" | "attach"; type ActionEvent = { action: Action; trigger: HTMLElement; }; type Props = { className?: string; disabled?: Partial>; value?: Partial>; onAction?: (event: ActionEvent) => void; }; type Item = { label: string; action: Action; icon: ComponentType<{ className?: string }>; }; const GROUPS: Item[][] = [ [ { label: "Bold", action: "bold", icon: BoldIcon }, { label: "Italic", action: "italic", icon: ItalicIcon }, { label: "Underline", action: "underline", icon: UnderlineIcon }, { label: "Strikethrough", action: "strike", icon: StrikeIcon }, ], [ { label: "Link", action: "link", icon: LinkIcon }, ], [ { label: "Ordered list", action: "ordered", icon: OrderedIcon }, { label: "Bullet list", action: "bullet", icon: BulletIcon }, { label: "Blockquote", action: "quote", icon: BlockquoteIcon }, ], [ { label: "Inline code", action: "code", icon: CodeIcon }, { label: "Code block", action: "pre", icon: CodeBlockIcon }, ], [ { label: "Attach", action: "attach", icon: AttachIcon }, { label: "Emoji", action: "emoji", icon: EmojiIcon }, ], ]; function ToolbarButton( { label, action, icon: Icon, active, disabled, onAction }: Item & { active?: boolean; disabled?: boolean; onAction?: (event: ActionEvent) => void; }, ) { return ( } onMouseDown={(e) => { e.preventDefault(); }} onClick={(e) => { if (disabled) return; onAction?.({ action, trigger: e.currentTarget }); }} /> } > {label} ); } function ComposerToolbar({ className, disabled, value, onAction }: Props) { return (
{GROUPS.map((group, i) => ( {group.map((item) => ( ))} {i < GROUPS.length - 1 && ( )} ))}
); } export { type ActionEvent as ComposerToolbarEvent, ComposerToolbar };