-
-
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
feat: add experimental responsive images config option #12378
Changes from all commits
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 |
---|---|---|
|
@@ -1070,6 +1070,37 @@ export interface ViteUserConfig extends OriginalViteUserConfig { | |
|
||
*/ | ||
remotePatterns?: Partial<RemotePattern>[]; | ||
|
||
/** | ||
* @docs | ||
* @name image.experimentalLayout | ||
* @default `undefined` | ||
* @description | ||
* The default layout type for responsive images. Can be overridden by the `layout` prop on the image component. | ||
* Requires the `experimental.responsiveImages` flag to be enabled. | ||
* - `responsive` - The image will scale to fit the container, maintaining its aspect ratio, but will not exceed the specified dimensions. | ||
* - `fixed` - The image will maintain its original dimensions. | ||
* - `full-width` - The image will scale to fit the container, maintaining its aspect ratio. | ||
*/ | ||
experimentalLayout?: ImageLayout | undefined; | ||
/** | ||
* @docs | ||
* @name image.experimentalObjectFit | ||
* @default `"cover"` | ||
* @description | ||
* The default object-fit value for responsive images. Can be overridden by the `fit` prop on the image component. | ||
* Requires the `experimental.responsiveImages` flag to be enabled. | ||
*/ | ||
experimentalObjectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down' | (string & {}); | ||
/** | ||
* @docs | ||
* @name image.experimentalObjectPosition | ||
* @default `"center"` | ||
* @description | ||
* The default object-position value for responsive images. Can be overridden by the `position` prop on the image component. | ||
* Requires the `experimental.responsiveImages` flag to be enabled. | ||
*/ | ||
experimentalObjectPosition?: string; | ||
}; | ||
|
||
/** | ||
|
@@ -1699,9 +1730,44 @@ export interface ViteUserConfig extends OriginalViteUserConfig { | |
* To use this feature with the Astro VS Code extension, you must also enable the `astro.content-intellisense` option in your VS Code settings. For editors using the Astro language server directly, pass the `contentIntellisense: true` initialization parameter to enable this feature. | ||
*/ | ||
contentIntellisense?: boolean; | ||
|
||
/** | ||
* @docs | ||
* @name experimental.responsiveImages | ||
* @type {boolean} | ||
* @default `undefined` | ||
* @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. | ||
* | ||
* ```js | ||
* { | ||
* experimental: { | ||
* responsiveImages: { | ||
* layout: 'responsive', | ||
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. This now changes in that you only set this to And, since we now have multiple properties (acknowledging there may still even be more to come!), when you do add the regular image config for this example, I would set at least a couple of them. (Not meaning to overly edit while stuff is still happening, just didn't want us to forget!) |
||
* }, | ||
* } | ||
* ``` | ||
* | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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. | ||
* | ||
* ```astro | ||
* --- | ||
* import { Image } from 'astro:assets'; | ||
* import myImage from '../assets/my_image.png'; | ||
* --- | ||
* <Image src={myImage} alt="A description of my image." layout='fixed' /> | ||
* ``` | ||
* | ||
*/ | ||
|
||
responsiveImages?: boolean; | ||
}; | ||
} | ||
|
||
export type ImageLayout = 'responsive' | 'fixed' | 'full-width' | 'none'; | ||
|
||
/** | ||
* Resolved Astro Config | ||
* | ||
|
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've gone with the shorter names for the HTML attributes for ease of use and avoidance of confusion of camel vs kebab