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

# Product Card Gallery

Image-led product tile with a wishlist toggle, variant thumbnails that switch the image, badge, rating and price.

## Install

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

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 Grid](https://ui.frontic.com/components/templates/category-grid.md)

npm packages: `@lucide/vue`

## Examples

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

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

const product: Product = {
  name: 'Blizzard Defender',
  key: 'blizzard-defender-455fb5a3',
  description: 'Built for snow-day adventures: warm, and free to move in.',
  link: { path: 'https://sw.demo-shop.com/blizzard-defender-455fb5a3' },
  price: { amount: 12600, currency: 'EUR' },
  cover: { src: image('blizzard-defender-aubergine') },
  rating: 4.6,
  reviewCount: 212,
  badge: 'New',
  siblings: {
    items: [
      {
        key: 'blizzard-defender-455fb5a3',
        name: 'Aubergine',
        cover: { src: image('blizzard-defender-aubergine') },
        link: { path: 'https://sw.demo-shop.com/blizzard-defender-455fb5a3' },
        colors: { exactColorHex: '#3d3347', exactColorName: 'Aubergine' },
      },
      {
        key: 'blizzard-defender-41d5aa85',
        name: 'Dusty rose',
        cover: { src: image('blizzard-defender-dusty-rose') },
        link: { path: 'https://sw.demo-shop.com/blizzard-defender-41d5aa85' },
        colors: { exactColorHex: '#b98a87', exactColorName: 'Dusty rose' },
      },
      {
        key: 'blizzard-defender-393a11b2',
        name: 'Salmon',
        cover: { src: image('blizzard-defender-salmon') },
        link: { path: 'https://sw.demo-shop.com/blizzard-defender-393a11b2' },
        colors: { exactColorHex: '#dc967b', exactColorName: 'Salmon' },
      },
    ],
  },
}
</script>

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

## API reference

### ProductCardGallery

Shows a product with its image, colour options, price and rating, and a wishlist button.

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

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `product` (required) | `Product` |  | The product the card shows; its `badge`, `clearout` and `inStore` fields add badges over the image. |
| `eyebrow` | `string` |  | Small text above the product name, such as the brand or collection. |
| `wishlistLabel` | `string` | `'Add to wishlist'` | Screen-reader label of the heart button while the product is not on the wishlist. |
| `wishlistedLabel` | `string` | `'Remove from wishlist'` | Screen-reader label of the heart button once the product is on the wishlist. |
| `clearoutLabel` | `string` | `'Clearout'` | Shown on the badge of a product marked `clearout`. |
| `inStoreLabel` | `string` | `'In Store'` | Shown on the badge of a product that is 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 |
| --- | --- | --- |
| `wishlist` | `product: Product` | Fires with the product when the shopper toggles it on the wishlist. |

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

## Exports

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

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

## Styling

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

States with a look of their own: hover.

## Source

`components/sections/product-card-gallery/ProductCardGallery.vue`

```vue
<script lang="ts">
/** Shows a product with its image, colour options, price and rating, and a wishlist button. */
export default {}
</script>

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

import type { HTMLAttributes } from 'vue'
import type { Product } from './types'
import { ref } from 'vue'
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 the card shows; its `badge`, `clearout` and `inStore` fields add badges over the image. */
    product: Product
    /** Small text above the product name, such as the brand or collection. */
    eyebrow?: string
    /** Screen-reader label of the heart button while the product is not on the wishlist. */
    wishlistLabel?: string
    /** Screen-reader label of the heart button once the product is on the wishlist. */
    wishlistedLabel?: string
    /** Shown on the badge of a product marked `clearout`. */
    clearoutLabel?: string
    /** Shown on the badge of a product that is 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',
    wishlistLabel: 'Add to wishlist',
    wishlistedLabel: 'Remove from wishlist',
    clearoutLabel: 'Clearout',
    inStoreLabel: 'In Store',
  },
)
const emit = defineEmits<{
  /** Fires with the product when the shopper toggles it on the wishlist. */
  wishlist: [product: Product]
}>()

const { selected: selectedSibling, cover } = useProductSibling(() => props.product)

const wishlisted = ref(false)

function wishlist() {
  wishlisted.value = !wishlisted.value
  emit('wishlist', props.product)
}
</script>

<template>
  <Card :surface="surface" :class="['group', props.class]">
    <CardImage class="relative">
      <div data-slot="product-card-gallery-image" class="fui-product-card-gallery-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="product.badge || product.clearout || product.inStore" class="absolute top-3 inset-s-3 flex flex-col items-start gap-1">
        <Badge v-if="product.badge" variant="new" data-slot="product-card-gallery-badge" class="fui-product-card-gallery-badge">{{ product.badge }}</Badge>
        <Badge v-if="product.clearout" variant="discount">{{ clearoutLabel }}</Badge>
        <Badge v-if="product.inStore" variant="success">{{ inStoreLabel }}</Badge>
      </div>
      <Button
        :variant="wishlisted ? 'solid' : 'outline'"
        color="neutral"
        size="icon-sm"
        class="absolute top-3 inset-e-3"
        :aria-label="wishlisted ? wishlistedLabel : wishlistLabel"
        :aria-pressed="wishlisted"
        @click="wishlist"
      >
        <HeartIcon data-icon />
      </Button>
    </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="product-card-gallery-title" class="fui-product-card-gallery-title">
          {{ product.name }}
        </h3>
        <p v-if="product.description" data-slot="hint" class="fui-hint line-clamp-2">
          {{ product.description }}
        </p>
      </div>

      <div class="mt-auto flex flex-col gap-1">
        <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, 6)"
            :key="sibling.key"
            :value="sibling.key"
            :hex="sibling.colors?.exactColorHex"
            :label="sibling.colors?.exactColorName ?? sibling.name"
          />
        </SwatchGroup>
        <Rating v-if="product.rating" :rating="product.rating" :label="ratingLabel" size="sm">
          <template v-if="product.reviewCount !== undefined" #meta>({{ product.reviewCount }})</template>
        </Rating>
        <Price :price="product.price" :locale="locale" />
      </div>
    </CardContent>
  </Card>
</template>
```

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

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