Merge branch 'feat/resenas-productos'
Build and Push Medusa / Escaneo de Secretos (Gitleaks) (push) Successful in 1m21s
Build and Push Medusa / Construir y publicar Medusa (push) Successful in 38m24s
Build and Push Frontend / Escaneo de Secretos (Gitleaks) (push) Successful in 49s
Build and Push Frontend / Construir y Subir Imagen (push) Failing after 33s
Build and Push Medusa / Escaneo de Secretos (Gitleaks) (push) Successful in 1m21s
Build and Push Medusa / Construir y publicar Medusa (push) Successful in 38m24s
Build and Push Frontend / Escaneo de Secretos (Gitleaks) (push) Successful in 49s
Build and Push Frontend / Construir y Subir Imagen (push) Failing after 33s
This commit is contained in:
commit
619228168d
28 files changed
+1276
-2
No files matched your search
@@ -46,7 +46,7 @@ export function AccountDialog({ open, onOpenChange }: { open: boolean; onOpenCha
|
||||
<h2 className="mt-3 text-3xl font-black">Hola, {customer.firstName ?? customer.email}</h2>
|
||||
<p className="mt-3 text-sm leading-6 text-slate-600">{customer.email}</p>
|
||||
<div className="mt-6 grid gap-3">
|
||||
<Button asChild variant="outline"><Link href="/catalog" onClick={() => onOpenChange(false)}><PackageCheck />Ver mis opciones de compra</Link></Button>
|
||||
<Button asChild variant="outline"><Link href="/cuenta/pedidos" onClick={() => onOpenChange(false)}><PackageCheck />Mis pedidos y reseñas</Link></Button>
|
||||
<Button variant="ghost" onClick={logout}><LogOut className="size-4" />Cerrar sesión</Button>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { Clock, PackageCheck, Star } from "lucide-react";
|
||||
import { type FormEvent, type ReactNode, useCallback, useEffect, useState } from "react";
|
||||
import { AccountDialog } from "@/components/account/account-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { formatMoney } from "@/lib/utils";
|
||||
import { useCustomerStore } from "@/store/customer-store";
|
||||
|
||||
type OrderItem = { productId: string; title: string; thumbnail: string | null; handle: string | null; quantity: number };
|
||||
type Order = { id: string; displayId: number | null; createdAt: string; status: string; total: number | null; currency: string; items: OrderItem[] };
|
||||
type MyReview = { id: string; product_id: string; status: "pending" | "approved" | "rejected" };
|
||||
|
||||
const REVIEW_LABEL: Record<MyReview["status"], string> = {
|
||||
pending: "Reseña enviada · en revisión",
|
||||
approved: "Reseña publicada",
|
||||
rejected: "Reseña no publicada",
|
||||
};
|
||||
|
||||
// "Mis pedidos": historial real del cliente (Store API) y, por cada
|
||||
// producto comprado, el boton para calificarlo. Solo desde aca se puede
|
||||
// reseñar: el backend exige que el pedido sea del cliente y contenga el
|
||||
// producto ("Compra verificada").
|
||||
export function OrdersClient() {
|
||||
const { token, customer, hasHydrated } = useCustomerStore();
|
||||
const [orders, setOrders] = useState<Order[] | null>(null);
|
||||
const [reviews, setReviews] = useState<MyReview[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [accountOpen, setAccountOpen] = useState(false);
|
||||
const [reviewing, setReviewing] = useState<{ order: Order; item: OrderItem } | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!token) return;
|
||||
setError(null);
|
||||
try {
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
const [ordersRes, reviewsRes] = await Promise.all([fetch("/api/customer/orders", { headers }), fetch("/api/reviews/me", { headers })]);
|
||||
const ordersData = await ordersRes.json();
|
||||
if (!ordersRes.ok) throw new Error(ordersData.error ?? "No pudimos cargar tus pedidos");
|
||||
const reviewsData = await reviewsRes.json().catch(() => ({ reviews: [] }));
|
||||
setOrders(ordersData.orders);
|
||||
setReviews(reviewsRes.ok ? reviewsData.reviews : []);
|
||||
} catch (loadError) {
|
||||
setError((loadError as Error).message);
|
||||
setOrders([]);
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
if (!hasHydrated) return <Shell><p className="text-slate-500">Cargando…</p></Shell>;
|
||||
|
||||
if (!customer || !token) {
|
||||
return (
|
||||
<Shell>
|
||||
<div className="rounded-2xl border border-slate-200 p-8 text-center">
|
||||
<p className="text-lg font-black text-ari-marino">Inicia sesión para ver tus pedidos</p>
|
||||
<p className="mt-2 text-sm text-slate-500">Desde aquí puedes calificar los productos que compraste.</p>
|
||||
<Button variant="primary" className="mt-5" onClick={() => setAccountOpen(true)}>Iniciar sesión</Button>
|
||||
</div>
|
||||
<AccountDialog open={accountOpen} onOpenChange={setAccountOpen} />
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
const reviewFor = (productId: string) => reviews.find((review) => review.product_id === productId);
|
||||
|
||||
return (
|
||||
<Shell>
|
||||
{error && <p className="mb-4 rounded-2xl bg-rose-50 p-4 text-sm font-bold text-rose-700">{error}</p>}
|
||||
{orders === null ? (
|
||||
<p className="text-slate-500">Cargando tus pedidos…</p>
|
||||
) : orders.length === 0 ? (
|
||||
<div className="rounded-2xl border border-dashed border-slate-300 p-8 text-center">
|
||||
<p className="font-black text-ari-marino">Todavía no tienes pedidos</p>
|
||||
<Button asChild variant="primary" className="mt-4"><Link href="/catalog">Ver catálogo</Link></Button>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="grid gap-5">
|
||||
{orders.map((order) => (
|
||||
<li key={order.id} className="rounded-2xl border border-slate-200 p-5 shadow-sm">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 border-b border-slate-100 pb-3 text-sm">
|
||||
<span className="font-black text-ari-marino">Pedido #{order.displayId ?? order.id.slice(-6)}</span>
|
||||
<span className="text-slate-500">
|
||||
{new Date(order.createdAt).toLocaleDateString("es-CO", { year: "numeric", month: "long", day: "numeric" })}
|
||||
{order.total !== null && <> · {formatMoney(order.total, order.currency)}</>}
|
||||
{order.status === "canceled" && <span className="ml-2 font-bold text-rose-600">Cancelado</span>}
|
||||
</span>
|
||||
</div>
|
||||
<ul className="mt-3 grid gap-3">
|
||||
{order.items.map((item) => {
|
||||
const review = reviewFor(item.productId);
|
||||
return (
|
||||
<li key={`${order.id}-${item.productId}`} className="flex flex-wrap items-center gap-4">
|
||||
<div className="relative size-16 shrink-0 overflow-hidden rounded-xl bg-slate-50">
|
||||
{item.thumbnail && <Image src={item.thumbnail} alt="" fill sizes="64px" className="object-contain" unoptimized />}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
{item.handle ? (
|
||||
<Link href={`/product/${item.handle}`} className="line-clamp-2 font-bold text-slate-900 hover:text-ari-coral">{item.title}</Link>
|
||||
) : (
|
||||
<span className="line-clamp-2 font-bold text-slate-900">{item.title}</span>
|
||||
)}
|
||||
<span className="text-xs text-slate-500">Cantidad: {item.quantity}</span>
|
||||
</div>
|
||||
{review ? (
|
||||
<span className={`inline-flex items-center gap-1.5 text-xs font-bold ${review.status === "approved" ? "text-emerald-700" : review.status === "pending" ? "text-amber-700" : "text-slate-500"}`}>
|
||||
{review.status === "pending" ? <Clock className="size-3.5" /> : <PackageCheck className="size-3.5" />}
|
||||
{REVIEW_LABEL[review.status]}
|
||||
</span>
|
||||
) : order.status === "canceled" ? null : (
|
||||
<Button size="sm" variant="primary" onClick={() => setReviewing({ order, item })}>
|
||||
<Star className="size-4" />Calificar
|
||||
</Button>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<ReviewDialog
|
||||
target={reviewing}
|
||||
token={token}
|
||||
onClose={() => setReviewing(null)}
|
||||
onSubmitted={() => {
|
||||
setReviewing(null);
|
||||
load();
|
||||
}}
|
||||
/>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
function Shell({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<div className="mx-auto max-w-3xl px-4 py-10">
|
||||
<span className="text-xs font-black uppercase tracking-[.18em] text-ari-coral">Mi cuenta</span>
|
||||
<h1 className="font-display mt-2 text-4xl font-bold tracking-tight text-ari-marino">Mis pedidos</h1>
|
||||
<div className="mt-8">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ReviewDialog({
|
||||
target,
|
||||
token,
|
||||
onClose,
|
||||
onSubmitted,
|
||||
}: {
|
||||
target: { order: Order; item: OrderItem } | null;
|
||||
token: string;
|
||||
onClose: () => void;
|
||||
onSubmitted: () => void;
|
||||
}) {
|
||||
const [rating, setRating] = useState(0);
|
||||
const [hover, setHover] = useState(0);
|
||||
const [title, setTitle] = useState("");
|
||||
const [content, setContent] = useState("");
|
||||
const [sending, setSending] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!target) return;
|
||||
setRating(0);
|
||||
setHover(0);
|
||||
setTitle("");
|
||||
setContent("");
|
||||
setError(null);
|
||||
}, [target]);
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
if (!target) return;
|
||||
if (rating < 1) return setError("Elige de 1 a 5 estrellas");
|
||||
if (content.trim().length < 10) return setError("Cuéntanos un poco más (mínimo 10 caracteres)");
|
||||
setSending(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/reviews", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ product_id: target.item.productId, order_id: target.order.id, rating, title: title.trim() || undefined, content: content.trim() }),
|
||||
});
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.error ?? "No pudimos enviar tu reseña");
|
||||
onSubmitted();
|
||||
} catch (submitError) {
|
||||
setError((submitError as Error).message);
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
}
|
||||
|
||||
const shown = hover || rating;
|
||||
return (
|
||||
<Dialog open={target !== null} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent className="max-w-lg p-6 sm:p-8">
|
||||
<DialogPrimitive.Title className="pr-10 text-2xl font-black text-ari-marino">Califica tu compra</DialogPrimitive.Title>
|
||||
<DialogPrimitive.Description className="mt-1 line-clamp-2 text-sm text-slate-500">{target?.item.title}</DialogPrimitive.Description>
|
||||
<form onSubmit={submit} className="mt-6 grid gap-4">
|
||||
<fieldset>
|
||||
<legend className="mb-2 text-sm font-black">Tu calificación</legend>
|
||||
{/* Patron ARIA de radiogroup (no toggles sueltos): el lector de
|
||||
pantalla anuncia "3 estrellas, seleccionado, 3 de 5", un solo
|
||||
tab-stop y flechas para cambiar -- con aria-pressed por
|
||||
estrella solo se anunciaba la estrella exacta, no la
|
||||
calificacion (reportado por frontend-critic). */}
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-label="Tu calificación"
|
||||
className="flex gap-1"
|
||||
onMouseLeave={() => setHover(0)}
|
||||
onKeyDown={(event) => {
|
||||
const delta = event.key === "ArrowRight" || event.key === "ArrowUp" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowDown" ? -1 : 0;
|
||||
if (!delta) return;
|
||||
event.preventDefault();
|
||||
// Como un radiogroup nativo: avanza desde la opcion con foco
|
||||
// (si aun no hay calificacion elegida) o desde la elegida.
|
||||
const buttons = [...event.currentTarget.querySelectorAll("button")];
|
||||
const focused = buttons.indexOf(document.activeElement as HTMLButtonElement) + 1;
|
||||
const next = Math.min(5, Math.max(1, (rating || focused || 0) + delta));
|
||||
setRating(next);
|
||||
setError(null);
|
||||
(event.currentTarget.querySelectorAll("button")[next - 1] as HTMLButtonElement | undefined)?.focus();
|
||||
}}
|
||||
>
|
||||
{[1, 2, 3, 4, 5].map((value) => (
|
||||
<button
|
||||
key={value}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={rating === value}
|
||||
aria-label={`${value} ${value === 1 ? "estrella" : "estrellas"}`}
|
||||
tabIndex={rating ? (rating === value ? 0 : -1) : value === 1 ? 0 : -1}
|
||||
onMouseEnter={() => setHover(value)}
|
||||
onClick={() => { setRating(value); setError(null); }}
|
||||
className="rounded-md p-0.5 transition hover:scale-110 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ari-marino"
|
||||
>
|
||||
<Star className={`size-9 ${value <= shown ? "fill-amber-500 text-amber-600" : "text-slate-400"}`} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<label className="grid gap-1.5 text-sm font-black">
|
||||
Título (opcional)
|
||||
<Input value={title} onChange={(event) => setTitle(event.target.value)} maxLength={80} placeholder="Ej: ¡A mi hijo le encantó!" />
|
||||
</label>
|
||||
<label className="grid gap-1.5 text-sm font-black">
|
||||
Tu reseña
|
||||
<textarea
|
||||
value={content}
|
||||
onChange={(event) => setContent(event.target.value)}
|
||||
rows={5}
|
||||
maxLength={2000}
|
||||
placeholder="¿Qué te pareció el producto? ¿Llegó bien?"
|
||||
className="rounded-2xl border border-slate-200 bg-white p-4 text-sm font-normal text-slate-950 outline-none focus:border-ari-coral focus:ring-4 focus:ring-ari-coral/15"
|
||||
/>
|
||||
</label>
|
||||
<p className="text-xs text-slate-500">Tu reseña se publica después de que la revisemos. Mostramos tu nombre y la inicial de tu apellido.</p>
|
||||
{error && <p className="rounded-xl bg-rose-50 p-3 text-sm font-bold text-rose-700">{error}</p>}
|
||||
<Button type="submit" variant="primary" size="lg" disabled={sending}>{sending ? "Enviando…" : "Enviar reseña"}</Button>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -349,6 +349,7 @@ function CategoryNavBar({ tree, collections, franchises, onOpenMenu, onOpenAccou
|
||||
{(close) => (
|
||||
<ul className="grid min-w-60 gap-1">
|
||||
<li><button type="button" onClick={() => { close(); onOpenAccount(); }} className={helpLinkClass}>Tu cuenta</button></li>
|
||||
<li><Link href="/cuenta/pedidos" prefetch={false} onClick={close} className={helpLinkClass}>Tus pedidos y reseñas</Link></li>
|
||||
<li><Link href="/envios" prefetch={false} onClick={close} className={helpLinkClass}>Envíos y tarifas</Link></li>
|
||||
<li><Link href="/cambios" prefetch={false} onClick={close} className={helpLinkClass}>Cambios y devoluciones</Link></li>
|
||||
<li><Link href="/preguntas-frecuentes" prefetch={false} onClick={close} className={helpLinkClass}>Preguntas frecuentes</Link></li>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { StarRating } from "@/components/product/star-rating";
|
||||
import { useReviewSummaryStore } from "@/store/review-summary-store";
|
||||
|
||||
// Promedio + cantidad de reseñas aprobadas. No renderiza nada si el
|
||||
// producto aun no tiene reseñas (ni un link vacio, en la ficha).
|
||||
export function CardRating({ productId, href }: { productId: string; href?: string }) {
|
||||
const load = useReviewSummaryStore((state) => state.load);
|
||||
const entry = useReviewSummaryStore((state) => state.summary[productId]);
|
||||
useEffect(() => load(), [load]);
|
||||
if (!entry || entry.count === 0) return null;
|
||||
const content = (
|
||||
<>
|
||||
<StarRating value={entry.average} />
|
||||
{entry.average.toLocaleString("es-CO", { minimumFractionDigits: 1 })} ({entry.count} {entry.count === 1 ? "reseña" : "reseñas"})
|
||||
</>
|
||||
);
|
||||
const className = "flex items-center gap-1.5 text-xs font-bold text-slate-500";
|
||||
return href ? <a href={href} className={`${className} mt-3 hover:text-ari-coral`}>{content}</a> : <span className={className}>{content}</span>;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
import Link from "next/link";
|
||||
import { Heart, ShoppingBag, Sparkles, TriangleAlert } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { CardRating } from "@/components/product/card-rating";
|
||||
import { ProductCardGallery } from "@/components/product/product-card-gallery";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -48,6 +49,7 @@ export function ProductCard({ product, priority = false }: { product: Product; p
|
||||
<div className="flex flex-1 flex-col space-y-3 p-5">
|
||||
<div className="flex items-center justify-between gap-2 text-xs font-bold text-slate-500"><span>{product.category}</span><span className="rounded-md bg-ari-coral-claro/10 px-2 py-1 text-ari-marino">{product.collection}</span></div>
|
||||
<Link href={`/product/${product.slug}`} prefetch={false}><h3 className="line-clamp-2 min-h-12 text-lg font-black leading-6 text-ari-marino group-hover:text-ari-coral">{product.name}</h3></Link>
|
||||
<CardRating productId={product.id} />
|
||||
<p className="line-clamp-2 min-h-10 text-sm leading-5 text-slate-500">{product.shortDescription}</p>
|
||||
{product.variants.length > 1 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { BadgeCheck, MessageSquareText } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { StarRating } from "@/components/product/star-rating";
|
||||
|
||||
type Review = { id: string; author_name: string; rating: number; title: string | null; content: string; created_at: string; verified_purchase: boolean };
|
||||
|
||||
// Reseñas de la ficha: solo las aprobadas por el dueño (el backend no
|
||||
// devuelve las pendientes), siempre de compradores verificados.
|
||||
export function ProductReviews({ productId }: { productId: string }) {
|
||||
const [data, setData] = useState<{ reviews: Review[]; average: number; count: number } | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`/api/reviews?product_id=${encodeURIComponent(productId)}`)
|
||||
.then((response) => response.json())
|
||||
.then(setData)
|
||||
.catch(() => setData({ reviews: [], average: 0, count: 0 }));
|
||||
}, [productId]);
|
||||
|
||||
return (
|
||||
<section id="resenas" aria-labelledby="resenas-titulo" className="mt-10 scroll-mt-40">
|
||||
<h2 id="resenas-titulo" className="flex items-center gap-2 text-sm font-black uppercase tracking-wide text-slate-500">
|
||||
<MessageSquareText className="size-4" />
|
||||
Reseñas de clientes
|
||||
</h2>
|
||||
{!data ? (
|
||||
<p className="mt-4 text-sm text-slate-400">Cargando reseñas…</p>
|
||||
) : data.count === 0 ? (
|
||||
<div className="mt-4 rounded-2xl border border-dashed border-slate-300 p-5 text-sm text-slate-600">
|
||||
Aún no hay reseñas de este producto. ¿Ya lo compraste?{" "}
|
||||
<Link href="/cuenta/pedidos" className="font-bold text-ari-marino underline decoration-ari-coral-claro underline-offset-2">Califícalo desde Mis pedidos</Link>.
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="mt-4 flex items-center gap-3">
|
||||
<StarRating value={data.average} size="lg" />
|
||||
<span className="text-2xl font-black text-ari-marino">{data.average.toLocaleString("es-CO", { minimumFractionDigits: 1 })}</span>
|
||||
<span className="text-sm text-slate-500">de 5 · {data.count} {data.count === 1 ? "reseña" : "reseñas"}</span>
|
||||
</div>
|
||||
<ul className="mt-6 grid gap-4">
|
||||
{data.reviews.map((review) => (
|
||||
<li key={review.id} className="rounded-2xl border border-slate-200 p-5">
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
||||
<StarRating value={review.rating} />
|
||||
{review.title && <strong className="text-slate-900">{review.title}</strong>}
|
||||
</div>
|
||||
<p className="mt-2 whitespace-pre-line text-sm leading-6 text-slate-700">{review.content}</p>
|
||||
<p className="mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-slate-500">
|
||||
<span className="font-bold text-slate-700">{review.author_name}</span>
|
||||
<span>{new Date(review.created_at).toLocaleDateString("es-CO", { year: "numeric", month: "long", day: "numeric" })}</span>
|
||||
{review.verified_purchase && (
|
||||
<span className="inline-flex items-center gap-1 font-bold text-emerald-700"><BadgeCheck className="size-3.5" />Compra verificada</span>
|
||||
)}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Star } from "lucide-react";
|
||||
|
||||
// Estrellas de solo lectura. El relleno parcial (ej. 4.5) se dibuja
|
||||
// recortando una capa de estrellas llenas encima de las vacias. amber-600
|
||||
// (no 400): contraste ~3.2:1 sobre blanco, minimo WCAG 1.4.11 para un
|
||||
// grafico informativo (amber-400 daba 1.7:1, reportado por frontend-critic).
|
||||
export function StarRating({ value, size = "sm", className = "" }: { value: number; size?: "sm" | "md" | "lg"; className?: string }) {
|
||||
const px = size === "lg" ? "size-6" : size === "md" ? "size-5" : "size-4";
|
||||
const pct = Math.max(0, Math.min(100, (value / 5) * 100));
|
||||
return (
|
||||
<span className={`relative inline-flex ${className}`} role="img" aria-label={`${value.toLocaleString("es-CO")} de 5 estrellas`}>
|
||||
<span className="flex text-slate-300">{[0, 1, 2, 3, 4].map((i) => <Star key={i} className={`${px} fill-current`} />)}</span>
|
||||
<span className="absolute inset-0 flex overflow-hidden text-amber-600" style={{ width: `${pct}%` }}>
|
||||
{[0, 1, 2, 3, 4].map((i) => <Star key={i} className={`${px} shrink-0 fill-current`} />)}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user