|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { cn } from '@/lib/utils' |
| 4 | +import React from 'react' |
| 5 | + |
| 6 | +import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch' |
| 7 | +import { Button } from './ui/button' |
| 8 | +import { |
| 9 | + ArrowPathIcon, |
| 10 | + MagnifyingGlassMinusIcon, |
| 11 | + MagnifyingGlassPlusIcon, |
| 12 | +} from '@heroicons/react/24/outline' |
| 13 | + |
| 14 | +interface MermaidZoomProps extends React.ComponentPropsWithoutRef<'svg'> {} |
| 15 | + |
| 16 | +const MermaidZoom: React.FC<MermaidZoomProps> = (props) => ( |
| 17 | + <div className="relative flex items-center justify-center"> |
| 18 | + <TransformWrapper centerOnInit initialScale={0.9} minScale={0.75}> |
| 19 | + {({ zoomIn, zoomOut, resetTransform, instance }) => ( |
| 20 | + <React.Fragment> |
| 21 | + <div className="absolute right-2 top-2 z-10 space-x-1"> |
| 22 | + <Button variant="outline" size="icon" onClick={() => zoomIn()}> |
| 23 | + <MagnifyingGlassPlusIcon className="size-5" /> |
| 24 | + </Button> |
| 25 | + <Button variant="outline" size="icon" onClick={() => zoomOut()}> |
| 26 | + <MagnifyingGlassMinusIcon className="size-5" /> |
| 27 | + </Button> |
| 28 | + <Button |
| 29 | + variant="outline" |
| 30 | + size="icon" |
| 31 | + onClick={() => resetTransform()} |
| 32 | + > |
| 33 | + <ArrowPathIcon className="size-5" /> |
| 34 | + </Button> |
| 35 | + </div> |
| 36 | + <TransformComponent |
| 37 | + wrapperClass="bg-white rounded-lg !w-full cursor-move" |
| 38 | + contentClass={'!w-full !h-full'} |
| 39 | + > |
| 40 | + <svg |
| 41 | + {...props} |
| 42 | + className={cn('mx-auto px-2 py-4', props.className)} |
| 43 | + /> |
| 44 | + </TransformComponent> |
| 45 | + </React.Fragment> |
| 46 | + )} |
| 47 | + </TransformWrapper> |
| 48 | + </div> |
| 49 | +) |
| 50 | + |
| 51 | +export default MermaidZoom |
0 commit comments