|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { Dialog } from '../../base'; |
| 3 | +import { DesignIcon, MesheryFilterIcon } from '../../icons'; |
| 4 | + |
| 5 | +interface CatalogCardDesignLogoProps { |
| 6 | + zoomEffect?: boolean; |
| 7 | + imgURL?: string[]; |
| 8 | + type: { type: string }; |
| 9 | + width: string; |
| 10 | + height: string; |
| 11 | + style?: React.CSSProperties; |
| 12 | +} |
| 13 | + |
| 14 | +const CatalogCardDesignLogo: React.FC<CatalogCardDesignLogoProps> = ({ |
| 15 | + zoomEffect = false, |
| 16 | + imgURL, |
| 17 | + type, |
| 18 | + width, |
| 19 | + height, |
| 20 | + style = {} |
| 21 | +}) => { |
| 22 | + const [imgError, setImgError] = useState(false); |
| 23 | + const [isZoomed, setIsZoomed] = useState(false); |
| 24 | + |
| 25 | + const handleZoomClick = () => { |
| 26 | + if (zoomEffect) { |
| 27 | + setIsZoomed(true); |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + const handleZoomClose = () => { |
| 32 | + setIsZoomed(false); |
| 33 | + }; |
| 34 | + |
| 35 | + const SvgComponent: React.FC<{ type: { type: string } }> = ({ type }) => { |
| 36 | + return type.type === 'filter' ? ( |
| 37 | + <MesheryFilterIcon width={width} height={height} style={style} /> |
| 38 | + ) : ( |
| 39 | + <DesignIcon width={width} height={height} style={style} /> |
| 40 | + ); |
| 41 | + }; |
| 42 | + |
| 43 | + return ( |
| 44 | + <> |
| 45 | + {imgURL && imgURL.length > 0 ? ( |
| 46 | + <div style={{ width: '100%', height: '7.5rem', position: 'relative' }}> |
| 47 | + {!imgError ? ( |
| 48 | + <> |
| 49 | + <img |
| 50 | + src={imgURL[0]} |
| 51 | + alt="Design SnapShot" |
| 52 | + loading="lazy" |
| 53 | + onClick={handleZoomClick} |
| 54 | + onError={() => setImgError(true)} |
| 55 | + style={{ |
| 56 | + cursor: 'pointer', |
| 57 | + width: '100%', |
| 58 | + height: '100%', |
| 59 | + objectFit: 'cover' |
| 60 | + }} |
| 61 | + /> |
| 62 | + <Dialog |
| 63 | + open={isZoomed} |
| 64 | + onClose={handleZoomClose} |
| 65 | + style={{ |
| 66 | + backgroundColor: 'rgba(0, 0, 0, 0.8)' |
| 67 | + }} |
| 68 | + PaperProps={{ |
| 69 | + style: { |
| 70 | + background: 'transparent', |
| 71 | + boxShadow: 'none', |
| 72 | + overflow: 'hidden', |
| 73 | + maxWidth: '60vw' |
| 74 | + } |
| 75 | + }} |
| 76 | + > |
| 77 | + <img |
| 78 | + src={imgURL[0]} |
| 79 | + alt="Zoomed Design SnapShot" |
| 80 | + style={{ objectFit: 'contain', maxWidth: '100%', maxHeight: '100%' }} |
| 81 | + /> |
| 82 | + </Dialog> |
| 83 | + </> |
| 84 | + ) : ( |
| 85 | + <SvgComponent type={type} /> |
| 86 | + )} |
| 87 | + </div> |
| 88 | + ) : ( |
| 89 | + <SvgComponent type={type} /> |
| 90 | + )} |
| 91 | + </> |
| 92 | + ); |
| 93 | +}; |
| 94 | + |
| 95 | +export default CatalogCardDesignLogo; |
0 commit comments