Skip to content
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 responsive image component #12381

Merged
merged 39 commits into from
Nov 11, 2024
Merged

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Nov 5, 2024

Changes

Adds support for a new layout prop to the image component, which triggers auto-generation of the srcset and sizes, and applies styles to make it resize correctly. The behaviour is behind an experimental flag.

Also adds the new props fit (for object fit), postion (for object-position) and priority (which disables lazy loading etc). See the latest version of the RFC for details.

This PR refactors a lot of the srcset-generating logic, but does not change the external API. Future PRs will implement cropping in the image service. It also does not include Picture tag support yet.

Testing

Adds a new test suite and fixture.

Docs

Copy link

changeset-bot bot commented Nov 5, 2024

⚠️ No Changeset found

Latest commit: e538c34

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Nov 5, 2024
Base automatically changed from resp-img-config to responsive-images November 6, 2024 06:58
@github-actions github-actions bot removed the docs pr label Nov 6, 2024
@ascorbic ascorbic changed the title wip: responsive image component feat: add responsive image component Nov 8, 2024
@ascorbic ascorbic marked this pull request as ready for review November 8, 2024 15:02
@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Nov 11, 2024
packages/astro/src/assets/internal.ts Show resolved Hide resolved
packages/astro/src/assets/layout.ts Show resolved Hide resolved
packages/astro/src/assets/layout.ts Outdated Show resolved Hide resolved
packages/astro/src/assets/layout.ts Outdated Show resolved Hide resolved
packages/astro/src/assets/layout.ts Outdated Show resolved Hide resolved
packages/astro/src/assets/layout.ts Show resolved Hide resolved
packages/astro/test/core-image-layout.test.js Show resolved Hide resolved
@ascorbic ascorbic merged commit e4a9c35 into responsive-images Nov 11, 2024
14 checks passed
@ascorbic ascorbic deleted the resp-img-component branch November 11, 2024 11:46
ascorbic added a commit that referenced this pull request Nov 15, 2024
* chore: changeset

* feat: add experimental responsive images config option (#12378)

* feat: add experimental responsive images config option

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update config types

* Move config into `images`

* Move jsdocs

---------

Co-authored-by: Sarah Rainsberger <[email protected]>

* feat: add responsive image component (#12381)

* feat: add experimental responsive images config option

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update config types

* Move config into `images`

* Move jsdocs

* wip: responsive image component

* Improve srcset logic

* Improve fixture

* Lock

* Update styling

* Fix style prop handling

* Update test (there's an extra style for images now)

* Safely access the src props

* Remove unused export

* Handle priority images

* Consolidate styles

* Update tests

* Comment

* Refactor srcset

* Avoid dupes of original image

* Calculate missing dimensions

* Bugfixes

* Add tests

* Fix test

* Correct order

* Lint

* Fix fspath

* Update test

* Fix test

* Conditional component per flag

* Fix class concatenation

* Remove logger

* Rename helper

* Add comments

* Format

* Fix markdoc tests

* Add test for style tag

---------

Co-authored-by: Sarah Rainsberger <[email protected]>

* feat: add crop support to image services (#12414)

* wip: add crop support to image services

* Add tests

* Strip crop attributes

* Don't upscale

* Format

* Get build working properly

* Changes from review

* Fix jsdoc

* feat: add responsive support to picture component (#12423)

* feat: add responsive support to picture component

* Add picture tests

* Fix test

* Implement own define vars

* Share logic

* Prevent extra astro-* class

* Use dataset scoping

* Revert unit test

* Revert "Fix test"

This reverts commit f9ec6e2.

* Changes from review

* docs: add docs for responsive images (#12429)

* docs: add responsive images flag docs

* docs: adds jsdoc for image components

* chore: updates from review

* Fix jsdoc

* Changes from review

* Add breakpoints option

* typo

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants