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 asImageSrc, asImageWidthSrcSet, asImagePixelDensitySrcSet #38

Merged
merged 33 commits into from
Feb 1, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Jan 22, 2022

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds the following image helpers:

  • asImageSrc: Converts an Image field to an image URL with optional image transformations (via Imgix).
  • asImageWidthSrcSet: Converts an Image field to a width-based srcset string.
  • asImagePixelDensitySrcSet: Converts an Image field to a pixel-density-based srcset string.

For more background on the need for and implementation of these helpers, see #37.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🐮

@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2022

Codecov Report

Merging #38 (3b66b0a) into master (915af37) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #38   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        13    +3     
  Lines          154       188   +34     
  Branches        30        39    +9     
=========================================
+ Hits           154       188   +34     
Impacted Files Coverage Δ
src/asImagePixelDensitySrcSet.ts 100.00% <100.00%> (ø)
src/asImageSrc.ts 100.00% <100.00%> (ø)
src/asImageWidthSrcSet.ts 100.00% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 915af37...3b66b0a. Read the comment docs.

@angeloashmore angeloashmore changed the title feat: add asImageSrc, asImageWidthSrcSet, asImagePixelDensitiesSrcSet feat: add asImageSrc, asImageWidthSrcSet, asImagePixelDensitySrcSet Jan 22, 2022
@angeloashmore angeloashmore marked this pull request as draft January 22, 2022 03:10
@angeloashmore angeloashmore marked this pull request as ready for review January 26, 2022 22:35
@github-actions
Copy link

github-actions bot commented Jan 26, 2022

size-limit report 📦

Path Size
dist/index.js 3.07 KB (+15.36% 🔺)
dist/index.cjs 3.57 KB (+18.8% 🔺)

Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very good! Some questions / minor stuff but feel free to proceed beyond ☺️ + yeah AVA 4 snapshots are broken for me :/

field: Field,
params: ImgixURLParams = {},
): AsImageSrcReturnType<Field> => {
if (isImageThumbnailFilled(field)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note but we should at some point update the other helpers to use those isFilled() functions too, great move!

src/asImageWidthSrcSet.ts Outdated Show resolved Hide resolved
test/asImagePixelDensitySrcSet.test.ts Outdated Show resolved Hide resolved
test/asImageWidthSrcSet.test.ts Show resolved Hide resolved
src/asImageWidthSrcSet.ts Show resolved Hide resolved
src/asImageWidthSrcSet.ts Show resolved Hide resolved
@angeloashmore
Copy link
Member Author

@lihbr The PR has been updated per your review. Could you take a look at the two remaining comments?

(Excuse the messy commit log. We'll squash this one. I was having trouble getting AVA 4 working and ended up reverting to AVA 3 instead… :/)

@lihbr
Copy link
Member

lihbr commented Jan 29, 2022

No worries ^^ Happens to me everyday~

Looking sharp! Let's just trim down the responsive sizes to the list of 5 and we're good :)

@angeloashmore angeloashmore merged commit 2b4984a into master Feb 1, 2022
@angeloashmore angeloashmore deleted the aa/image-helpers branch February 1, 2022 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants