ProductCard
The product tile used in grids and sliders, with price, badges, wishlist and add-to-cart.
Use ProductCard to show a product in a grid, slider or list. It already handles the price, sale and stock badges, the wishlist button and add-to-cart, so you only pass the product.
Example
import { ProductCard } from '@salla.sa/twilight-theme-engine/product';
import type { Product } from '@salla.sa/twilight-theme-engine/types';
export function FixedProducts({ products }: { products: Product[] }) {
return (
<div className="grid grid-cols-2 gap-4 md:grid-cols-4">
{products.map((product, index) => (
<ProductCard key={product.id} product={product} index={index} />
))}
</div>
);
}components/product-card
API
| Prop | Type | Description |
|---|---|---|
product | Product | The product to show. Required. |
layout? | "vertical" | "horizontal" | "fullImage" | "minimal" | "special" | Card layout. Default: "vertical". |
className? | string | Extra class on the card. |
withShadow? | boolean | Adds the card shadow class. Default: false. |
withQuantity? | boolean | Shows the remaining quantity, or an out-of-stock badge. Default: false. |
withoutAddButton? | boolean | Hides the add-to-cart button. Default: false. |
index? | number | Position in a list. Delays the card animation by index x 100 ms. Default: 0. |
imagePriority? | boolean | Load the image eagerly. Use for the first cards above the fold. Default: false. |
sizes? | string | Overrides the image sizes hint. |
Gotchas
- It uses
useMoney,useWishlistandImageinside, so it must be belowTwilightProvider(your root route already is). - Out-of-stock products show a "notify me" button, unless the theme setting
notify_when_available_in_cardis turned off. - Product links are plain
<a href>anchors, so opening a product reloads the page. - To change the card for the whole theme, wrap it (as the starter theme does with its own
ProductCard) or replace it through the component registry. See Replace the product card.
A registry replacement is used only when product:card was registered twice: the registry keeps the earlier component as the "original", and ProductCard ignores a replacement that has no original. A single override on a fresh registry leaves the engine card in place. The choice is also made once, on the first render, so register before any card renders.
Next
- Replace the product card is the step-by-step version.
- Layout and components shows the other ways to swap a component.