mirror of
https://github.com/vercel/commerce.git
synced 2025-04-27 21:37:50 +00:00
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { getCollectionProducts } from "lib/store/products";
|
|
import { getImageUrl } from "lib/utils/image";
|
|
import Link from "next/link";
|
|
import { GridTileImage } from "./grid/tile";
|
|
|
|
export async function Carousel() {
|
|
// Collections that start with `hidden-*` are hidden from the search page.
|
|
const products = await getCollectionProducts({
|
|
collection: "hidden-homepage-carousel",
|
|
});
|
|
|
|
if (!products?.length) return null;
|
|
|
|
// Purposefully duplicating products to make the carousel loop and not run out of products on wide screens.
|
|
const carouselProducts = [...products, ...products, ...products];
|
|
|
|
return (
|
|
<div className="w-full overflow-x-auto pb-6 pt-1">
|
|
<ul className="flex animate-carousel gap-4">
|
|
{carouselProducts.map((product, i) => (
|
|
<li
|
|
key={`${product.handle}${i}`}
|
|
className="relative aspect-square h-[30vh] max-h-[275px] w-2/3 max-w-[475px] flex-none md:w-1/3"
|
|
>
|
|
<Link
|
|
href={`/product/${product.handle}`}
|
|
className="relative h-full w-full"
|
|
>
|
|
<GridTileImage
|
|
alt={product.title}
|
|
label={{
|
|
title: product.title,
|
|
amount: product.priceRange.maxVariantPrice.amount,
|
|
currencyCode: product.priceRange.maxVariantPrice.currencyCode,
|
|
}}
|
|
src={
|
|
product.featuredImage
|
|
? getImageUrl(product.featuredImage.source)
|
|
: ""
|
|
}
|
|
fill
|
|
sizes="(min-width: 1024px) 25vw, (min-width: 768px) 33vw, 50vw"
|
|
/>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|