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

# Product Card Hover

Linked product tile whose quick-add button slides up over the image on hover or focus, with name, price, rating and colour dots.

## Install

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

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)

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

## Examples

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

const product: Product = {
  name: 'Snowflake Ski Goggles',
  key: 'snowflake-ski-goggles',
  link: { path: 'https://sw.demo-shop.com/snowflake-ski-goggles-57f8abf9' },
  price: { amount: 12700, currency: 'EUR', ref: 15900 },
  cover: { src: 'https://static.frontic.com/cdn-cgi/image/width=640,format=auto/ui/products/snowflake-ski-goggles.jpg' },
  rating: 4.4,
  reviewCount: 64,
}
</script>

<template>
  <div class="mx-auto w-full max-w-xs">
    <ProductCardHover :product="product" />
  </div>
</template>
```

## API reference

### ProductCardHover

Shows a product with its image and price, with a quick-add button.

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

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `product` (required) | `Product` |  | The product the card shows; its `badge`, `clearout` and `inStore` fields add badges over the image. |
| `quickAddLabel` | `string` | `'Quick add'` | Shown on the add-to-cart button that appears over the image on hover or focus. |
| `addedLabel` | `string` | `'Added'` | Shown on the quick-add button for two seconds after the product was added. |
| `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 |
| --- | --- | --- |
| `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-hover'
```

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

## Styling

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

States with a look of their own: hover.

## Source

`components/sections/product-card-hover/ProductCardHover.vue`

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

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

import type { HTMLAttributes } from 'vue'
import type { Product } from './types'
import { 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, PriceAmount, PriceRef } 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
    /** Shown on the add-to-cart button that appears over the image on hover or focus. */
    quickAddLabel?: string
    /** Shown on the quick-add button for two seconds after the product was added. */
    addedLabel?: 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',
    quickAddLabel: 'Quick add',
    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 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="['group', props.class]">
    <CardImage class="relative">
      <a :href="product.link?.path ?? '#'" class="group/link relative block outline-none">
        <div data-slot="product-card-hover-image" class="fui-product-card-hover-image overflow-hidden">
          <Image :src="cover" :alt="product.name" class="aspect-square w-full transition-transform duration-500 ease-out group-hover:scale-105" />
        </div>
        <span data-slot="focus-ring" aria-hidden="true" class="pointer-events-none absolute inset-0 z-10 group-focus-visible/link:fui-focus-ring group-focus-visible/link:-outline-offset-3" />
        <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="promo">{{ product.badge }}</Badge>
          <Badge v-if="product.clearout" variant="discount">{{ clearoutLabel }}</Badge>
          <Badge v-if="product.inStore" variant="success">{{ inStoreLabel }}</Badge>
        </div>
      </a>
      <div
        class="absolute inset-x-3 bottom-3 z-20 translate-y-2 opacity-0 transition duration-300 ease-out group-focus-within:translate-y-0 group-focus-within:opacity-100 group-hover:translate-y-0 group-hover:opacity-100 pointer-coarse:translate-y-0 pointer-coarse:opacity-100"
      >
        <Button color="buy" size="sm" class="w-full" aria-live="polite" @click="addToCart">
          <CheckIcon v-if="added" data-icon />
          <PlusIcon v-else data-icon />
          {{ added ? addedLabel : quickAddLabel }}
        </Button>
      </div>
    </CardImage>
    <CardContent class="flex flex-col gap-2">
      <div class="flex items-start justify-between gap-3">
        <h3 data-slot="part-title" class="fui-part-title">
          {{ product.name }}
        </h3>
        <Price :price="product.price" :locale="locale" :show-discount="false" align="end" class="shrink-0">
          <PriceAmount />
          <PriceRef />
        </Price>
      </div>
      <Rating v-if="product.rating" :rating="product.rating" :label="ratingLabel" size="sm">
        <template v-if="product.reviewCount !== undefined" #meta>({{ product.reviewCount }})</template>
      </Rating>
      <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, 4)"
          :key="sibling.key"
          :value="sibling.key"
          :hex="sibling.colors?.exactColorHex"
          :label="sibling.colors?.exactColorName ?? sibling.name"
        />
      </SwatchGroup>
    </CardContent>
  </Card>
</template>
```

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

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