import * as React from 'react'; import { HiOutlineExternalLink, HiOutlineEye, HiOutlinePaperClip, HiOutlinePhotograph, HiX, } from 'react-icons/hi'; import Lightbox from 'react-image-lightbox'; import 'react-image-lightbox/style.css'; import UnstyledLink from '@/components/links/UnstyledLink'; import { FileWithPreview } from '@/types/dropzone'; type FilePreviewProps = { file: FileWithPreview; } & ( | { deleteFile?: ( e: React.MouseEvent, file: FileWithPreview ) => void; readOnly?: true; } | { deleteFile: ( e: React.MouseEvent, file: FileWithPreview ) => void; readOnly?: false; } ); export default function FilePreview({ deleteFile, file, readOnly, }: FilePreviewProps): React.ReactElement { const [index, setIndex] = React.useState(0); const [isOpen, setIsOpen] = React.useState(false); const images = [file.preview]; const handleDelete = (e: React.MouseEvent) => { e.stopPropagation(); deleteFile?.(e, file); }; const imagesType = ['image/png', 'image/jpg', 'image/jpeg']; return imagesType.includes(file.type) ? ( <>
  • {!readOnly && ( )}
  • {isOpen && ( setIsOpen(false)} onMovePrevRequest={() => setIndex( (prevIndex) => (prevIndex + images.length - 1) % images.length ) } onMoveNextRequest={() => setIndex((prevIndex) => (prevIndex + 1) % images.length) } /> )} ) : (
  • {!readOnly && ( )}
  • ); }