Skip to content

Conversation

@benjaminsehl
Copy link
Member

@benjaminsehl benjaminsehl commented Jan 5, 2023

Replaced by Shopify/hydrogen-react#114

Demo Link: https://n5jyshg6a-f1f4fa724b7467f41f07.myshopify.dev/image-demo?shopify_employee_access=true

<Image /> now supports all unit types, both for responsive and fixed with images.

Todo:

  • Write tests
  • Write guide/docs
  • Migrate to Storefront Kit
  • Add support for Picture element (could wait until post 2.0)

Picture Element

Picture component should look something like:

 <Picture
  width="100%"
  {...props}>
  <Image 
      src={data.src} 
      aspectRatio="4/5" 
      sizes="100vw" 
      media="(min-width: 800px)" />        
  <Image 
      src={data.src} 
      aspectRatio="2/3" 
      sizes="100vw" 
      media="(min-width: 1200px)" />
</Picture>

When inside the component should render a element, the last component should render an element. Ideally we'd somehow do that automatically — looking at the nodes of children, and then setting the as prop for you. Alternatively, our component could re-export the Image component but as a <Source /> component — which would be in keeping with HTML semantics.

@benjaminsehl benjaminsehl requested a review from blittle January 5, 2023 05:16
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2023

We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset.
If the changes are user-facing and should cause a version bump, run npm run changeset add to track your changes and include them in the next release CHANGELOG.
If you are making simple updates to examples or documentation, you do not need to add a changeset.

Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

Great job Ben! 🔥
This is far better commented than any of us devs do 😂

I lack context on the Image component but here are some minor comments about the code.
Also, wondering if this component should go in hydrogen-react instead?

@blittle
Copy link
Contributor

blittle commented Jan 5, 2023

FYI @frehner, Ben and I spoke about moving this to RSK, cause there's nothing unique to Remix in it's implementation.

Copy link
Contributor

@frehner frehner left a comment

Choose a reason for hiding this comment

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

This PR may also be relevant here Shopify/hydrogen-react#103

In any case, this looks pretty good. I used responsive image lint on the example page and it brought up two issues:

Screenshot 2023-01-05 at 9 51 26 AM

I don't think that's too bad of an issue, it just means that the sizes didn't match perfectly for a 1080p screen, right? I could be wrong on that, though.

Screenshot 2023-01-05 at 9 51 30 AM

This one does seem to be a potential bug/issue we would want to look into, though. I think.


There's a lot of helper functions here, which I like. It should help ensure that you can write pretty specific tests for each one which should help raise confidence on ensuring that things are all working as expected.

It may also be helpful to go through the existing tests and see if any of them should still apply; would help us prevent regressions on edge cases that we've fixed in the past.

Looking good! 👍

? undefined
: generateSizes(widths, fixedAspectRatio, crop);

return React.createElement(Component, {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need React.createElement here, and instead can just use normal JSX with <Component/>

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh thanks — Bret actually did that part so I was just leaning on that. I can change it back to JSX though — is there a reason you did that @blittle?

src,
/*
* Supports third party loaders, which are expected to provide
* a function that can generate a URL string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this signature (src, width, height, crop) => src for these functions standard or something you are coming up with here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Standard in how Imagery works — there are even more parameters you can pass, but felt overkill. One alternative would be to change this to params which would be an object of the same options.

That might be beneficial because crop could eventually be expanded to accept an object — which Imagery accommodates.

@blittle blittle changed the base branch from v0.x-2022-10 to 2023-01 January 31, 2023 14:51
@benjaminsehl
Copy link
Member Author

Closed in favour of moving to hydrogen-react Shopify/hydrogen-react#114

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.

5 participants