/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ import React from 'react'; import FileSaver from 'file-saver'; import classNames from 'classnames'; import { Box, Chip, Header, Icon, IconButton, Icons, Text, as } from 'folds'; import * as css from './ImageViewer.css'; import { useZoom } from '../../hooks/useZoom'; import { usePan } from '../../hooks/usePan'; import { downloadMedia } from '../../utils/matrix'; export type ImageViewerProps = { alt: string; src: string; requestClose: () => void; }; export const ImageViewer = as<'div', ImageViewerProps>( ({ className, alt, src, requestClose, ...props }, ref) => { const { zoom, zoomIn, zoomOut, setZoom } = useZoom(0.2); const { pan, cursor, onMouseDown } = usePan(zoom !== 1); const handleDownload = async () => { const fileContent = await downloadMedia(src); FileSaver.saveAs(fileContent, alt); }; return (
{alt} setZoom(zoom === 1 ? 2 : 1)}> {Math.round(zoom * 100)}% 1 ? 'Success' : 'SurfaceVariant'} outlined={zoom > 1} size="300" radii="Pill" onClick={zoomIn} aria-label="Zoom In" > } > Download
{alt}
); } );