-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing props to every instance of next/image using parameters
- Loading branch information
1 parent
97dbc82
commit e06f67e
Showing
7 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createContext } from 'react'; | ||
import type * as _NextImage from 'next/image'; | ||
import type * as _NextLegacyImage from 'next/legacy/image'; | ||
|
||
export const ImageContext = createContext< | ||
Partial<_NextImage.ImageProps & _NextLegacyImage.ImageProps> | ||
>({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import type { Addon_StoryContext } from '@storybook/types'; | ||
import { ImageContext } from './context'; | ||
|
||
export const ImageDecorator = ( | ||
Story: React.FC, | ||
{ parameters }: Addon_StoryContext | ||
): React.ReactNode => { | ||
if (!parameters.nextjs?.image) { | ||
return <Story />; | ||
} | ||
|
||
return ( | ||
<ImageContext.Provider value={parameters.nextjs.image}> | ||
<Story /> | ||
</ImageContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters