mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +00:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
'use client';
|
|
|
|
import SanityImage from '@/components/ui/sanity-image/sanity-image';
|
|
import type { Product } from '@/lib/storm/product';
|
|
import Price from 'components/price';
|
|
import Text from 'components/ui/text';
|
|
import { cn } from 'lib/utils';
|
|
import Link from 'next/link';
|
|
import { FC } from 'react';
|
|
interface Props {
|
|
className?: string;
|
|
product: Product;
|
|
variant?: 'default';
|
|
}
|
|
|
|
const ProductCard: FC<Props> = ({ product, className, variant = 'default' }) => {
|
|
const rootClassName = cn('w-full group relative overflow-hidden', className);
|
|
console.log(product);
|
|
|
|
return (
|
|
<Link
|
|
href={`${product.slug}`}
|
|
className={rootClassName}
|
|
aria-label={product.name}
|
|
locale={product.locale}
|
|
>
|
|
{variant === 'default' && (
|
|
<div className={'relative flex h-full w-full flex-col justify-center'}>
|
|
<div className="relative h-full w-full overflow-hidden">
|
|
{product?.images && (
|
|
<SanityImage
|
|
image={product?.images[0]}
|
|
alt={product.title || 'Product Image'}
|
|
sizes="(max-width: 1024px) 50vw, 20vw"
|
|
/>
|
|
)}
|
|
</div>
|
|
|
|
<div className={cn('flex flex-col items-start text-high-contrast', className)}>
|
|
<Text className="mt-3" variant="listChildHeading">
|
|
{product.title}
|
|
</Text>
|
|
<Price
|
|
className="mt-1 text-sm font-bold leading-tight lg:text-base"
|
|
amount={`${product.price.value}`}
|
|
currencyCode={product.price.currencyCode ? product.price.currencyCode : 'SEK'}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</Link>
|
|
);
|
|
};
|
|
|
|
export default ProductCard;
|