diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-22 15:09:39 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-22 15:09:39 +0200 |
| commit | 321dae4a47594af83269fa560b375965d7f35763 (patch) | |
| tree | 28392e486bb8c99c231e767d1532935c5ebc1b94 /.storybook | |
| parent | 70bd37fe14d4e0c1538291fa97b0522ab6d20941 (diff) | |
fix: render all images unoptimized in Storybook
There is a bug with next/image and Storybook. I was manually adding
`unoptimized` to images. Instead we can use a workaround by adding an
extra config in Storybook `preview.js` file.
Diffstat (limited to '.storybook')
| -rw-r--r-- | .storybook/preview.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/.storybook/preview.js b/.storybook/preview.js index 344df2a..e30927b 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,6 +1,24 @@ import '@styles/globals.scss'; +import * as NextImage from 'next/image'; import { IntlProvider } from 'react-intl'; +const OriginalNextImage = NextImage.default; + +Object.defineProperty(NextImage, 'default', { + configurable: true, + value: (props) => + typeof props.src === 'string' ? ( + <OriginalNextImage {...props} unoptimized blurDataURL={props.src} /> + ) : ( + <OriginalNextImage {...props} unoptimized /> + ), +}); + +Object.defineProperty(NextImage, '__esModule', { + configurable: true, + value: true, +}); + export const parameters = { actions: { argTypesRegex: '^on[A-Z].*' }, controls: { |
