MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / MermaidButton

Function MermaidButton

webview-ui/src/components/common/MermaidButton.tsx:23–246  ·  view source on GitHub ↗
({ containerRef, code, isLoading, svgToPng, children }: MermaidButtonProps)

Source from the content-addressed store, hash-verified

21}
22
23export function MermaidButton({ containerRef, code, isLoading, svgToPng, children }: MermaidButtonProps) {
24 const [showModal, setShowModal] = useState(false)
25 const [zoomLevel, setZoomLevel] = useState(1)
26 const [copyFeedback, setCopyFeedback] = useState(false)
27 const [isHovering, setIsHovering] = useState(false)
28 const [modalViewMode, setModalViewMode] = useState<"diagram" | "code">("diagram")
29 const [isDragging, setIsDragging] = useState(false)
30 const [dragPosition, setDragPosition] = useState({ x: 0, y: 0 })
31 const { copyWithFeedback } = useCopyToClipboard()
32 const { t } = useAppTranslation()
33
34 /**
35 * Opens a modal with the diagram for zooming
36 */
37 const handleZoom = async (e: React.MouseEvent) => {
38 e.stopPropagation()
39 setShowModal(true)
40 setZoomLevel(1)
41 setModalViewMode("diagram")
42 }
43
44 /**
45 * Copies the diagram text to clipboard
46 */
47 const handleCopy = async (e: React.MouseEvent) => {
48 e.stopPropagation()
49
50 try {
51 await copyWithFeedback(code, e)
52
53 // Show feedback
54 setCopyFeedback(true)
55 setTimeout(() => setCopyFeedback(false), 2000)
56 } catch (err) {
57 console.error("Error copying text:", err instanceof Error ? err.message : String(err))
58 }
59 }
60
61 /**
62 * Saves the diagram as an image file
63 */
64 const handleSave = async (e: React.MouseEvent) => {
65 e.stopPropagation()
66
67 // Get the SVG element from the container
68 const svgEl = containerRef.current?.querySelector("svg")
69 if (!svgEl) {
70 console.error("SVG element not found")
71 return
72 }
73
74 try {
75 // Convert SVG to PNG
76 const pngDataUrl = await svgToPng(svgEl)
77
78 // Send message to VSCode to save the image
79 vscode.postMessage({
80 type: "saveImage",

Callers

nothing calls this directly

Calls 4

useCopyToClipboardFunction · 0.90
useAppTranslationFunction · 0.90
tFunction · 0.85
adjustZoomFunction · 0.70

Tested by

no test coverage detected