logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
      2.0.0
  • Confirmation
    • Think
      2.0.0
    • ThoughtChain
      2.0.0
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
    • CodeHighlighter
      2.1.0
    • FileCard
      2.0.0
    • Mermaid
      2.1.0
    • Sources
      2.0.0
  • Others
    • XProvider

Mermaid

Used to render diagrams with Mermaid.
Importimport { Mermaid } from "@ant-design/x";
Sourcecomponents/mermaid
Docs
Edit this page...
Versionsupported since 2.1.0
Changelog
loading

When to Use

  • Used to render interactive Mermaid diagrams that support zooming, panning, and switching between image and code views in applications.
  • When used together with XMarkdown, it can render Mermaid diagrams within Markdown content and enhance interactive features.

Code Demo

API

PropertyDescriptionTypeDefault
childrenCode contentstring-
headerHeaderReact.ReactNode | nullReact.ReactNode
classNameStyle class namestring-
classNamesStyle class namePartial<Record<'root' | 'header' | 'graph' | 'code', string>>-
stylesStyle objectPartial<Record<'root' | 'header' | 'graph' | 'code', React.CSSProperties>>-
highlightPropsCode highlighting configurationhighlightProps-
configMermaid configurationMermaidConfig-
actionsActions configuration{ enableZoom?: boolean; enableDownload?: boolean; enableCopy?: boolean; customActions?: ItemType[] }{ enableZoom: true, enableDownload: true, enableCopy: true }
onRenderTypeChangeCallback when render type changes(value: 'image' | 'code') => void-
prefixClsStyle prefixstring-
styleCustom styleReact.CSSProperties-

Semantic DOM

Theme Variables (Design Token)

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgTitleTitle background colorstringrgba(0,0,0,0.06)
colorBorderCodeCode block border colorstring#f0f0f0
colorBorderGraphGraph border colorstring#f0f0f0
colorTextTitleTitle text colorstringrgba(0,0,0,0.88)
Global TokenHow to use?

FAQ

How to avoid unnecessary re-renders or re-initialization when using 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:

tsx
// Dynamic config: cache with useMemo
const config = React.useMemo(
() => ({
theme: isDark ? 'dark' : 'base',
fontFamily: 'monospace',
}),
[isDark],
);
// Static config: extract as a constant
const CONFIG = { theme: 'base', fontFamily: 'monospace' } as const;
<Mermaid config={config}>{code}</Mermaid>;
Basic
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Header
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Header Actions
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
With XMarkdown
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Login Flow

Header Actions Configuration

  • root
    root
  • header
    Wrapper element of the header
  • graph
    Wrapper element of the graph