Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 04:30 UTC
docs: add click-to-expand zoom to Mermaid diagrams
Wrap Mermaid SVG output with react-medium-image-zoom (already used by images) so users can click any diagram to view it full-screen. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sushmitha Mallesh committed
Mar 3, 2026 at 22:43 UTC
8cf078182ce6602ca972a72b99b3da0e70acff30
1 file changed
+17
-6
docs/components/mermaid.tsx
+17
-6
@@ -2,15 +2,20 @@
2
3
import { useEffect, useRef, useState } from 'react';
4
import mermaid from 'mermaid';
5
+import Zoom from 'react-medium-image-zoom';
6
+import 'react-medium-image-zoom/dist/styles.css';
7
8
function getCssVar(name: string): string {
9
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
10
}
11
12
+function svgToDataUrl(svg: string): string {
13
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
14
+}
15
+
16
export function Mermaid({ chart }: { chart: string }) {
17
const renderCount = useRef(0);
18
const baseId = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);
13
- const containerRef = useRef<HTMLDivElement>(null);
19
const [svg, setSvg] = useState('');
20
21
useEffect(() => {
@@ -60,11 +65,17 @@ export function Mermaid({ chart }: { chart: string }) {
65
return () => observer.disconnect();
66
}, [chart]);
67
68
+ if (!svg) return null;
69
+
70
return (
64
- <div
65
- ref={containerRef}
66
- className="my-4 overflow-x-auto max-w-full mx-auto [&>svg]:mx-auto"
67
- dangerouslySetInnerHTML={{ __html: svg }}
68
- />
71
+ <div className="my-4 max-w-full mx-auto">
72
+ <Zoom>
73
+ <img
74
+ src={svgToDataUrl(svg)}
75
+ alt="Mermaid diagram"
76
+ className="mx-auto"
77
+ />
78
+ </Zoom>
79
+ </div>
80
);
81
}