-
Notifications
You must be signed in to change notification settings - Fork 401
New Image component #649
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
Closed
Closed
New Image component #649
Changes from 37 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
a52f736
New Image PR
benjaminsehl c0cfbe0
Make existing tests pass
cartogram b1110fa
Remove missing sizes warning if fixed width
benjaminsehl e33681f
Add tests for warnings and fix bug when getting normalizedWidth
cartogram ca6fa6f
Change multiline log style
cartogram 694cc48
test missing src value
cartogram e49968e
Enable restrict template literal rule
cartogram c3f102a
More tests
cartogram e6f21f9
more tests
cartogram 2039367
Pass custom loader to srcSet
cartogram daa0b59
Adds width and height prop to the image
benjaminsehl 9bf619d
Improve default width and height props on rendered HTML
benjaminsehl 0f34b1d
Only console warn in dev
benjaminsehl 3c5cb24
Intellisense improvements
benjaminsehl bd82a80
Comment out console warning tests
benjaminsehl 981ba48
Updates Demo Store images
benjaminsehl 010be7d
Adds docs and examples, updates demo store implementation
benjaminsehl 21cb8ae
Update generated docs data
benjaminsehl 2108d73
Export IMAGE_FRAGMENT from Image component
benjaminsehl 9fcc242
Merge branch '2023-01' into new-image
benjaminsehl e5e8b84
Update Demo Store
benjaminsehl a754e2b
Fix image sizing demo store
benjaminsehl 5c22196
Update product card size
benjaminsehl a812593
Update demo store, improve image srcset for fixed width
benjaminsehl 133433b
Updates tests and starting config
benjaminsehl 0975081
Add crop to placeholder image
benjaminsehl c0b539d
remove sizes from fixed width image
benjaminsehl c73adeb
adds changesets
benjaminsehl 90c4de4
fix development env only tests
cartogram 68a09c5
Fixes __HYDROGEN_DEV__
benjaminsehl 1aef9e6
Use Component notation instead of React.createElement
benjaminsehl d06c228
Tries to fix TS stuff
benjaminsehl 1ec83dd
Tries to fix TS stuff, part 2
benjaminsehl 8172bf1
Refactor
benjaminsehl 0ccc4dc
Fix checks
benjaminsehl 3956df7
Merge branch '2023-04-POC' into new-image
benjaminsehl 566ef57
Delete ImageLegacy and remove old references
benjaminsehl 4227e72
Remove test utils
benjaminsehl d001ad9
Fixes errors with test-utils
benjaminsehl 4df5c29
Static ProcessEnv type, and adds details to changeset
benjaminsehl 8f8dec7
Removes node types from devDependencies
benjaminsehl 7170955
Remove test utils
benjaminsehl d11da0a
Removes unneeded prop, updates package lock file
benjaminsehl e83d11a
Change to work off 2023-04
benjaminsehl 3b32aa8
Removes width and height as specified inline styles
benjaminsehl 6fc38a0
Updates changeset
benjaminsehl eada9a3
Update image size on demo store cart line item
benjaminsehl a648c50
PDP css fix
benjaminsehl 0a051e3
Merge branch '2023-04-POC' into new-image
lordofthecactus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@shopify/hydrogen-react': patch | ||
| --- | ||
|
|
||
| Adds an all-new responsive Image component | ||
427 changes: 305 additions & 122 deletions
427
packages/hydrogen-react/docs/generated/generated_docs_data.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,31 @@ | ||
| import {Image} from '@shopify/hydrogen-react'; | ||
| import React from 'react'; | ||
| import {Image, IMAGE_FRAGMENT} from '@shopify/hydrogen-react'; | ||
| import type {Product} from '@shopify/hydrogen-react/storefront-api-types'; | ||
|
|
||
| // An example query that includes the image fragment | ||
| const IMAGE_QUERY = `#graphql | ||
| ${IMAGE_FRAGMENT} | ||
| query { | ||
| product { | ||
| featuredImage { | ||
| ...Image | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| export default function ProductImage({product}: {product: Product}) { | ||
| const image = product.featuredImage; | ||
|
|
||
| if (!image) { | ||
| return null; | ||
| } | ||
|
|
||
| return <Image data={image} />; | ||
| return ( | ||
| <Image | ||
| data={image} | ||
| sizes="(min-width: 45em) 50vw, 100vw" | ||
| aspectRatio="4/5" | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,82 @@ | ||
| import * as React from 'react'; | ||
| import type {Story} from '@ladle/react'; | ||
| import {Image, type ShopifyImageProps} from './Image.js'; | ||
| import {IMG_SRC_SET_SIZES} from './image-size.js'; | ||
| import {Image, ShopifyLoaderOptions, LoaderParams} from './Image.js'; | ||
| import type {PartialDeep} from 'type-fest'; | ||
| import type {Image as ImageType} from './storefront-api-types.js'; | ||
|
|
||
| type Crop = 'center' | 'top' | 'bottom' | 'left' | 'right'; | ||
|
|
||
| type ImageConfig = { | ||
| intervals: number; | ||
| startingWidth: number; | ||
| incrementSize: number; | ||
| placeholderWidth: number; | ||
| }; | ||
|
|
||
| type HtmlImageProps = React.ImgHTMLAttributes<HTMLImageElement>; | ||
|
|
||
| const Template: Story<{ | ||
| 'data.url': ShopifyImageProps['data']['url']; | ||
| 'data.width': ShopifyImageProps['data']['width']; | ||
| 'data.height': ShopifyImageProps['data']['height']; | ||
| width: ShopifyImageProps['width']; | ||
| height: ShopifyImageProps['height']; | ||
| widths: ShopifyImageProps['widths']; | ||
| loaderOptions: ShopifyImageProps['loaderOptions']; | ||
| as?: 'img' | 'source'; | ||
| data?: PartialDeep<ImageType, {recurseIntoArrays: true}>; | ||
| loader?: (params: LoaderParams) => string; | ||
| src: string; | ||
| width?: string | number; | ||
| height?: string | number; | ||
| crop?: Crop; | ||
| sizes?: string; | ||
| aspectRatio?: string; | ||
| config?: ImageConfig; | ||
| alt?: string; | ||
| loading?: 'lazy' | 'eager'; | ||
| loaderOptions?: ShopifyLoaderOptions; | ||
| widths?: (HtmlImageProps['width'] | ImageType['width'])[]; | ||
| }> = (props) => { | ||
| const finalProps: ShopifyImageProps = { | ||
| data: { | ||
| url: props['data.url'], | ||
| width: props['data.width'], | ||
| height: props['data.height'], | ||
| id: 'testing', | ||
| }, | ||
| width: props.width, | ||
| height: props.height, | ||
| widths: props.widths, | ||
| loaderOptions: props.loaderOptions, | ||
| }; | ||
| return <Image {...finalProps} />; | ||
| return ( | ||
| <> | ||
| {/* Standard Usage */} | ||
| <Image | ||
| {...props} | ||
| width="100%" | ||
| loading="eager" | ||
| aspectRatio="1/1" | ||
| sizes="100vw" | ||
| /> | ||
| {/* */} | ||
| <Image | ||
| {...props} | ||
| src="https://cdn.shopify.com/s/files/1/0551/4566/0472/products/Main.jpg" | ||
| width="100%" | ||
| aspectRatio="1/1" | ||
| sizes="100vw" | ||
| /> | ||
| <Image {...props} sizes="50vw" width="50vw" /> | ||
| <Image {...props} aspectRatio="4/3" width="50vw" sizes="50vw" /> | ||
| <Image {...props} width="30vw" sizes="30vw" /> | ||
| <Image {...props} width={100} height={200} /> | ||
| <Image {...props} width="5rem" /> | ||
| <Image {...props} widths={[100, 200, 300]} /> | ||
| <Image | ||
| {...props} | ||
| loaderOptions={{ | ||
| crop: 'center', | ||
| }} | ||
| widths={[200, 300]} | ||
| /> | ||
| <Image | ||
| sizes="100vw" | ||
| src="https://cdn.shopify.com/s/files/1/0551/4566/0472/products/Main.jpg" | ||
| widths={[100, 200, 300]} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export const Default = Template.bind({}); | ||
| Default.args = { | ||
| 'data.url': | ||
| 'https://cdn.shopify.com/s/files/1/0551/4566/0472/products/Main.jpg', | ||
| 'data.width': 100, | ||
| 'data.height': 100, | ||
| width: 500, | ||
| height: 500, | ||
| widths: IMG_SRC_SET_SIZES, | ||
| loaderOptions: { | ||
| crop: 'center', | ||
| scale: 2, | ||
| width: 500, | ||
| height: 500, | ||
| data: { | ||
| url: 'https://cdn.shopify.com/s/files/1/0551/4566/0472/products/Main.jpg', | ||
| altText: 'alt text', | ||
| width: 3908, | ||
| height: 3908, | ||
| }, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.