Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a52f736
New Image PR
benjaminsehl Mar 6, 2023
c0cfbe0
Make existing tests pass
cartogram Mar 7, 2023
b1110fa
Remove missing sizes warning if fixed width
benjaminsehl Mar 7, 2023
e33681f
Add tests for warnings and fix bug when getting normalizedWidth
cartogram Mar 7, 2023
ca6fa6f
Change multiline log style
cartogram Mar 7, 2023
694cc48
test missing src value
cartogram Mar 8, 2023
e49968e
Enable restrict template literal rule
cartogram Mar 9, 2023
c3f102a
More tests
cartogram Mar 9, 2023
e6f21f9
more tests
cartogram Mar 9, 2023
2039367
Pass custom loader to srcSet
cartogram Mar 13, 2023
daa0b59
Adds width and height prop to the image
benjaminsehl Mar 13, 2023
9bf619d
Improve default width and height props on rendered HTML
benjaminsehl Mar 13, 2023
0f34b1d
Only console warn in dev
benjaminsehl Mar 13, 2023
3c5cb24
Intellisense improvements
benjaminsehl Mar 13, 2023
bd82a80
Comment out console warning tests
benjaminsehl Mar 13, 2023
981ba48
Updates Demo Store images
benjaminsehl Mar 13, 2023
010be7d
Adds docs and examples, updates demo store implementation
benjaminsehl Mar 14, 2023
21cb8ae
Update generated docs data
benjaminsehl Mar 14, 2023
2108d73
Export IMAGE_FRAGMENT from Image component
benjaminsehl Mar 14, 2023
9fcc242
Merge branch '2023-01' into new-image
benjaminsehl Mar 14, 2023
e5e8b84
Update Demo Store
benjaminsehl Mar 14, 2023
a754e2b
Fix image sizing demo store
benjaminsehl Mar 14, 2023
5c22196
Update product card size
benjaminsehl Mar 14, 2023
a812593
Update demo store, improve image srcset for fixed width
benjaminsehl Mar 14, 2023
133433b
Updates tests and starting config
benjaminsehl Mar 14, 2023
0975081
Add crop to placeholder image
benjaminsehl Mar 14, 2023
c0b539d
remove sizes from fixed width image
benjaminsehl Mar 14, 2023
c73adeb
adds changesets
benjaminsehl Mar 14, 2023
90c4de4
fix development env only tests
cartogram Mar 14, 2023
68a09c5
Fixes __HYDROGEN_DEV__
benjaminsehl Mar 15, 2023
1aef9e6
Use Component notation instead of React.createElement
benjaminsehl Mar 15, 2023
d06c228
Tries to fix TS stuff
benjaminsehl Mar 15, 2023
1ec83dd
Tries to fix TS stuff, part 2
benjaminsehl Mar 16, 2023
8172bf1
Refactor
benjaminsehl Mar 17, 2023
0ccc4dc
Fix checks
benjaminsehl Mar 17, 2023
3956df7
Merge branch '2023-04-POC' into new-image
benjaminsehl Apr 6, 2023
566ef57
Delete ImageLegacy and remove old references
benjaminsehl Apr 6, 2023
4227e72
Remove test utils
benjaminsehl Apr 12, 2023
d001ad9
Fixes errors with test-utils
benjaminsehl Apr 12, 2023
4df5c29
Static ProcessEnv type, and adds details to changeset
benjaminsehl Apr 12, 2023
8f8dec7
Removes node types from devDependencies
benjaminsehl Apr 12, 2023
7170955
Remove test utils
benjaminsehl Apr 12, 2023
d11da0a
Removes unneeded prop, updates package lock file
benjaminsehl Apr 12, 2023
e83d11a
Change to work off 2023-04
benjaminsehl Apr 12, 2023
3b32aa8
Removes width and height as specified inline styles
benjaminsehl Apr 12, 2023
6fc38a0
Updates changeset
benjaminsehl Apr 12, 2023
eada9a3
Update image size on demo store cart line item
benjaminsehl Apr 12, 2023
a648c50
PDP css fix
benjaminsehl Apr 12, 2023
0a051e3
Merge branch '2023-04-POC' into new-image
lordofthecactus Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/ExternalVideo.test.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PartialDeep} from 'type-fest';
import type {ExternalVideo as ExternalVideoType} from './storefront-api-types.js';
import {faker} from '@faker-js/faker';
import {getPreviewImage} from './Image.test.helpers.js';
import {getPreviewImage} from './ImageLegacy.test.helpers.js';

export function getExternalVideoData(
externalVideo: Partial<ExternalVideoType> = {},
Expand Down
100 changes: 66 additions & 34 deletions packages/hydrogen-react/src/Image.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,77 @@
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, ShopifyLoaderParams} 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: ShopifyLoaderParams) => 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]}
/>
</>
);
};

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,
},
};
Loading