diff --git a/components/mermaid-diagram.tsx b/components/mermaid-diagram.tsx index d12d256..9652a91 100644 --- a/components/mermaid-diagram.tsx +++ b/components/mermaid-diagram.tsx @@ -1,8 +1,9 @@ 'use client' import { isValidElement, useEffect, useId, useState, type ReactNode } from 'react' -import { Code2, GitBranch } from 'lucide-react' +import { Code2, GitBranch, Maximize2 } from 'lucide-react' import { Button } from '@/components/ui/button' +import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog' /** Renders Mermaid source to sanitized SVG on the client, with a toggle back to the raw source for copying/editing. */ export function MermaidDiagram({ source }: { source: string }) { @@ -10,6 +11,7 @@ export function MermaidDiagram({ source }: { source: string }) { const [svg, setSvg] = useState(null) const [error, setError] = useState(null) const [showSource, setShowSource] = useState(false) + const [expanded, setExpanded] = useState(false) useEffect(() => { let cancelled = false @@ -31,23 +33,39 @@ export function MermaidDiagram({ source }: { source: string }) { const failed = error !== null const displaySource = showSource || failed || svg === null + const canExpand = svg !== null && !failed && !showSource return (
Diagram - {!failed && svg !== null && ( - - )} +
+ {canExpand && ( + + )} + {!failed && svg !== null && ( + + )} +
{failed && ( @@ -59,6 +77,17 @@ export function MermaidDiagram({ source }: { source: string }) {
)}
+ {canExpand && ( + + + Diagram, fullscreen +
+ +
+ )}
) } diff --git a/tests/components/markdown-content.test.tsx b/tests/components/markdown-content.test.tsx index 67ab099..7603401 100644 --- a/tests/components/markdown-content.test.tsx +++ b/tests/components/markdown-content.test.tsx @@ -28,5 +28,6 @@ describe('MarkdownContent', () => { expect(html).toContain('flowchart TD') expect(html).toContain('A --> B') expect(html).not.toContain('language-mermaid') + expect(html).not.toContain('Expand') }) })