feat(storefront): galería deslizable en las tarjetas de producto del listado
Permite ver todas las imágenes de un producto desde el catálogo y los carruseles sin entrar a la ficha: swipe con scroll-snap nativo en móvil, flechas al pasar el mouse en escritorio (pointer-fine) y puntos de posición. Cada imagen sigue enlazando a la ficha; productos con una sola imagen no muestran controles. overscroll-behavior-x: contain evita que el swipe de imágenes mueva el carrusel de productos del inicio. Validado antes del merge con build de producción local (datos mock) y Playwright con eventos táctiles reales a 390/320 px y 1280 px. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018r19s4H8MBGegqToqw5guP
This commit is contained in:
1 parent
496ad982f3
commit
123cbbd87a
2 files changed
+117
-2
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { Heart, ShoppingBag, Sparkles, TriangleAlert } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { ProductCardGallery } from "@/components/product/product-card-gallery";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { Product } from "@/lib/headless/types";
|
||||
@@ -22,6 +22,9 @@ export function ProductCard({ product, priority = false }: { product: Product; p
|
||||
? Math.round((1 - product.price / product.compareAtPrice) * 100)
|
||||
: null;
|
||||
|
||||
const galleryImages = Array.from(new Set(product.images.filter(Boolean)));
|
||||
if (galleryImages.length === 0) galleryImages.push(product.thumbnail);
|
||||
|
||||
const [selectedVariantId, setSelectedVariantId] = useState(product.variants[0]?.id);
|
||||
const selectedVariant = product.variants.find((variant) => variant.id === selectedVariantId) ?? product.variants[0];
|
||||
const outOfStock = selectedVariant?.available === false;
|
||||
@@ -37,7 +40,7 @@ export function ProductCard({ product, priority = false }: { product: Product; p
|
||||
return (
|
||||
<article className="group flex h-full flex-col overflow-hidden rounded-lg border border-slate-100 bg-white shadow-lg shadow-ari-marino/5 transition duration-300 hover:-translate-y-1.5 hover:shadow-2xl hover:shadow-ari-coral/10">
|
||||
<div className="relative aspect-square overflow-hidden bg-white">
|
||||
<Link href={`/product/${product.slug}`} prefetch={false}><Image src={product.thumbnail} alt={product.name} fill priority={priority} sizes="(max-width: 640px) 82vw, (max-width: 1024px) 44vw, 280px" className="object-cover transition duration-500 group-hover:scale-[1.035]" /></Link>
|
||||
<ProductCardGallery images={galleryImages} name={product.name} href={`/product/${product.slug}`} priority={priority} />
|
||||
<div className="absolute left-3 top-3 flex gap-2">{outOfStock && <Badge className="bg-rose-600 text-white">Agotado</Badge>}{discountPercent && discountPercent > 0 && <Badge className="bg-ari-coral-claro text-ari-marino">-{discountPercent}%</Badge>}{product.isNew && <Badge className="bg-ari-marino text-white">Nuevo</Badge>}{product.featured && <Badge className="bg-ari-coral-claro text-ari-marino"><Sparkles className="mr-1 size-3" />Top</Badge>}</div>
|
||||
{outOfStock && <div className="pointer-events-none absolute inset-0 bg-white/40" />}
|
||||
<button type="button" aria-label={isFavorite ? "Quitar de favoritos" : "Agregar a favoritos"} aria-pressed={isFavorite} className={`absolute right-3 top-3 rounded-full p-2.5 shadow-lg backdrop-blur transition ${isFavorite ? "bg-ari-coral text-white" : "bg-white/95 text-slate-900 hover:text-ari-coral"}`} onClick={() => toggleProduct(product)}><Heart className={`size-4 ${isFavorite ? "fill-current" : ""}`} /></button>
|
||||
|
||||
Reference in new issue
Block a user