-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add docs for responsive images #12429
Changes from 3 commits
3ba577a
6cdb28e
c7cebd8
9ac1807
6701c7b
16a8c0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1743,27 +1743,38 @@ export interface ViteUserConfig extends OriginalViteUserConfig { | |||||||||||||
* @version 5.0.0 | ||||||||||||||
* @description | ||||||||||||||
* | ||||||||||||||
* Enables and configures automatic responsive image options for images in your project. Set to `true` (for no default option passed to your images) or an object with default responsive image configuration options. | ||||||||||||||
* Enables automatic responsive images in your project. | ||||||||||||||
* | ||||||||||||||
* ```js | ||||||||||||||
* { | ||||||||||||||
* experimental: { | ||||||||||||||
* responsiveImages: { | ||||||||||||||
* layout: 'responsive', | ||||||||||||||
* experimental: { | ||||||||||||||
* responsiveImages: true, | ||||||||||||||
* }, | ||||||||||||||
* } | ||||||||||||||
* ``` | ||||||||||||||
* | ||||||||||||||
* Then, you can add a `layout` option to any `<Image />` component when needed to override your default configuration: `responsive`, `fixed`, `full-width`, or `none`. This attribute is required to transform your images if `responsiveImages.layout` is not configured. Images with a layout value of `undefined` or `none` will not be transformed. | ||||||||||||||
* When enabled, you can pass a `layout` props to any `<Image /> or `<Picture />` to enable automatic responsive images. You can also set a default value using `image.experimentalLayout`. When a layout is set, images have automatically generated `srcset` and `sizes` attributes based on the image's dimensions and the layout type. Images with `responsive` and `full-width` layouts will have styles applied to ensure they resize according to their container. | ||||||||||||||
* | ||||||||||||||
* ```astro | ||||||||||||||
* --- | ||||||||||||||
* import { Image } from 'astro:assets'; | ||||||||||||||
* import { Image, Picture } from 'astro:assets'; | ||||||||||||||
* import myImage from '../assets/my_image.png'; | ||||||||||||||
* --- | ||||||||||||||
* <Image src={myImage} alt="A description of my image." layout='fixed' /> | ||||||||||||||
* <Image src={myImage} alt="A description of my image." layout='responsive' width={800} height={600} /> | ||||||||||||||
* <Picture src={myImage} alt="A description of my image." layout='full-width' formats={['avif', 'webp', 'jpeg']} /> | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I didn't is because it's very verbose, with a large srcset. I could do an abbreviated one though. |
||||||||||||||
* ``` | ||||||||||||||
* | ||||||||||||||
* | ||||||||||||||
* ### Responsive image properties | ||||||||||||||
* | ||||||||||||||
* These are additional Image properties available when responsive images are enabled: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just confirming, not the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah no, it's for both |
||||||||||||||
* | ||||||||||||||
* - `layout`: The layout type for the image. Can be `responsive`, `fixed`, `full-width` or `none`. Defaults to value of `image.experimentalLayout`. | ||||||||||||||
* - `fit`: Defines how the image should be cropped if the aspect ratio is changed. Values match those of CSS `object-fit`. Defaults to `cover`, or the value of `image.experimentalObjectFit` if set. | ||||||||||||||
* - `position`: Defines the position of the image crop if the aspect ratio is changed. Values match those of CSS `object-position`. Defaults to `center`, or the value of `image.experimentalObjectPosition` if set. | ||||||||||||||
* - `priority`: If set, eagerly loads the image. Otherwise images will be lazy-loaded. Use this for your largest above-the-fold image. Defaults to `false`. | ||||||||||||||
* | ||||||||||||||
* The `densities` prop is not supported when using responsive images. It is not recommended to use the `widths` or `sizes` props as these are automatically generated based on the image's dimensions and the layout type. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe something like this? Make it more accurate (but doesn't have to be ENTIRELY and comprehensively accurate; just needs to say these are the ones not to use). I think framing them as the list not to use vs putting this info in paragraph text is more scannable. |
||||||||||||||
* | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
responsiveImages?: boolean; | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether setting
image.experimentalLayout
makes ALL your<Image />
components responsive by default, or (as my suggestion above is for), you still need to specify<Image layout />
but you just don't have to pass a value and the default set will be used.So I think something like what I suggested above works for that second case. If the first case is actually true, then I think that could be made explicit more like:
The main point of the feedback was that I wasn't entirely sure what the "default" behaviour is, so something that makes that more explicit is probably helpful!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
experimentalLayout
does enable it for all Images and Pictures. That's just a default though: you can instead enable it on an image-by-image basis, and if it is set, you can override it on each image too. I'll try to word that more clearly!