You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add optional media key to PropTypes and Typescript declarations
* Add optional fluidImages and fixedImages props
* Add art direction to fixed and fluid images
* Add art direction to base64 and tracedSVG
* Add art direction to noscript image
* Add tests for fixedImages and fluidImages
* Respond to code review
* Use const in tests
* Additinal code review refactor
* Fix e2e tests
* Add README docs
* Fix typo and update wording in README
* Name selectors in e2e test
* Work around SVG bug by encoding spaces
* Fix breaking Placeholder change, respond to code review, and update snapshots
* Use @polarthene's Pastebin
* Update sharp snapshot test
* Reset integration tests
* Move fluidImages & fixedImages into fluid & fixed
* update tests with no media
* cleanup spreadprops
* Add warning if multiple sources with no media were used
* review changes
* fix tests
Copy file name to clipboardExpand all lines: packages/gatsby-image/README.md
+77-23
Original file line number
Diff line number
Diff line change
@@ -331,31 +331,85 @@ You will need to add it in your graphql query as is shown in the following snipp
331
331
}
332
332
```
333
333
334
+
## Art-directing multiple images
335
+
336
+
`gatsby-image` supports showing different images at different breakpoints, which is known as [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#Art_direction). To do this, you can define your own array of `fixed` or `fluid` images, along with a `media` key per image, and pass it to `gatsby-image`'s `fixed` or `fluid` props. The `media` key that is set on an image can be any valid CSS media query.
337
+
338
+
```jsx
339
+
importReactfrom"react"
340
+
import { graphql } from"gatsby"
341
+
importImgfrom"gatsby-image"
342
+
343
+
exportdefault ({ data }) => {
344
+
// Set up the array of image data and `media` keys.
While you could achieve a similar effect with plain CSS media queries, `gatsby-image` accomplishes this using the `<picture>` tag, which ensures that browsers only download the image they need for a given breakpoint.
|`fixed`|`object`| Data returned from the `fixed` query |
339
-
|`fluid`|`object`| Data returned from the `fluid` query |
340
-
|`fadeIn`|`bool`| Defaults to fading in the image on load |
341
-
|`durationFadeIn`|`number`| fading duration is set up to 500ms by default |
342
-
|`title`|`string`| Passed to the `img` element |
343
-
|`alt`|`string`| Passed to the `img` element. Defaults to an empty string `alt=""`|
344
-
|`crossOrigin`|`string`| Passed to the `img` element |
345
-
|`className`|`string` / `object`| Passed to the wrapper element. Object is needed to support Glamor's css prop |
346
-
|`style`|`object`| Spread into the default styles of the wrapper element |
347
-
|`imgStyle`|`object`| Spread into the default styles of the actual `img` element |
348
-
|`placeholderStyle`|`object`| Spread into the default styles of the placeholder `img` element |
349
-
|`placeholderClassName`|`string`| A class that is passed to the placeholder `img` element |
350
-
|`backgroundColor`|`string` / `bool`| Set a colored background placeholder. If true, uses "lightgray" for the color. You can also pass in any valid color string. |
351
-
|`onLoad`|`func`| A callback that is called when the full-size image has loaded. |
352
-
|`onStartLoad`|`func`| A callback that is called when the full-size image starts loading, it gets the parameter { wasCached: boolean } provided. |
353
-
|`onError`|`func`| A callback that is called when the image fails to load. |
354
-
|`Tag`|`string`| Which HTML tag to use for wrapping elements. Defaults to `div`. |
355
-
|`objectFit`|`string`| Passed to the `object-fit-images` polyfill when importing from `gatsby-image/withIEPolyfill`. Defaults to `cover`. |
356
-
|`objectPosition`|`string`| Passed to the `object-fit-images` polyfill when importing from `gatsby-image/withIEPolyfill`. Defaults to `50% 50%`. |
357
-
|`loading`|`string`| Set the browser's native lazy loading attribute. One of `lazy`, `eager` or `auto`. Defaults to `lazy`. |
358
-
|`critical`|`bool`| Opt-out of lazy-loading behavior. Defaults to `false`. Deprecated, use `loading` instead. |
|`fixed`|`object` / `array`| Data returned from the `fixed` query. When prop is an array it has to be combined with `media` keys, allows for art directing `fixed` images. |
391
+
|`fluid`|`object` / `array`| Data returned from the `fluid` query. When prop is an array it has to be combined with `media` keys, allows for art directing `fluid` images. |
392
+
|`fadeIn`|`bool`| Defaults to fading in the image on load |
393
+
|`durationFadeIn`|`number`| fading duration is set up to 500ms by default |
394
+
|`title`|`string`| Passed to the `img` element |
395
+
|`alt`|`string`| Passed to the `img` element. Defaults to an empty string `alt=""`|
396
+
|`crossOrigin`|`string`| Passed to the `img` element |
397
+
|`className`|`string` / `object`| Passed to the wrapper element. Object is needed to support Glamor's css prop |
398
+
|`style`|`object`| Spread into the default styles of the wrapper element |
399
+
|`imgStyle`|`object`| Spread into the default styles of the actual `img` element |
400
+
|`placeholderStyle`|`object`| Spread into the default styles of the placeholder `img` element |
401
+
|`placeholderClassName`|`string`| A class that is passed to the placeholder `img` element |
402
+
|`backgroundColor`|`string` / `bool`| Set a colored background placeholder. If true, uses "lightgray" for the color. You can also pass in any valid color string. |
403
+
|`onLoad`|`func`| A callback that is called when the full-size image has loaded. |
404
+
|`onStartLoad`|`func`| A callback that is called when the full-size image starts loading, it gets the parameter { wasCached: boolean } provided. |
405
+
|`onError`|`func`| A callback that is called when the image fails to load. |
406
+
|`Tag`|`string`| Which HTML tag to use for wrapping elements. Defaults to `div`. |
407
+
|`objectFit`|`string`| Passed to the `object-fit-images` polyfill when importing from `gatsby-image/withIEPolyfill`. Defaults to `cover`. |
408
+
|`objectPosition`|`string`| Passed to the `object-fit-images` polyfill when importing from `gatsby-image/withIEPolyfill`. Defaults to `50% 50%`. |
409
+
|`loading`|`string`| Set the browser's native lazy loading attribute. One of `lazy`, `eager` or `auto`. Defaults to `lazy`. |
410
+
|`critical`|`bool`| Opt-out of lazy-loading behavior. Defaults to `false`. Deprecated, use `loading` instead. |
411
+
|`fixedImages`|`array`| An array of objects returned from `fixed` queries. When combined with `media` keys, allows for art directing `fixed` images. |
412
+
|`fluidImages`|`array`| An array of objects returned from `fluid` queries. When combined with `media` keys, allows for art directing `fluid` images. |
0 commit comments