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

STRF-8622 Add helper for generating a 1x/2x srcset for store logo #149

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

bookernath
Copy link
Contributor

@bookernath bookernath commented Oct 21, 2021

What? Why?

Add a helper to make it easy to generate 1x/2x srcsets for images that have stored dimensions.

The specific reason for creating this is to allow the store logo to look good even when it has been given an explicit pixel size; we can separate CSS pixel size from inherent pixel sizing easily with this helper.

Given an input like:

{{getImageSrcset1x2x image_with_dimensions "123x456"}}
and a StencilImage with dimensions like this:

image_with_dimensions: {
    data: "https://cdn.example.com/path/to/{:size}/image.png?c=2",
    width: 1400,
    height: 950,
}

It will produce a srcset value string like this: https://cdn.example.com/path/to/123x456/image.png?c=2 1x, https://cdn.example.com/path/to/246x912/image.png?c=2 2x

It can also create the best-possible version if the image is not big enough to support 2x, such as:

{{getImageSrcset1x2x image_with_dimensions "123x556"}}
https://cdn.example.com/path/to/123x556/image.png?c=2 1x, https://cdn.example.com/path/to/210x950/image.png?c=2 1.7086x which is still a valid srcset.

How was it tested?


Unit tests.

cc @bigcommerce/storefront-team

Copy link
Contributor

@jairo-bc jairo-bc left a comment

Choose a reason for hiding this comment

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

Overall logic looks good to me. Left few suggestions on code changes

@bookernath
Copy link
Contributor Author

@jairo-bc I've addressed your feedback, can you re-review? ♻️

@bookernath
Copy link
Contributor Author

FYI @bigcommerce/dev-docs

@bookernath bookernath changed the title Add helper for generating a 1x/2x srcset for store logo STRF-8622 Add helper for generating a 1x/2x srcset for store logo Oct 22, 2021
@jairo-bc jairo-bc merged commit 2c86343 into bigcommerce:master Oct 22, 2021
@bookernath bookernath deleted the srcset1x2x branch October 22, 2021 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants