import React from 'react'; import { forwardRef } from '../../utils/forwardRef'; import { PreviewBase } from './PreviewBase'; export interface PreviewImageVisualProps { /** * Width of the thumbnail image. */ thumbnailWidth?: number; } const usePreviewImageVisuals = ({ thumbnailWidth = 30 }: PreviewImageVisualProps) => { return { thumbnailProps: { className: 'preview__thumbnail', style: { width: thumbnailWidth }, }, imageProps: { className: 'preview__image', }, }; }; /** @inheritdoc */ export interface PreviewImageProps extends PreviewImageVisualProps { /** * Source of the thumbnail image. */ thumbnailSrc: string; /** * Source of the full image. */ src: string; /** * Alt text for the image. */ alt: string; } export const PreviewImage = forwardRef(function PreviewImage( { src, thumbnailSrc, thumbnailWidth = 30, alt, ...restProps }: PreviewImageProps, ref: React.ForwardedRef ) { restProps satisfies Record; const { thumbnailProps, imageProps } = usePreviewImageVisuals({ thumbnailWidth }); return ( ref={ref} content={({ close }) => {alt} close(true)} />} offset={-thumbnailWidth} placement='bottom left' closeDelay={0} > {triggerProps => {alt}} ); });