Mermaid
Mermaid
Used to render diagrams with Mermaid.
Importimport { Mermaid } from "@ant-design/x"; |
Sourcecomponents/mermaid |
Docs |
Versionsupported since 2.1.0 |
Importimport { Mermaid } from "@ant-design/x"; |
Sourcecomponents/mermaid |
Docs |
Versionsupported since 2.1.0 |
| Property | Description | Type | Default |
|---|---|---|---|
| children | Code content | string | - |
| header | Header | React.ReactNode | null | React.ReactNode |
| className | Style class name | string | - |
| classNames | Style class name | Partial<Record<'root' | 'header' | 'graph' | 'code', string>> | - |
| styles | Style object | Partial<Record<'root' | 'header' | 'graph' | 'code', React.CSSProperties>> | - |
| highlightProps | Code highlighting configuration | highlightProps | - |
| config | Mermaid configuration | MermaidConfig | - |
| actions | Actions configuration | { enableZoom?: boolean; enableDownload?: boolean; enableCopy?: boolean; customActions?: ItemType[] } | { enableZoom: true, enableDownload: true, enableCopy: true } |
| onRenderTypeChange | Callback when render type changes | (value: 'image' | 'code') => void | - |
| prefixCls | Style prefix | string | - |
| style | Custom style | React.CSSProperties | - |
| Token Name | Description | Type | Default Value |
|---|---|---|---|
| colorBgTitle | Title background color | string | rgba(0,0,0,0.06) |
| colorBorderCode | Code block border color | string | #f0f0f0 |
| colorBorderGraph | Graph border color | string | #f0f0f0 |
| colorTextTitle | Title text color | string | rgba(0,0,0,0.88) |
config?When passing the config prop, ensure it is a reference-stable object. Avoid passing object literals directly in JSX (e.g., config={{ theme: 'base' }}), as this will cause Mermaid to re-initialize on every parent re-render. ✅ Recommended approaches:
// Dynamic config: cache with useMemoconst config = React.useMemo(() => ({theme: isDark ? 'dark' : 'base',fontFamily: 'monospace',}),[isDark],);// Static config: extract as a constantconst CONFIG = { theme: 'base', fontFamily: 'monospace' } as const;<Mermaid config={config}>{code}</Mermaid>;