-
-
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.
Merge pull request #25745 from piratetaco/patch-2
Next.js: Support getImageProps API
- Loading branch information
Showing
5 changed files
with
99 additions
and
52 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
33 changes: 33 additions & 0 deletions
33
code/frameworks/nextjs/template/stories_nextjs-default-js/GetImageProps.stories.jsx
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,33 @@ | ||
import { getImageProps } from 'next/image'; | ||
import React from 'react'; | ||
|
||
import Accessibility from '../../assets/accessibility.svg'; | ||
import Testing from '../../assets/testing.png'; | ||
|
||
// referenced from https://nextjs.org/docs/pages/api-reference/components/image#theme-detection-picture | ||
const Component = (props) => { | ||
const { | ||
props: { srcSet: dark }, | ||
} = getImageProps({ src: Accessibility, ...props }); | ||
const { | ||
// capture rest on one to spread to img as default; it doesn't matter which barring art direction | ||
props: { srcSet: light, ...rest }, | ||
} = getImageProps({ src: Testing, ...props }); | ||
|
||
return ( | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcSet={dark} /> | ||
<source media="(prefers-color-scheme: light)" srcSet={light} /> | ||
<img {...rest} /> | ||
</picture> | ||
); | ||
}; | ||
|
||
export default { | ||
component: Component, | ||
args: { | ||
alt: 'getImageProps Example', | ||
}, | ||
}; | ||
|
||
export const Default = {}; |
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