Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
experimenting view transition
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-phan committed Jan 12, 2024
1 parent 4139796 commit 40e3934
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
7 changes: 1 addition & 6 deletions app/components/FeaturedProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ function FeatureProductsContent({
return (
<>
{products.map((product) => (
<ProductCard
product={product}
key={product.id}
onClick={onClick}
quickAdd
/>
<ProductCard product={product} key={product.id} quickAdd />
))}
</>
);
Expand Down
16 changes: 14 additions & 2 deletions app/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ export function Link(props: LinkProps) {

if (typeof className === 'function') {
return (
<RemixNavLink to={toWithLocale} className={className} {...resOfProps} />
<RemixNavLink
unstable_viewTransition
to={toWithLocale}
className={className}
{...resOfProps}
/>
);
}

return <RemixLink to={toWithLocale} className={className} {...resOfProps} />;
return (
<RemixLink
unstable_viewTransition
to={toWithLocale}
className={className}
{...resOfProps}
/>
);
}
5 changes: 4 additions & 1 deletion app/components/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export function ProductCard({
return (
<div className="flex flex-col gap-2">
<Link
onClick={onClick}
// onClick={onClick}
to={`/products/${product.handle}`}
prefetch="intent"
className={({isTransitioning}) => {
return isTransitioning ? 'vt-product-image' : '';
}}
>
<div className={clsx('grid gap-4', className)}>
<div className="card-image aspect-[4/5] bg-primary/5">
Expand Down
6 changes: 5 additions & 1 deletion app/components/ProductGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Image} from '@shopify/hydrogen';

import type {MediaFragment} from 'storefrontapi.generated';
import clsx from 'clsx';

/**
* A client component that defines a media gallery for hosting images, 3D models, and videos of products
Expand Down Expand Up @@ -48,7 +49,10 @@ export function ProductGallery({
? '(min-width: 48em) 60vw, 90vw'
: '(min-width: 48em) 30vw, 90vw'
}
className="object-cover w-full h-full aspect-square fadeIn"
className={clsx(
'object-cover w-full h-full aspect-square',
i === 0 ? 'vt-product-image' : '',
)}
/>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/routes/($locale).products.$productHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export async function loader({params, request, context}: RouteLoaderArgs) {
throw new Response('product', {status: 404});
}

if (!product.selectedVariant) {
throw redirectToFirstVariant({product, request});
}
// if (!product.selectedVariant) {
// throw redirectToFirstVariant({product, request});
// }

// In order to show which variants are available in the UI, we need to query
// all of them. But there might be a *lot*, so instead separate the variants
Expand Down
4 changes: 2 additions & 2 deletions app/sections/product-information/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ let ProductInformation = forwardRef<HTMLDivElement, ProductInformationProps>(
gallerySize === 'small'
? 'large'
: gallerySize === 'large'
? 'small'
: 'medium'
? 'small'
: 'medium'
],
)}
>
Expand Down
4 changes: 4 additions & 0 deletions app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@
transform-origin: top left;
}
}

.vt-product-image {
view-transition-name: product-image;
}

0 comments on commit 40e3934

Please sign in to comment.