mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Update to new design. (#1103)
This commit is contained in:
@@ -1,92 +1,77 @@
|
||||
'use client';
|
||||
|
||||
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline';
|
||||
import { GridTileImage } from 'components/grid/tile';
|
||||
import Image from 'next/image';
|
||||
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);
|
||||
export function Gallery({ images }: { images: { src: string; altText: string }[] }) {
|
||||
const [currentImageIndex, setCurrentImageIndex] = useState(0);
|
||||
|
||||
function handleNavigate(direction: 'next' | 'previous') {
|
||||
if (direction === 'next') {
|
||||
setCurrentImage(currentImage + 1 < images.length ? currentImage + 1 : 0);
|
||||
setCurrentImageIndex(currentImageIndex + 1 < images.length ? currentImageIndex + 1 : 0);
|
||||
} else {
|
||||
setCurrentImage(currentImage === 0 ? images.length - 1 : currentImage - 1);
|
||||
setCurrentImageIndex(currentImageIndex === 0 ? images.length - 1 : currentImageIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
const buttonClassName =
|
||||
'px-9 cursor-pointer ease-in-and-out duration-200 transition-bg bg-[#7928ca] hover:bg-violetDark';
|
||||
'h-full px-6 transition-all ease-in-out hover:scale-110 hover:text-black dark:hover:text-white';
|
||||
|
||||
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}
|
||||
<div className="mr-8 h-full">
|
||||
<div className="relative mb-12 h-full max-h-[550px] overflow-hidden">
|
||||
{images[currentImageIndex] && (
|
||||
<Image
|
||||
className="relative h-full w-full object-contain"
|
||||
height={600}
|
||||
isInteractive={false}
|
||||
width={600}
|
||||
alt={images[currentImageIndex]?.altText as string}
|
||||
src={images[currentImageIndex]?.src as string}
|
||||
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 className="absolute bottom-[15%] flex w-full justify-center">
|
||||
<div className="mx-auto flex h-11 items-center rounded-full border border-white bg-neutral-50/80 text-neutral-500 backdrop-blur dark:border-black dark:bg-neutral-900/80">
|
||||
<button
|
||||
aria-label="Previous product image"
|
||||
onClick={() => handleNavigate('previous')}
|
||||
className={buttonClassName}
|
||||
>
|
||||
<ArrowLeftIcon className="h-5" />
|
||||
</button>
|
||||
<div className="mx-1 h-6 w-px bg-neutral-500"></div>
|
||||
<button
|
||||
aria-label="Next product image"
|
||||
onClick={() => handleNavigate('next')}
|
||||
className={buttonClassName}
|
||||
>
|
||||
<ArrowRightIcon className="h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{images.length > 1 ? (
|
||||
<div className="flex">
|
||||
<div className="flex items-center justify-center gap-2 overflow-auto py-1">
|
||||
{images.map((image, index) => {
|
||||
const isActive = index === currentImage;
|
||||
const isActive = index === currentImageIndex;
|
||||
return (
|
||||
<button
|
||||
aria-label="Enlarge product image"
|
||||
key={image.src}
|
||||
className="h-full w-1/4"
|
||||
onClick={() => setCurrentImage(index)}
|
||||
className="h-auto w-20"
|
||||
onClick={() => setCurrentImageIndex(index)}
|
||||
>
|
||||
<GridTileImage
|
||||
alt={image?.altText}
|
||||
alt={image.altText}
|
||||
src={image.src}
|
||||
width={600}
|
||||
height={600}
|
||||
background="purple-dark"
|
||||
active={isActive}
|
||||
/>
|
||||
</button>
|
||||
|
31
components/product/product-description.tsx
Normal file
31
components/product/product-description.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { AddToCart } from 'components/cart/add-to-cart';
|
||||
import Price from 'components/price';
|
||||
import Prose from 'components/prose';
|
||||
import { Product } from 'lib/shopify/types';
|
||||
import { VariantSelector } from './variant-selector';
|
||||
|
||||
export function ProductDescription({ product }: { product: Product }) {
|
||||
return (
|
||||
<>
|
||||
<div className="mb-6 flex flex-col border-b pb-6 dark:border-neutral-700">
|
||||
<h1 className="mb-2 text-5xl font-medium">{product.title}</h1>
|
||||
<div className="mr-auto w-auto rounded-full bg-blue-600 p-2 text-sm text-white">
|
||||
<Price
|
||||
amount={product.priceRange.maxVariantPrice.amount}
|
||||
currencyCode={product.priceRange.maxVariantPrice.currencyCode}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<VariantSelector options={product.options} variants={product.variants} />
|
||||
|
||||
{product.descriptionHtml ? (
|
||||
<Prose
|
||||
className="mb-6 text-sm leading-tight dark:text-white/[60%]"
|
||||
html={product.descriptionHtml}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<AddToCart variants={product.variants} availableForSale={product.availableForSale} />
|
||||
</>
|
||||
);
|
||||
}
|
@@ -114,16 +114,15 @@ export function VariantSelector({
|
||||
href={optionUrl}
|
||||
title={`${option.name} ${value}${!isAvailableForSale ? ' (Out of Stock)' : ''}`}
|
||||
className={clsx(
|
||||
'flex h-12 min-w-[48px] items-center justify-center rounded-full px-2 text-sm',
|
||||
'flex min-w-[48px] items-center justify-center rounded-full border bg-neutral-100 px-2 py-1 text-sm dark:border-neutral-900 dark:bg-neutral-900',
|
||||
{
|
||||
'cursor-default ring-2 ring-black dark:ring-white': isActive,
|
||||
'ring-1 ring-gray-300 transition duration-300 ease-in-out hover:scale-110 hover:bg-gray-100 hover:ring-black dark:ring-gray-700 dark:hover:bg-transparent dark:hover:ring-white':
|
||||
'cursor-default ring-2 ring-blue-600': isActive,
|
||||
'ring-1 ring-transparent transition duration-300 ease-in-out hover:scale-110 hover:ring-blue-600 ':
|
||||
!isActive && isAvailableForSale,
|
||||
'relative z-10 cursor-not-allowed overflow-hidden bg-gray-100 ring-1 ring-gray-300 before:absolute before:inset-x-0 before:-z-10 before:h-px before:-rotate-45 before:bg-gray-300 before:transition-transform dark:bg-gray-900 dark:ring-gray-700 before:dark:bg-gray-700':
|
||||
'relative z-10 cursor-not-allowed overflow-hidden bg-neutral-100 text-neutral-400 ring-1 ring-neutral-300 before:absolute before:inset-x-0 before:-z-10 before:h-px before:-rotate-45 before:bg-neutral-300 before:transition-transform dark:bg-neutral-900 dark:text-neutral-600 dark:ring-neutral-700 before:dark:bg-neutral-700':
|
||||
!isAvailableForSale
|
||||
}
|
||||
)}
|
||||
data-testid={isActive ? 'selected-variant' : 'variant'}
|
||||
>
|
||||
{value}
|
||||
</DynamicTag>
|
||||
|
Reference in New Issue
Block a user