-
Notifications
You must be signed in to change notification settings - Fork 326
Image rework #1271
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
Image rework #1271
Conversation
| lib: ['ESNext', 'DOM'], | ||
| target: 'es6', | ||
| }, | ||
| tsconfig: './packages/hydrogen/tsconfig.json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the weird ts-jest issues but I don't know if it has other side effects or not??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shall see!
mcvinci
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this, @frehner! I added a few suggestions throughout to align the code comments with the new descriptions in the reference doc.
| | height | <code>height</code> | The integer value for the height of the image. This is a required prop when `src` is present. | | ||
| | loader? | <code>(props: ImageLoaderOptions): string</code> | A custom function that generates the image URL. Parameters passed into this function includes `src` and an `options` object that contains the provided `width`, `height` and `loaderOptions` values. | | ||
| | loaderOptions? | <code>ImageLoaderOptions['options']</code> | An object of `loader` function options. For example, if the `loader` function requires a `scale` option, then the value can be a property of the `loaderOptions` object (for example, `{scale: 2}`). | | ||
| | priority? | <code>boolean</code> | Whether the image will be immediately loaded. Defaults to `false`. This prop should be used only when the image is visible above the fold. For more information, refer to the [Image Embed element's loading attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading). | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should priority? be retained?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope it's gone
| | `height` | A string of the pixel height (for example, `100px`) or `original` for the original height of the image. | | ||
| | `crop` | Valid values: `top`, `bottom`, `left`, `right`, or `center`. | | ||
| | `scale` | Valid values: 2 or 3. | | ||
| | `format` | Valid values: `jpg` or `pjpg`. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double-checking! Is this no longer an option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
jplhomer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terrific work, Anthony!
|
|
||
| it('renders an `img` element without `width` and `height` attributes when invalid dimensions are provided', () => { | ||
| // eslint-disable-next-line jest/no-focused-tests | ||
| it.only('renders an `img` element without `width` and `height` attributes when invalid dimensions are provided', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heads-up: looks like we need to remove it.only here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops nice catch!
| width && newUrl.searchParams.append('width', width.toString()); | ||
| height && newUrl.searchParams.append('height', height.toString()); | ||
| crop && newUrl.searchParams.append('crop', crop); | ||
| scale && newUrl.searchParams.append('scale', scale.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so nice!
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
Also cleaned up other tests from outputting to the console. Updated migration docs a tiny bit
|
@mcvinci just did a small documentation update, you can more easily see the changes I made by looking at this specific commit Fixed the tests, and also mocked out console.log / console.error stuff that was polluting our test output. Once tests pass, I'll merge. |
Description
Closes #1223 and massively reworks the internal implementation of the Image component
Removes
useImageUrlin favor of just calling the functionshopifyImageLoader- it's actually probably faster / better, and it can also be run on the client and the server, unlikeuseImageUrlwhich can only be run on the client.imageLoadernow takes in an object instead of positional params, which makes it easy to only use what you care to use and skip the rest.The TypeScript experience is improved; if you're using the
dataprop, you're using a SFAPI source and so theloaderandloaderOptionswill be typed for that. If you're using thesrcprop, we use a generic to infer the props you pass in toloaderOptionsand apply that to theloaderparam. Also, when usingsrc,widthandheightare required props.Hopefully cleaned up some side effects in the Image tests that weren't being cleaned up before, but I'm still running into
ts-jestissues that I can't figure out.<Video/>propsoptionsturns intoimagePreviewOptionsto be more explicit what the options are for.addImageSizeParametersToUrlfunction refactored to just use URL's.searchParams.appendto make the logic much easier.Despite the recent change to add the
priorityprop in #1245 , I decided it didn't make sense to essentially rename what is already a standardized HTML attribute, so I removedpriorityand changed the logic to makeloadingthe source of truth.Additional context
Todos before this is ready:
ts-jestis having issues parsing some testsBefore submitting the PR, please make sure you do the following:
fixes #123)yarn changeset addif this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning