# MermaidDiagram

Mermaid diagrams with zoom and a source view, and a clear message when one can’t be drawn.

- **Use it for**: A diagram written in Mermaid, with zoom and source view.
- **Not for**: Interactive workflows. Try [WorkflowGraph](https://unseenui.com/components/workflow-graph/).

## Installation

```bash
npm install @stackunseen/ui mermaid dompurify
```

## Usage

```tsx
import { MermaidDiagram } from '@stackunseen/ui/mermaid';
import '@stackunseen/ui/styles.css';

<MermaidDiagram variant="panel" code={diagram} title="Agent workflow" />
```

## Props

- `code` (`string`): Mermaid source. Restricted, unsupported or invalid input shows a source preview and message.
- `title` (`string (optional)`): The diagram title. Defaults to Diagram.
- `description` (`string (optional)`): A short explanation of what the diagram shows.
- `state` (`'complete' | 'streaming' (optional)`): Use streaming while source is arriving, then complete when it is ready to render.

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `className` | `string` | Added to the root element, after the component's own classes. |
| `code` (required) | `string` |  |
| `description` | `string` |  |
| `state` | `"complete" \| "streaming"` |  |
| `title` | `string` |  |
| `variant` | `"source" \| "panel" \| "minimal"` |  |

## Keyboard

Tab reaches the source disclosure and diagram controls. Use the source view as an alternative to reading the diagram.

## Works with

[MarkdownResponse](https://unseenui.com/components/markdown-response/), [MarkdownCodeBlock](https://unseenui.com/components/markdown-code-block/), [RichMarkdownResponse](https://unseenui.com/components/rich-markdown-response/), [MathFormula](https://unseenui.com/components/math-formula/)

Page: https://unseenui.com/components/mermaid-diagram/
