Veil UI
Components

Product Card

A product tile with image, price, rating and an add-to-cart action.

Installation

$ npx veil-ui@latest add product-card

Usage

import { ProductCard } from "@/components/ui/product-card";

<ProductCard src="/watch.jpg" alt="Minimal watch" name="Minimal watch" price={129} />;

Examples

Basic

A minimalist wristwatch
Minimal watch
4.6(214)

$129.00

Sale

Over-ear headphonesSale
Studio headphones
4.8(1024)

$199.00$249.00

API reference

The package exports product-card along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.

Accessibility

  • Content uses semantic HTML — lists are lists, tables are tables and metadata uses a definition list.
  • Interactive elements are real buttons or links with visible focus states.
  • Images require meaningful alt text; icons used decoratively are aria-hidden.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add product-card --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Star } from "lucide-vue-next";
import { computed } from "vue";

import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { cn } from "@/lib/utils";

const props = withDefaults(
  defineProps<{
    src: string;
    alt: string;
    name: string;
    price: number;
    originalPrice?: number;
    rating?: number;
    reviewCount?: number;
    badge?: string;
    currency?: string;
    class?: string;
  }>(),
  { currency: "USD" },
);

const emit = defineEmits<{ addToCart: [] }>();

const discounted = computed(
  () => props.originalPrice !== undefined && props.originalPrice > props.price,
);

function formatPrice(value: number) {
  return new Intl.NumberFormat(undefined, {
    style: "currency",
    currency: props.currency,
  }).format(value);
}
</script>

<template>
  <Card
    data-slot="product-card"
    :class="cn('group max-w-xs overflow-hidden py-0', props.class)"
  >
    <div class="relative">
      <img
        :src="src"
        :alt="alt"
        loading="lazy"
        class="aspect-square w-full object-cover transition-transform duration-300 group-hover:scale-105"
      />
      <span
        v-if="badge"
        class="absolute left-3 top-3 rounded-full bg-primary px-2 py-0.5 text-xs font-medium text-primary-foreground"
      >
        {{ badge }}
      </span>
    </div>
    <CardHeader class="pt-4">
      <CardTitle class="text-sm">{{ name }}</CardTitle>
      <div
        v-if="rating !== undefined"
        class="flex items-center gap-1 text-xs text-muted-foreground"
      >
        <Star class="size-3.5 fill-current text-amber-500" aria-hidden="true" />
        <span>{{ rating.toFixed(1) }}</span>
        <span v-if="reviewCount !== undefined">({{ reviewCount }})</span>
      </div>
    </CardHeader>
    <CardContent class="flex items-center justify-between gap-3 pb-4">
      <p class="flex items-baseline gap-2">
        <span class="text-base font-semibold">{{ formatPrice(price) }}</span>
        <span v-if="discounted" class="text-xs text-muted-foreground line-through">
          {{ formatPrice(originalPrice!) }}
        </span>
      </p>
      <Button type="button" size="sm" @click="emit('addToCart')">
        Add to cart
      </Button>
    </CardContent>
  </Card>
</template>

On this page