@@ -13,10 +13,10 @@ interface ImageLightboxProps
13
13
'ref' | 'src' | 'width' | 'height' | 'alt'
14
14
> {
15
15
alt : string ;
16
- height : number ;
17
16
imgPath : string ;
18
17
src : string ;
19
- width : number ;
18
+ height ?: number ;
19
+ width ?: number ;
20
20
}
21
21
22
22
export function ImageLightbox ( {
@@ -31,8 +31,17 @@ export function ImageLightbox({
31
31
} : ImageLightboxProps ) {
32
32
const [ open , setOpen ] = useState ( false ) ;
33
33
34
- // Check if dimensions are valid (not NaN) for Next.js Image
35
- const isValidDimensions = ! isNaN ( width ) && ! isNaN ( height ) && width > 0 && height > 0 ;
34
+ // Check if we should use Next.js Image or regular img
35
+ // Use Next.js Image for internal images with valid dimensions
36
+ // Use regular img for external images or when dimensions are invalid/missing
37
+ const shouldUseNextImage =
38
+ ! src . startsWith ( 'http' ) && // Internal image
39
+ width != null &&
40
+ height != null && // Dimensions provided
41
+ ! isNaN ( width ) &&
42
+ ! isNaN ( height ) && // Valid numbers
43
+ width > 0 &&
44
+ height > 0 ; // Positive values
36
45
37
46
const handleClick = ( e : React . MouseEvent ) => {
38
47
// If Ctrl/Cmd+click, open image in new tab
@@ -70,14 +79,14 @@ export function ImageLightbox({
70
79
// Next.js Image has stricter typing for certain props like 'placeholder'
71
80
const { placeholder : _placeholder , ...imageCompatibleProps } = props ;
72
81
73
- // Render the appropriate image component based on dimension validity
82
+ // Render the appropriate image component
74
83
const renderImage = ( ) => {
75
- if ( isValidDimensions ) {
84
+ if ( shouldUseNextImage ) {
76
85
return (
77
86
< Image
78
87
src = { src }
79
- width = { width }
80
- height = { height }
88
+ width = { width ! }
89
+ height = { height ! }
81
90
style = { {
82
91
width : '100%' ,
83
92
height : 'auto' ,
@@ -131,12 +140,12 @@ export function ImageLightbox({
131
140
132
141
{ /* Image container */ }
133
142
< div className = "relative flex items-center justify-center" >
134
- { isValidDimensions ? (
143
+ { shouldUseNextImage ? (
135
144
< Image
136
145
src = { src }
137
146
alt = { alt }
138
- width = { width }
139
- height = { height }
147
+ width = { width ! }
148
+ height = { height ! }
140
149
className = "max-h-[90vh] max-w-[90vw] object-contain"
141
150
style = { {
142
151
width : 'auto' ,
0 commit comments