Skip to content

Commit 22f1e0b

Browse files
feat: custom image component with lighthouse effect
Signed-off-by: rishabhsharma1997 <[email protected]>
1 parent e7e1e2d commit 22f1e0b

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { useState } from 'react';
2+
import { Dialog } from '../../base';
3+
4+
interface ImageComponentProps {
5+
src: string;
6+
alt?: string;
7+
width?: number | string;
8+
height?: number | string;
9+
loading?: undefined | 'eager' | 'lazy';
10+
decoding?: 'sync' | 'async' | 'auto';
11+
crossOrigin?: 'anonymous' | 'use-credentials' | '';
12+
sizes?: string;
13+
srcSet?: string;
14+
className?: string;
15+
style?: React.CSSProperties;
16+
onClick?: (event: React.MouseEvent<HTMLImageElement, MouseEvent>) => void;
17+
}
18+
19+
const CustomImage: React.FC<ImageComponentProps> = ({ src, alt, ...props }) => {
20+
const [isZoomed, setIsZoomed] = useState(false);
21+
22+
const handleZoomClick = () => {
23+
setIsZoomed(true);
24+
};
25+
26+
const handleZoomClose = () => {
27+
setIsZoomed(false);
28+
};
29+
30+
return (
31+
<>
32+
<img
33+
src={src}
34+
alt={alt}
35+
loading="lazy"
36+
onClick={handleZoomClick}
37+
{...props}
38+
style={{
39+
cursor: 'pointer',
40+
maxWidth: '100%',
41+
height: 'auto',
42+
...props.style
43+
}}
44+
/>
45+
<Dialog
46+
open={isZoomed}
47+
onClose={handleZoomClose}
48+
style={{
49+
backgroundColor: 'rgba(0, 0, 0, 0.8)'
50+
}}
51+
PaperProps={{
52+
style: {
53+
background: 'transparent',
54+
boxShadow: 'none',
55+
overflow: 'auto',
56+
maxWidth: '60rem'
57+
}
58+
}}
59+
>
60+
<img
61+
src={src}
62+
alt={alt}
63+
style={{
64+
objectFit: 'contain',
65+
maxWidth: '100%',
66+
maxHeight: '100%'
67+
}}
68+
/>
69+
</Dialog>
70+
</>
71+
);
72+
};
73+
74+
export default CustomImage;

src/custom/CustomImage/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import CustomImage from './CustomImage';
2+
export { CustomImage };

src/custom/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CustomColumnVisibilityControl,
99
CustomColumnVisibilityControlProps
1010
} from './CustomColumnVisibilityControl/CustomColumnVisibilityControl';
11+
import { CustomImage } from './CustomImage';
1112
import { CustomTooltip, InfoTooltip } from './CustomTooltip';
1213
import {
1314
CustomDialog,
@@ -54,6 +55,7 @@ export {
5455
ConnectionChip,
5556
CustomColumnVisibilityControl,
5657
CustomDialog,
58+
CustomImage,
5759
CustomTooltip,
5860
EmptyState,
5961
ErrorBoundary,

0 commit comments

Comments
 (0)