mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 22:16:58 +00:00
finish dark/light modes, add related product section, fix label pill spacing
This commit is contained in:
parent
5da9b4785b
commit
39740e4d9c
@ -2,14 +2,14 @@ import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import Grid from 'components/grid';
|
||||
import { GridTileImage } from 'components/grid/tile';
|
||||
import Footer from 'components/layout/footer';
|
||||
import ProductGridItems from 'components/layout/product-grid-items';
|
||||
import { Gallery } from 'components/product/gallery';
|
||||
import { ProductDescription } from 'components/product/product-description';
|
||||
import { HIDDEN_PRODUCT_TAG } from 'lib/constants';
|
||||
import { getProduct, getProductRecommendations } from 'lib/shopify';
|
||||
import { Image } from 'lib/shopify/types';
|
||||
import Link from 'next/link';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
@ -81,7 +81,7 @@ export default async function ProductPage({ params }: { params: { handle: string
|
||||
__html: JSON.stringify(productJsonLd)
|
||||
}}
|
||||
/>
|
||||
<div className="rounded-lg border bg-white lg:grid lg:grid-cols-6">
|
||||
<div className="rounded-lg border border-gray-200 bg-white p-8 dark:border-gray-700 dark:bg-black md:p-12 lg:grid lg:grid-cols-6">
|
||||
<div className="lg:col-span-4">
|
||||
<Gallery
|
||||
images={product.images.map((image: Image) => ({
|
||||
@ -91,7 +91,7 @@ export default async function ProductPage({ params }: { params: { handle: string
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="p-6 lg:col-span-2">
|
||||
<div className="py-6 pr-8 md:pr-12 lg:col-span-2">
|
||||
<ProductDescription product={product} />
|
||||
</div>
|
||||
</div>
|
||||
@ -113,9 +113,30 @@ async function RelatedProducts({ id }: { id: string }) {
|
||||
return (
|
||||
<div className="px-4 py-8">
|
||||
<div className="mb-4 text-3xl font-bold">Related Products</div>
|
||||
<Grid className="grid-cols-2 lg:grid-cols-5">
|
||||
<ProductGridItems products={relatedProducts} />
|
||||
</Grid>
|
||||
<div className="flex flex-row space-x-4 overflow-auto">
|
||||
{relatedProducts.map((product, i) => {
|
||||
return (
|
||||
<Link
|
||||
key={i}
|
||||
className="h-full w-1/2 flex-none lg:w-1/5"
|
||||
href={`/product/${product.handle}`}
|
||||
>
|
||||
<GridTileImage
|
||||
alt={product.title}
|
||||
labels={{
|
||||
isSmall: true,
|
||||
title: product.title,
|
||||
amount: product.priceRange.maxVariantPrice.amount,
|
||||
currencyCode: product.priceRange.maxVariantPrice.currencyCode
|
||||
}}
|
||||
src={product.featuredImage?.url}
|
||||
width={600}
|
||||
height={600}
|
||||
/>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ export async function Carousel() {
|
||||
if (!products?.length) return null;
|
||||
|
||||
return (
|
||||
<div className="relative w-full pb-6 overflow-hidden">
|
||||
<div className="flex space-x-4 animate-carousel">
|
||||
<div className="relative w-full overflow-hidden pb-6">
|
||||
<div className="flex animate-carousel space-x-4">
|
||||
{[...products, ...products].map((product, i) => (
|
||||
<Link
|
||||
key={`${product.handle}${i}`}
|
||||
@ -21,7 +21,7 @@ export async function Carousel() {
|
||||
{product.featuredImage ? (
|
||||
<Image
|
||||
alt={product.title}
|
||||
className="object-contain h-full"
|
||||
className="h-full object-contain"
|
||||
fill
|
||||
sizes="33vw"
|
||||
src={product.featuredImage.url}
|
||||
|
@ -22,15 +22,15 @@ export function GridTileImage({
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'relative flex h-full w-full items-center justify-center overflow-hidden rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black',
|
||||
'relative flex h-full w-full items-center justify-center overflow-hidden rounded-lg border bg-white dark:bg-black',
|
||||
active !== undefined && active
|
||||
? 'border-2 border-blue-600'
|
||||
: 'border-gray-200 dark:border-gray-800',
|
||||
{
|
||||
relative: labels
|
||||
}
|
||||
)}
|
||||
>
|
||||
{active !== undefined && active ? (
|
||||
<span className="absolute w-full h-full bg-white opacity-25"></span>
|
||||
) : null}
|
||||
{props.src ? (
|
||||
<Image
|
||||
className={clsx('relative h-full w-full object-contain', {
|
||||
@ -45,7 +45,7 @@ export function GridTileImage({
|
||||
title={labels.title}
|
||||
amount={labels.amount}
|
||||
currencyCode={labels.currencyCode}
|
||||
size="large"
|
||||
size={labels.isSmall ? 'small' : 'large'}
|
||||
position={labelPosition}
|
||||
/>
|
||||
) : null}
|
||||
|
@ -17,23 +17,32 @@ const Label = ({
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'absolute bottom-0 left-0 flex items-center rounded-full border bg-white/80 p-1 text-black backdrop-blur-md dark:border-gray-800 dark:bg-black/80 dark:text-white',
|
||||
size === 'large' ? 'text-sm' : 'text-xs',
|
||||
'absolute bottom-0 left-0 flex w-full',
|
||||
position === 'center'
|
||||
? 'mb-4 ml-4 md:mb-8 md:ml-8 lg:mb-[35%] lg:ml-20'
|
||||
? 'px-2 pb-2 md:px-8 md:pb-8 lg:px-20 lg:pb-[35%]'
|
||||
: size === 'large'
|
||||
? 'mb-4 ml-4 md:mb-8 md:ml-8'
|
||||
: 'mb-4 ml-4'
|
||||
? 'px-2 pb-2 md:px-8 md:pb-8'
|
||||
: 'px-2 pb-2'
|
||||
)}
|
||||
>
|
||||
<h3 data-testid="product-name" className="mr-6 inline pl-2 font-semibold">
|
||||
{title}
|
||||
</h3>
|
||||
<Price
|
||||
className="flex-none rounded-full bg-blue-600 p-2 font-semibold text-white"
|
||||
amount={amount}
|
||||
currencyCode={currencyCode}
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
'flex items-center rounded-full border bg-white/80 p-1 text-black backdrop-blur-md dark:border-gray-800 dark:bg-black/80 dark:text-white',
|
||||
size === 'large' ? 'text-sm' : 'text-xs'
|
||||
)}
|
||||
>
|
||||
<h3
|
||||
data-testid="product-name"
|
||||
className="mr-6 inline pl-2 font-semibold leading-none tracking-tight"
|
||||
>
|
||||
{title}
|
||||
</h3>
|
||||
<Price
|
||||
className="flex-none rounded-full bg-blue-600 p-2 font-semibold text-white"
|
||||
amount={amount}
|
||||
currencyCode={currencyCode}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline';
|
||||
import clsx from 'clsx';
|
||||
import { GridTileImage } from 'components/grid/tile';
|
||||
import Image from 'next/image';
|
||||
import { useState } from 'react';
|
||||
@ -17,14 +18,14 @@ export function Gallery({ images }: { images: { src: string; altText: string }[]
|
||||
}
|
||||
|
||||
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">
|
||||
<div className="relative mb-12 h-full max-h-[550px] overflow-hidden">
|
||||
{images[currentImage] && (
|
||||
<Image
|
||||
className="relative object-contain w-full h-full"
|
||||
className="relative h-full w-full object-contain"
|
||||
height={600}
|
||||
width={600}
|
||||
alt={images[currentImage]?.altText as string}
|
||||
@ -34,45 +35,36 @@ export function Gallery({ images }: { images: { src: string; altText: string }[]
|
||||
|
||||
{images.length > 1 ? (
|
||||
<div className="absolute bottom-[15%] flex w-full justify-center">
|
||||
<div className="flex items-center px-6 mx-auto text-gray-500 border border-white rounded-full h-11 bg-light/80 backdrop-blur">
|
||||
<div className="mx-auto flex h-11 items-center rounded-full border border-white bg-light/80 text-gray-500 backdrop-blur dark:border-black dark:bg-dark/80">
|
||||
<button
|
||||
aria-label="Previous product image"
|
||||
onClick={() => handleNavigate('previous')}
|
||||
className={buttonClassName}
|
||||
>
|
||||
<ArrowLeftIcon className="h-5" />
|
||||
</button>
|
||||
<div className="w-px h-6 mx-6 bg-gray-400"></div>
|
||||
<button aria-label="Next product image" onClick={() => handleNavigate('next')}>
|
||||
<div className="mx-1 h-6 w-px bg-gray-500"></div>
|
||||
<button
|
||||
aria-label="Next product image"
|
||||
onClick={() => handleNavigate('next')}
|
||||
className={buttonClassName}
|
||||
>
|
||||
<ArrowRightIcon className="h-5" />
|
||||
</button>
|
||||
{/* <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')}
|
||||
>
|
||||
<ArrowRightIcon className="h-6" />
|
||||
</button> */}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{images.length > 1 ? (
|
||||
<div className="flex">
|
||||
<div className="flex space-x-2">
|
||||
{images.map((image, index) => {
|
||||
const isActive = index === currentImage;
|
||||
return (
|
||||
<button
|
||||
aria-label="Enlarge product image"
|
||||
key={image.src}
|
||||
className="w-1/4 h-full"
|
||||
className={clsx('h-auto w-1/6')}
|
||||
onClick={() => setCurrentImage(index)}
|
||||
>
|
||||
<GridTileImage
|
||||
|
Loading…
x
Reference in New Issue
Block a user