-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description This PR refactors the Image component so that the core logic can be consolidated into a single function. This allows usage outside of `<Image>`, such as: 1. Working with [`background-image`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-image) or [`image-set`](https://developer.mozilla.org/en-US/docs/Web/CSS/image/image-set) 2. Working with canvas [`context.drawImage()`](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Using_images) or simply `new Image()` 3. Working with [`<picture>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) media queries to implement Art Direction or Light/Dark Mode images ### Example ```tsx import { unstable_getImgProps as getImgProps } from 'next/image' export default function Page() { const common = { alt: 'Hero', width: 800, height: 400 } const { props: { srcSet: dark } } = getImgProps({ ...common, src: '/dark.png' }) const { props: { srcSet: light, ...rest } } = getImgProps({ ...common, src: '/light.png' }) return (<picture> <source media="(prefers-color-scheme: dark)" srcSet={dark} /> <source media="(prefers-color-scheme: light)" srcSet={light} /> <img {...rest} /> </picture>) } ``` ### Related fix NEXT-257 Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
- Loading branch information
Showing
16 changed files
with
1,449 additions
and
998 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import Image from './dist/client/image' | ||
export * from './dist/client/image' | ||
import Image from './dist/shared/lib/image-external' | ||
export * from './dist/shared/lib/image-external' | ||
export default Image |
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./dist/client/image') | ||
module.exports = require('./dist/shared/lib/image-external') |
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
Oops, something went wrong.