import type { FC } from 'react' import { useRef } from 'react' import { t } from 'i18next' import { createPortal } from 'react-dom' import { RiCloseLine, RiExternalLinkLine } from '@remixicon/react' import Tooltip from '@/app/components/base/tooltip' import { randomString } from '@/utils' type ImagePreviewProps = { url: string title: string onCancel: () => void } const ImagePreview: FC = ({ url, title, onCancel, }) => { const selector = useRef(`copy-tooltip-${randomString(4)}`) const openInNewTab = () => { // Open in a new window, considering the case when the page is inside an iframe if (url.startsWith('http')) { window.open(url, '_blank') } else if (url.startsWith('data:image')) { // Base64 image const win = window.open() win?.document.write(`${title}`) } else { console.error('Unable to open image', url) } } return createPortal(
e.stopPropagation()}> {/* eslint-disable-next-line @next/next/no-img-element */} {title}
, document.body, ) } export default ImagePreview