Skip to content

Commit 159a64a

Browse files
authored
fix a bug where fill would be applied even if explicitly set to false
1 parent 5e719e8 commit 159a64a

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

example/pages/index.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ProxyImage,
77
buildProxyImagePath,
88
} from '@bitpatty/next-image-s3-imgproxy-loader';
9+
import { useEffect, useRef, useState } from 'react';
910

1011
const demoContent: {
1112
label: string;
@@ -111,6 +112,18 @@ const demoContent: {
111112
];
112113

113114
const Home: NextPage = () => {
115+
const [size, setSize] = useState<number>(200);
116+
const sizeToggle = useRef<boolean>(false);
117+
118+
useEffect(() => {
119+
const interval = setInterval(() => {
120+
sizeToggle.current = !sizeToggle.current;
121+
setSize(sizeToggle.current ? 200 : 100);
122+
}, 3000);
123+
124+
return () => clearInterval(interval);
125+
}, []);
126+
114127
return (
115128
<>
116129
<Head>
@@ -128,6 +141,20 @@ const Home: NextPage = () => {
128141
</div>
129142
))}
130143
</div>
144+
<div>
145+
<div>
146+
<h2>Dynamic</h2>
147+
<div className="imgcontainer">
148+
<img
149+
src={buildProxyImagePath('test-bucket/test-image.png', {
150+
proxyParams: pb()
151+
.resize({ width: size, height: size })
152+
.build(),
153+
})}
154+
/>
155+
</div>
156+
</div>
157+
</div>
131158
<div>
132159
<div>
133160
<h2>Background Image</h2>

example/styles/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ main > div > div {
1717
height: 200px;
1818
width: 200px;
1919
}
20+

src/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ const ProxyImage = ({
277277
return `${endpoint ?? IMGPROXY_ENDPOINT}?${urlParams.toString()}`;
278278
};
279279

280-
return (
281-
<Image
282-
src={file}
283-
loader={imageLoader}
284-
{...(props.width == null && !props.fill ? { fill: true } : {})}
285-
{...props}
286-
/>
287-
);
280+
// Toggle fill on if width is not provided
281+
const fillProp = props.fill
282+
? { fill: true }
283+
: props.width == null && props.fill == null
284+
? { fill: true }
285+
: {};
286+
287+
return <Image src={file} loader={imageLoader} {...props} {...fillProp} />;
288288
};
289289

290290
export { ProxyImage, IMGPROXY_ENDPOINT, buildProxyImagePath, handle };

0 commit comments

Comments
 (0)