forked from layer5io/sistent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom image component with lighthouse effect
Signed-off-by: rishabhsharma1997 <[email protected]>
- Loading branch information
1 parent
e7e1e2d
commit 22f1e0b
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import { Dialog } from '../../base'; | ||
|
||
interface ImageComponentProps { | ||
src: string; | ||
alt?: string; | ||
width?: number | string; | ||
height?: number | string; | ||
loading?: undefined | 'eager' | 'lazy'; | ||
decoding?: 'sync' | 'async' | 'auto'; | ||
crossOrigin?: 'anonymous' | 'use-credentials' | ''; | ||
sizes?: string; | ||
srcSet?: string; | ||
className?: string; | ||
style?: React.CSSProperties; | ||
onClick?: (event: React.MouseEvent<HTMLImageElement, MouseEvent>) => void; | ||
} | ||
|
||
const CustomImage: React.FC<ImageComponentProps> = ({ src, alt, ...props }) => { | ||
const [isZoomed, setIsZoomed] = useState(false); | ||
|
||
const handleZoomClick = () => { | ||
setIsZoomed(true); | ||
}; | ||
|
||
const handleZoomClose = () => { | ||
setIsZoomed(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<img | ||
src={src} | ||
alt={alt} | ||
loading="lazy" | ||
onClick={handleZoomClick} | ||
{...props} | ||
style={{ | ||
cursor: 'pointer', | ||
maxWidth: '100%', | ||
height: 'auto', | ||
...props.style | ||
}} | ||
/> | ||
<Dialog | ||
open={isZoomed} | ||
onClose={handleZoomClose} | ||
style={{ | ||
backgroundColor: 'rgba(0, 0, 0, 0.8)' | ||
}} | ||
PaperProps={{ | ||
style: { | ||
background: 'transparent', | ||
boxShadow: 'none', | ||
overflow: 'auto', | ||
maxWidth: '60rem' | ||
} | ||
}} | ||
> | ||
<img | ||
src={src} | ||
alt={alt} | ||
style={{ | ||
objectFit: 'contain', | ||
maxWidth: '100%', | ||
maxHeight: '100%' | ||
}} | ||
/> | ||
</Dialog> | ||
</> | ||
); | ||
}; | ||
|
||
export default CustomImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import CustomImage from './CustomImage'; | ||
export { CustomImage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters