Features
Libraries
A standalone Mermaid editor with a source pane beside the drawn diagram, with a template menu and export.
Installation#
bash
pnpm dlx shadcn@latest add @zui/mermaid-editorUsage#
tsx
import { MermaidEditor } from '@/components/editor/mermaid/react/editor';tsx
function Diagram() {
return <MermaidEditor defaultValue={'flowchart LR\n A --> B'} onValueChange={save} />;
}It is controlled when given value, and starts from defaultValue otherwise. DiagramViewer, in viewer.tsx, draws a stored diagram without the editing pane.
API reference#
MermaidEditor#
| Prop | Type | Default |
|---|---|---|
value | string | - |
defaultValue | string | - |
onValueChange | (source: string) => void | - |
readOnly | boolean | false |
layout | 'auto' | 'split' | 'tabs' | 'auto' |
toolbar | boolean | true |
className | string | - |
With layout="auto" the source and the diagram sit side by side on a wide viewport and in tabs on a narrow one.