Skip to content

Commit f20cf44

Browse files
committed
Add sizes prop to Image component and update responsive behavior in Basic example
1 parent 4b71974 commit f20cf44

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/components/Image.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const Image = (props: IKImageProps) => {
5151
const contextValues = useContext(ImageKitContext);
5252

5353
// Its important to extract the ImageKit specific props from the props, so that we can use the rest of the props as is in the img element
54-
const { transformation = [], src = "", loading = "lazy", queryParameters, urlEndpoint, transformationPosition, responsive = true, ...nonIKParams } = {
54+
const { transformation = [], src = "", loading = "lazy", queryParameters, urlEndpoint, transformationPosition, sizes, responsive = true, ...nonIKParams } = {
5555
...contextValues, // Default values from context
5656
...props // Override with props
5757
};
@@ -69,24 +69,27 @@ export const Image = (props: IKImageProps) => {
6969
src,
7070
transformation,
7171
width: isNaN(widthInt) ? undefined : widthInt,
72-
sizes: nonIKParams.sizes,
72+
sizes,
7373
queryParameters,
7474
urlEndpoint,
7575
transformationPosition
7676
})
7777

7878
if (!responsive) {
79-
<img
80-
loading={loading}
81-
{...nonIKParams}
82-
src={newSrc}
83-
/>
79+
return (
80+
<img
81+
{...nonIKParams}
82+
loading={loading}
83+
src={newSrc}
84+
/>
85+
)
8486
}
8587

8688
return (
8789
<img
88-
loading={loading}
8990
{...nonIKParams}
91+
loading={loading}
92+
sizes={sizes}
9093
srcSet={srcSet}
9194
src={newSrc}
9295
/>

test-app/app/components/basic.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Image, ImageKitProvider, Video } from "@imagekit/react";
22

3-
43
export const Basic = () => {
54
return (
65
<div>
@@ -131,7 +130,7 @@ export const Basic = () => {
131130
transformation={[{
132131
named: "restrict-unnamed",
133132
}]}
134-
responsive={true}
133+
responsive={false}
135134
sizes="(max-width: 600px) 100vw, 50vw"
136135
/>
137136

@@ -194,7 +193,6 @@ export const Basic = () => {
194193
controls={true}
195194
/>
196195
</ImageKitProvider>
197-
198196
</div>
199197
)
200198
}

0 commit comments

Comments
 (0)