mirror of
https://github.com/vercel/commerce.git
synced 2025-06-27 17:01:21 +00:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { Product } from 'lib/woocomerce/models/product';
|
|
import { woocommerce } from 'lib/woocomerce/woocommerce';
|
|
import Link from 'next/link';
|
|
import { GridTileImage } from './grid/tile';
|
|
|
|
export async function Carousel() {
|
|
const products: Product[] = await woocommerce.get('products', { author: 1 });
|
|
|
|
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.id}${i}`}
|
|
className="relative aspect-square h-[60vh] max-h-[359px] w-2/3 max-w-[475px] flex-none md:w-1/3"
|
|
>
|
|
<Link href={`/product/${product.slug}`} className="relative h-full w-full">
|
|
<GridTileImage
|
|
alt={product.name}
|
|
label={{
|
|
title: product.name,
|
|
amount: product.price,
|
|
currencyCode: 'EUR'
|
|
}}
|
|
src={product.images?.[0]?.src || ''}
|
|
fill
|
|
sizes="(min-width: 1024px) 25vw, (min-width: 768px) 33vw, 50vw"
|
|
/>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|