import { CloseCircleOutlined } from '@ant-design/icons'; import { Progress } from 'antd'; import classNames from 'classnames'; import * as Vibrant from 'node-vibrant'; import React from 'react'; import AutoImage from './index'; import './single-image.less'; interface SingleImageProps { loading?: boolean; width?: number; height?: number; progress?: number; maxHeight?: number; maxWidth?: number; dataUrl: string; uid: number; autoSize?: boolean; onDelete: (uid: number) => void; autoBgColor?: boolean; editable?: boolean; } const SingleImage: React.FC = (props) => { const { editable, onDelete: handleOnDelete, autoSize, uid, loading, width, height, progress, maxHeight, maxWidth, dataUrl, autoBgColor } = props; const [color, setColor] = React.useState(''); const imgWrapper = React.useRef(null); const thumImgWrapStyle = React.useMemo(() => { return loading ? { width: width, height: height } : {}; }, [loading, width, height]); const handleOnLoad = React.useCallback(async () => { if (!autoBgColor) { return; } const img = imgWrapper.current?.querySelector('img'); if (!img) { return; } Vibrant.from(img.src).getPalette((err: any, palette: any) => { if (err) { console.error(err); return; } const color = palette?.Vibrant?.rgb; const rgba = color ? `rgba(${color[0]}, ${color[1]}, ${color[2]},0.7)` : ''; setColor(rgba); }); }, []); return (
{/* {autoBgColor && (
*/} <> {loading ? ( ) : ( )} {editable && ( handleOnDelete(uid)}> )}
); }; export default React.memo(SingleImage);