🚀 Ship faster with premium components 🚀
Search documentation v1.2.0

Product Card

Display key product information in a card format

Source Report Issue
Command docs
How to add this block to your project
npm run add ProductCard

Use the ProductCard component to display key product information like product image, pricing, rating, badges or ribbons. They can be used for:

Unlock code
How to use the ProductCard component in Astro
---
// Your import path might differ
import checkWavesIcon from '@icons/check-waves.svg?raw'
---
<ProductCard
href="/products/astro"
img={{
src: '/img/products/astro.png',
alt: 'Astro',
width: 250,
height: 150
}}
name="Product Card for Astro"
price="$25"
showFavoriteButton={true}
badge={{
text: 'Fully responsive',
icon: checkWavesIcon
}}
button={{
text: 'Preview',
href: '/previews/astro'
}}
ribbon={{
text: 'New',
theme: 'alert'
}}
rating={{
score: 5,
color: 'var(--w-color-warning)'
}}
/>

The ProductCard component only expects the following three props:

All other props are optional. The following card is displayed with the required props only:

Badges

To add badges to the card, use the badge prop that expects an object in the form of BadgeProps, along with a text property and an optional icon property:

Unlock code
How to use badges
<ProductCard
...
badge={{
text: 'Fully responsive',
icon: 'circle-check' // You can also pass SVG strings
}}
/>

For a list of available icon types that you can use with the Astro component, please refer to our Icon component documentation.

Ribbons

Ribbons can also be specified using the ribbon prop that can be described using a RibbonProps object along with a text node:

Unlock code
How to use ribbons
<ProductCard
...
ribbon={{ text: 'Ribbon' }}
/>
Unlock code
How to use ribbons
<ProductCard
...
ribbon={{
text: 'New',
theme: 'alert'
}}
/>
Unlock code
How to use ribbons
<ProductCard
...
ribbon={{
text: 'Updated',
theme: 'success',
type: 'folded'
}}
/>

Rating

The rating on the card can be customized through the rating prop which expects a RatingProps object.

Unlock code
How to display ratings
<ProductCard
...
rating={{ score: 5 }}
/>
Unlock code
How to display ratings
<ProductCard
...
rating={{
score: 4,
color: 'var(--w-color-warning)',
emptyColor: 'var(--w-color-primary-20)',
outline: false
}}
/>

CTAs

The ProductCard component comes with two CTA buttons that can be added using the button and showFavoriteButton props, both of which appear on hover:

Unlock code
How to add CTA buttons
<ProductCard
...
showFavoriteButton={true}
button={{
text: 'Preview',
href: '/previews/astro'
}}
/>

Events

The component exposes two custom events you can listen to, to handle changes when the product is added or removed from favorites. Add the following code to your template to handle add/remove events:

Unlock code
How to listen to favorite changes
<script>
import { listen } from 'webcoreui'
listen('addToFavorite', event => console.log('Added:', event))
listen('removeFromFavorite', event => console.log('Removed:', event))
</script>

The event object can hold an arbitrary value. By default, it includes the name of the product. You can easily change what is being emitted by the events by updating the value of the emit variable on top of your component. Svelte and React variants also expose an onAddToFavorite and onRemoveFromFavorite props you can use.

API

Unlock code
Component API reference
type ProductCardProps = {
href: string
name: string
img: {
src: string
alt: string
width: number
height: number
lazy?: boolean
}
price?: string
target?: '_self'
| '_blank'
| '_parent'
| '_top'
| '_unfencedTop'
ribbon?: {
text: string
} & RibbonProps
showFavoriteButton?: boolean
addedToFavorite?: boolean
rating?: RatingProps
button?: {
text: string
icon?: string
} & ButtonProps
badge?: {
text: string
icon?: string
} & BadgeProps
className?: string
}
type SvelteProductCardProps = {
onAddToFavorite?: (args: unknown) => void
onRemoveFromFavorite?: (args: unknown) => void
} & ProductCardProps
type ReactProductCardProps = {
onAddToFavorite?: (args: unknown) => void
onRemoveFromFavorite?: (args: unknown) => void
} & ProductCardProps
PropPurpose
href Sets the link of the product card.
target Sets the target of the link.
name Sets the product's name on the card.
img.src Sets the path for the image on the card.
img.alt Sets an alternate text for the image.
img.width Sets the width of the image.
img.height Sets the height of the image.
img.lazy Set to true to enable lazy loading for the image.
price Sets the product's price on the card.
ribbon Sets a ribbon for the card.
showFavoriteButton Set to true to display a favorite button on hover.
addedToFavorite Sets the initial state of the favorite button. Set to true if the product is already added to favorites.
rating Sets a rating for the product.
button.text Sets a CTA button over the image that is revealed on hover.
button.icon Sets an optional icon for the CTA button.
badge.text Sets a badge under the name of the product.
badge.icon Sets an optional icon for the badge.
className Pass additional CSS classes for the card.
Svelte & React PropPurpose
onAddToFavorite Add event listeners when the product is added to favorite.
onRemoveFromFavorite Add event listeners when the product is removed from favorite.