mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 08:15:54 +00:00
We're making some updates to Next.js Commerce. Everything prior to this commit marks what we're calling [`v1`](https://github.com/vercel/commerce/releases/tag/v1) as a point in time to be able to reference and still use going into the future. The current architecture of Commerce is a multi-vendor, interoperable solution, including:
- [Shopify](https://shopify.vercel.store/)
- [Swell](https://swell.vercel.store/)
- [BigCommerce](https://bigcommerce.vercel.store/)
- [Vendure](https://vendure.vercel.store/)
- [Saleor](https://saleor.vercel.store/)
- [Ordercloud](https://ordercloud.vercel.store/)
- [Spree](https://spree.vercel.store/)
- [Kibo Commerce](https://kibocommerce.vercel.store/)
- [Commerce.js](https://commercejs.vercel.store/)
- [SalesForce Cloud Commerce](https://salesforce-cloud-commerce.vercel.store/)
All features can be toggled on or off, and it's easy to change between commerce providers. To support this, we needed to create a ["commerce metaframework"](d1d9e8c434/packages/commerce/new-provider.md
) where providers could confirm to an API spec to add support for Next.js Commerce. While this worked and was successful for `v1`, we have different design goals and ambitions for `v2`.
**What You Need To Know**
- `v1` will not be updated moving forward. If you need to reference `v1`, you will still be able to clone and deploy the version tagged at this release.
- `v2` will be shifting to be a single provider vs. provider agnostic. Other providers are welcome to fork this repository and swap out the underlying `lib/` implementation that connects to the selected commerce provider (Shopify). This architecture was chosen to reduce the surface area of the codebase, remove the intermediate metaframework layer for provider-interoperability, and enable usage with the latest Next.js and React features.
- We will be sharing more about `v2` in the future as we continue to iterate before the marked release.
100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import clsx from 'clsx';
|
|
import { GridTileImage } from 'components/grid/tile';
|
|
import ArrowLeftIcon from 'components/icons/arrow-left';
|
|
|
|
export function Gallery({
|
|
title,
|
|
amount,
|
|
currencyCode,
|
|
images
|
|
}: {
|
|
title: string;
|
|
amount: string;
|
|
currencyCode: string;
|
|
images: { src: string; altText: string }[];
|
|
}) {
|
|
const [currentImage, setCurrentImage] = useState(0);
|
|
|
|
function handleNavigate(direction: 'next' | 'previous') {
|
|
if (direction === 'next') {
|
|
setCurrentImage(currentImage + 1 < images.length ? currentImage + 1 : 0);
|
|
} else {
|
|
setCurrentImage(currentImage === 0 ? images.length - 1 : currentImage - 1);
|
|
}
|
|
}
|
|
|
|
const buttonClassName =
|
|
'px-9 cursor-pointer ease-in-and-out duration-200 transition-bg bg-[#7928ca] hover:bg-violetDark';
|
|
|
|
return (
|
|
<div className="h-full">
|
|
<div className="relative h-full max-h-[600px] overflow-hidden">
|
|
{images[currentImage] && (
|
|
<GridTileImage
|
|
src={images[currentImage]?.src as string}
|
|
alt={images[currentImage]?.altText as string}
|
|
width={600}
|
|
height={600}
|
|
isInteractive={false}
|
|
priority={true}
|
|
background="purple"
|
|
labels={{
|
|
title,
|
|
amount,
|
|
currencyCode
|
|
}}
|
|
/>
|
|
)}
|
|
|
|
{images.length > 1 ? (
|
|
<div className="absolute bottom-10 right-10 flex h-12 flex-row border border-white text-white shadow-xl dark:border-black dark:text-black">
|
|
<button
|
|
aria-label="Previous product image"
|
|
className={clsx(buttonClassName, 'border-r border-white dark:border-black')}
|
|
onClick={() => handleNavigate('previous')}
|
|
>
|
|
<ArrowLeftIcon className="h-6" />
|
|
</button>
|
|
<button
|
|
aria-label="Next product image"
|
|
className={clsx(buttonClassName)}
|
|
onClick={() => handleNavigate('next')}
|
|
>
|
|
<ArrowLeftIcon className="h-6 rotate-180" />
|
|
</button>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
|
|
{images.length > 1 ? (
|
|
<div className="flex">
|
|
{images.map((image, index) => {
|
|
const isActive = index === currentImage;
|
|
return (
|
|
<button
|
|
aria-label="Enlarge product image"
|
|
key={image.src}
|
|
className="h-full w-1/4"
|
|
onClick={() => setCurrentImage(index)}
|
|
>
|
|
<GridTileImage
|
|
alt={image.altText}
|
|
src={image.src}
|
|
width={600}
|
|
height={600}
|
|
background="purple-dark"
|
|
active={isActive}
|
|
/>
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|