Update to new design. (#1103)

This commit is contained in:
Lee Robinson
2023-07-24 21:40:29 -05:00
committed by GitHub
parent d918fcc895
commit 59fc2bc2e9
61 changed files with 1002 additions and 1247 deletions

View File

@@ -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>