Skip to main content

MermaidDiagram

Docusaurus renders Mermaid diagrams natively — MermaidDiagram takes that one step further. It wraps the built-in <Mermaid> component and adds an interactive layer: zoom, pan, fullscreen view, and SVG/PNG export. Readers can actually explore large, complex diagrams instead of squinting at a fixed image.

Any diagram type that Docusaurus's Mermaid integration supports works here — flowcharts, sequence diagrams, entity relationships, state machines, and more.


Live demo

Loading demo…

Try scrolling or pinching to zoom. The fullscreen and export buttons are in the top-right corner.


Installation

npm install docucraft

MermaidDiagram wraps Docusaurus's native Mermaid integration, so @docusaurus/theme-mermaid must be installed and enabled in your project.

npm install @docusaurus/theme-mermaid

Add it to docusaurus.config.ts:

export default {
markdown: { mermaid: true },
themes: ['@docusaurus/theme-mermaid'],
};

Usage

import { MermaidDiagram } from 'docucraft';

<MermaidDiagram
definition={String.raw`flowchart LR
API --> Service --> Database
`}
ariaLabel="System overview"
/>

Best practices

Always set ariaLabel. It describes the diagram for screen readers and gets attached to the viewport as an accessible label. Keep it brief but descriptive — "Payment flow overview" is better than "diagram".

Use String.raw for complex diagrams. Some Mermaid syntax uses backslash characters. Wrapping your definition in String.raw passes the string exactly as written, without JavaScript's escape processing.

Set a meaningful exportFileName. When a reader exports your diagram, the downloaded file gets named after this value. "order-flow" beats "diagram".

Disable controls you don't need. If fullscreen or export don't fit a particular diagram's context, set enableFullscreen={false} or enableExport={false} to keep the UI clean.

Use showHint={false} for embedded diagrams. The hint row below the diagram tells readers how to interact with it. Once your audience is familiar with the controls, hiding it saves vertical space.


Props

PropTypeDefaultDescription
definitionstringMermaid source code. Required.
ariaLabelstringAccessible label for the diagram viewport.
classNamestringAdditional CSS class on the root element.
minScalenumber0.6Minimum zoom level.
maxScalenumber4Maximum zoom level.
zoomStepnumber0.12Zoom increment per scroll step or button click.
showHintbooleantrueShow or hide the usage hint below the diagram.
hintTextstringReplaces the default hint text.
exportFileNamestring"diagram"Base file name for exported SVG and PNG files.
enableFullscreenbooleantrueShow the fullscreen button.
enableExportbooleantrueShow the SVG and PNG export buttons.