---
name: product-card-basic
title: Product Card Basic
url: https://ui.frontic.com/components/sections/product-card-basic.md
tier: sections
install: npx @frontic/ui add product-card-basic
files:
  - components/sections/product-card-basic/ProductCardBasic.vue
  - components/sections/product-card-basic/index.ts
  - components/sections/product-card-basic/types.ts
registryDependencies:
  - badge
  - button
  - card
  - image
  - price
  - product
  - rating
  - swatch-group
  - use-product-sibling
dependencies:
  - "@lucide/vue"
  - "@vueuse/core"
---

# Product Card Basic

Product tile with sale and stock badges, rating, price, colour swatches that switch the image, and an add-to-cart button that confirms the add.

## Install

```sh
npx @frontic/ui add product-card-basic
```

Built from: [Badge](https://ui.frontic.com/components/ui/badge.md), [Button](https://ui.frontic.com/components/ui/button.md), [Card](https://ui.frontic.com/components/ui/card.md), [Image](https://ui.frontic.com/components/ui/image.md), [Price](https://ui.frontic.com/components/ui/price.md), [Product](https://ui.frontic.com/lib/product.md), [Rating](https://ui.frontic.com/components/ui/rating.md), [Swatch Group](https://ui.frontic.com/components/ui/swatch-group.md), [Use Product Sibling](https://ui.frontic.com/composables/use-product-sibling.md)

Used by: [Category Filter](https://ui.frontic.com/components/templates/category-filter.md), [Filter Sheet](https://ui.frontic.com/components/templates/filter-sheet.md), [Filter Sidebar](https://ui.frontic.com/components/templates/filter-sidebar.md), [Filter Toolbar](https://ui.frontic.com/components/templates/filter-toolbar.md)

npm packages: `@lucide/vue`, `@vueuse/core`

## Examples

```vue
<script setup lang="ts">
import { ProductCardBasic, type Product } from '@/components/sections/product-card-basic'

const image = (name: string) => `https://static.frontic.com/cdn-cgi/image/width=640,format=auto/ui/products/${name}.jpg`

const product: Product = {
  name: 'Northern Light Hybrid Jacket',
  key: 'northern-light-hybrid-jacket-black',
  price: { amount: 11500, currency: 'EUR' },
  cover: { src: image('northern-light-hybrid-jacket-charcoal') },
  rating: 4.7,
  reviewCount: 86,
  badge: 'New',
  inStore: true,
  siblings: {
    items: [
      {
        key: 'northern-light-hybrid-jacket-black',
        name: 'Charcoal',
        cover: { src: image('northern-light-hybrid-jacket-charcoal') },
        colors: { exactColorHex: '#4a4a47', exactColorName: 'Charcoal' },
      },
      {
        key: 'northern-light-hybrid-jacket-orchid',
        name: 'Lavender',
        cover: { src: image('northern-light-hybrid-jacket-lavender') },
        colors: { exactColorHex: '#b8a2cf', exactColorName: 'Lavender' },
      },
    ],
  },
}
</script>

<template>
  <div class="mx-auto w-full max-w-xs">
    <ProductCardBasic :product="product" eyebrow="Women · Jackets" />
  </div>
</template>
```

## API reference

### ProductCardBasic

Shows a product with its image, price and rating, with an add-to-cart button.

Styling: [`part-title`](https://ui.frontic.com/DESIGN.md#part-title); [`meta`](https://ui.frontic.com/DESIGN.md#meta). Change them there and every part that extends them follows.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `product` (required) | `Product` |  | The product to show: name, price, cover, rating, badges and colour siblings. |
| `eyebrow` | `string` |  | Shown above the product's name, e.g. the brand or category. |
| `addToCartLabel` | `string` | `'Add to Cart'` | Shown on the button that adds the product to the cart. |
| `addedLabel` | `string` | `'Added'` | Shown on the add-to-cart button for two seconds after a click. |
| `clearoutLabel` | `string` | `'Clearout'` | Shown on the badge of a product marked as clearout. |
| `inStoreLabel` | `string` | `'In Store'` | Shown on the badge of a product available in store. |
| `locale` | `string` |  | BCP 47 locale the price is formatted in, e.g. `de-DE`; the ConfigProvider's when left out. |
| `ratingLabel` | `((score: number, max: number) => string)`: `(score: number, max: number): string` |  | Builds the rating's screen-reader name from the score, to one decimal, and the top of the scale; `4.6 out of 5` when left out. |
| `surface` | `'raised' \| 'bare'` | `'raised'` | Bare drops the edge, shadow and inset, for a section placed inside another Card. |
| `class` | `ClassValue` |  | Classes added to the part's own element, after its recipe classes. |

| Event | Payload | Description |
| --- | --- | --- |
| `add-to-cart` | `product: Product` | Fires with the product when the shopper adds it to the cart. |

| Data attribute | Values | Description |
| --- | --- | --- |
| `data-surface` | `'raised' \| 'bare'` | Carries the `surface` prop. |

## Exports

```ts
import { type Product, type ProductSibling } from '@/components/sections/product-card-basic'
```

- `Product`, `ProductSibling`: from [Product](https://ui.frontic.com/lib/product.md)

## Styling

| Part | Recipe |
| --- | --- |
| `default` | [`product-card-basic`](https://ui.frontic.com/DESIGN.md#product-card-basic) |
| `image` | [`product-card-basic-image`](https://ui.frontic.com/DESIGN.md#product-card-basic-image) |
| `part-title` | [`part-title`](https://ui.frontic.com/DESIGN.md#part-title) |
| `meta` | [`meta`](https://ui.frontic.com/DESIGN.md#meta) |

States with a look of their own: hover.

## Source

`components/sections/product-card-basic/ProductCardBasic.vue`

```vue
<script lang="ts">
/** Shows a product with its image, price and rating, with an add-to-cart button. */
export default {}
</script>

<script setup lang="ts">
import { CheckIcon, ShoppingBagIcon } from '@lucide/vue'

import type { HTMLAttributes } from 'vue'
import type { Product } from './types'
import { computed, ref } from 'vue'
import { useTimeoutFn } from '@vueuse/core'
import { useProductSibling } from '@library/composables/use-product-sibling'
import { Badge } from '@library/components/ui/badge'
import { Button } from '@library/components/ui/button'
import { Card, CardContent, CardImage } from '@library/components/ui/card'
import { Image } from '@library/components/ui/image'
import { Price } from '@library/components/ui/price'
import { Rating } from '@library/components/ui/rating'
import { SwatchGroup, SwatchGroupItem } from '@library/components/ui/swatch-group'

const props = withDefaults(
  defineProps<{
    /** The product to show: name, price, cover, rating, badges and colour siblings. */
    product: Product
    /** Shown above the product's name, e.g. the brand or category. */
    eyebrow?: string
    /** Shown on the button that adds the product to the cart. */
    addToCartLabel?: string
    /** Shown on the add-to-cart button for two seconds after a click. */
    addedLabel?: string
    /** Shown on the badge of a product marked as clearout. */
    clearoutLabel?: string
    /** Shown on the badge of a product available in store. */
    inStoreLabel?: string
    /** BCP 47 locale the price is formatted in, e.g. `de-DE`; the ConfigProvider's when left out. */
    locale?: string
    /** Builds the rating's screen-reader name from the score, to one decimal, and the top of the scale; `4.6 out of 5` when left out. */
    ratingLabel?: (score: number, max: number) => string
    /** Bare drops the edge, shadow and inset, for a section placed inside another Card. */
    surface?: 'raised' | 'bare'
    class?: HTMLAttributes['class']
  }>(),
  {
    surface: 'raised',
    addToCartLabel: 'Add to Cart',
    addedLabel: 'Added',
    clearoutLabel: 'Clearout',
    inStoreLabel: 'In Store',
  },
)
const emit = defineEmits<{
  /** Fires with the product when the shopper adds it to the cart. */
  'add-to-cart': [product: Product]
}>()

const { selected: selectedSibling, cover } = useProductSibling(() => props.product)
const hasBadges = computed(() => Boolean(props.product.badge || props.product.clearout || props.product.inStore))

const added = ref(false)
const { start: revertLater } = useTimeoutFn(() => (added.value = false), 2000, { immediate: false })

function addToCart() {
  emit('add-to-cart', props.product)
  added.value = true
  revertLater()
}
</script>

<template>
  <Card :surface="surface" :class="['fui-product-card-basic group', props.class]">
    <CardImage class="relative">
      <div data-slot="product-card-basic-image" class="fui-product-card-basic-image overflow-hidden">
        <Image :src="cover" :alt="product.name" class="aspect-3/4 w-full transition-transform duration-500 ease-out group-hover:scale-105" />
      </div>
      <div v-if="hasBadges" class="absolute top-3 inset-s-3 flex flex-col items-start gap-1">
        <Badge v-if="product.badge" variant="promo">{{ product.badge }}</Badge>
        <Badge v-if="product.clearout" variant="discount">{{ clearoutLabel }}</Badge>
        <Badge v-if="product.inStore" variant="success">{{ inStoreLabel }}</Badge>
      </div>
    </CardImage>

    <CardContent class="flex flex-1 flex-col gap-3">
      <div class="flex flex-col gap-1">
        <p v-if="eyebrow" data-slot="meta" class="fui-meta">{{ eyebrow }}</p>
        <h3 data-slot="part-title" class="fui-part-title line-clamp-2">
          {{ product.name }}
        </h3>
        <Rating v-if="product.rating" :rating="product.rating" :label="ratingLabel" size="sm">
          <template v-if="product.reviewCount !== undefined" #meta>({{ product.reviewCount }})</template>
        </Rating>
      </div>

      <Price :price="product.price" :locale="locale" />

      <SwatchGroup v-if="product.siblings?.items?.length" v-model="selectedSibling" type="single" size="xs" shape="pill" label-class="sr-only">
        <SwatchGroupItem
          v-for="sibling in product.siblings.items.slice(0, 5)"
          :key="sibling.key"
          :value="sibling.key"
          :hex="sibling.colors?.exactColorHex"
          :label="sibling.colors?.exactColorName ?? sibling.name"
        />
      </SwatchGroup>

      <Button color="buy" class="mt-auto w-full" aria-live="polite" @click="addToCart">
        <CheckIcon v-if="added" data-icon />
        <ShoppingBagIcon v-else data-icon />
        {{ added ? addedLabel : addToCartLabel }}
      </Button>
    </CardContent>
  </Card>
</template>
```

`components/sections/product-card-basic/types.ts`

```ts
export type { Product, ProductSibling } from '@library/lib/product'
```
