import React, { useState } from 'react'; import { Box } from '../Box/Box'; import { Center } from '../Center/Center'; import { Skeleton } from '../Skeleton/Skeleton'; import { useStyles, useTheme } from '../../core'; // FIX: Export ImageProps to allow it to be imported and used in other components like Card. export interface ImageProps extends React.ImgHTMLAttributes { fallbackSrc?: string; fallback?: React.ReactNode; fit?: React.CSSProperties['objectFit']; radius?: string; } export const Image: React.FC = ({ src, fallbackSrc, fallback, fit = 'cover', radius = '8px', className, ...props }) => { const { theme } = useTheme(); const createStyle = useStyles('image'); const [status, setStatus] = useState<'loading' | 'loaded' | 'error'>('loading'); const handleLoad = () => setStatus('loaded'); const handleError = () => setStatus('error'); const imageClass = createStyle({ width: '100%', height: '100%', objectFit: fit, borderRadius: radius, }); const finalSrc = status === 'error' && fallbackSrc ? fallbackSrc : src; return ( {status === 'loading' && } {status === 'error' && !fallbackSrc && fallback && (
{fallback}
)}
); };