Skip to content

Commit cf54d02

Browse files
authored
Improve UnoptimizedImage docs (#583)
When working with nextjs, image component has "fill" property. If not handled correctly, components in Ladle look different than on the page.
1 parent eaac9e9 commit cf54d02

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/website/docs/nextjs.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,29 @@ export default UnoptimizedLink;
3535
```
3636

3737
```tsx title=".ladle/UnoptimizedImage.tsx"
38-
const UnoptimizedImage = (props: any) => {
39-
return <img {...props} />;
38+
import React from 'react';
39+
40+
interface UnoptimizedImageProps
41+
extends React.ImgHTMLAttributes<HTMLImageElement> {
42+
fill?: boolean;
43+
}
44+
45+
const UnoptimizedImage: React.FC<UnoptimizedImageProps> = ({
46+
fill,
47+
...props
48+
}) => {
49+
const style: React.CSSProperties = fill
50+
? {
51+
position: 'absolute',
52+
inset: '0',
53+
width: '100%',
54+
height: '100%',
55+
}
56+
: {};
57+
58+
return <img {...props} style={style} />;
4059
};
60+
4161
export default UnoptimizedImage;
4262
```
4363

0 commit comments

Comments
 (0)