Product card
The shop card: an image that zooms inside its frame on hover, the crossed-out pre-discount price, stars that fill to the fraction of the rating and a stock badge (the low one breathes and counts the units left); the add-to-cart button morphs into its added state on a spring.
Real scenarios
The component as it is used in a product — not a specimen grid.
The storefront shelf
The shop as it ships: hover (or focus) a card and its photo zooms inside the frame, the pre-discount price is crossed out while the saving — a whole percent — is computed from the two prices, the stars fill to the fraction of the rating, and the stock badge speaks in states (the low one breathes and counts the units left). Every number, percent and tally arrives in the page’s own digits.
The cart, from both sides
The button morphs on its spring — icon swap, label crossfade, recolour — and announces itself to screen readers. The left card arrives with in-cart already true (the server is the truth there); the right one starts empty. Without add-action everything stays client-side and the nx-add / nx-remove events bubble from the card — here they report through a toast; pass add-action="addToCart" and remove-action="removeFromCart" instead, and Livewire’s method is called after the optimistic flip while the button holds still for the round-trip.
Out-of-stock cards never get here: their button ships disabled, so the guard never has to fire.
No photo, and sold out
Without an image the tags ride along the body’s top edge instead of over a photo — the audiobook still carries its discount, rating and stock. And when stock is out, the badge turns danger and the button disables itself with the “out of stock” words from the core i18n table.
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| title / category / href | string | required / null / null | The product’s name (its small category above) and the product page’s URL; with href the title becomes a real link. |
| image | array | null | ['src' => …, 'alt' => …] — a 4:5 frame the image zooms inside; without an image the discount/stock tags ride the body’s top edge instead of over a photo. |
| price / compareAt / currency / decimals | number / number / string / int | 0 / null / null / 0 | The price and the pre-discount one (crossed out, its whole-percent saving computed from the pair), the currency (free text like “toman”) and the fraction digits — all in the page’s own digits. |
| rating / ratingCount | number / int | null | A 0–5 rating — the stars fill to its fraction and screen readers get “X of 5”; ratingCount tallies the reviews in the reader’s own word. |
| stock / stockCount | string / int | null | in | low | out — in stock, “only N left” (a breathing badge) and out, which disables the button; stockCount only matters for low. |
| inCart / addAction / removeAction | bool / string | false / null / null | in-cart is the truth from outside; without the actions everything stays client-side and the nx-add / nx-remove events (carrying title and price) bubble. With add-action="addToCart" your Livewire method fires after the optimistic flip with (title, price), the button holding still for the round-trip. |
| labels / locale | array / string | [] / زبان اپ | Overrides for the built-in words (add/added/remove and the stock states with {count} and {value} placeholders) and the digits-and-words locale — defaults come from the core i18n table (fa/en/ar). |
Snippet
<x-nx::product-card title="هدفون بیسیم نابو B2" category="صدا" href="#"
:image="['src' => $photo, 'alt' => 'هدفون نابو B2، نمای روبهرو']"
:price="4850000" :compareAt="6900000" currency="تومان"
:rating="4.5" :ratingCount="1284" stock="in" />
{{-- کمموجود: نشانِ نفسکش با تعدادِ مانده میسازد --}}
<x-nx::product-card title="اسپیکر کتابی نابو Mini" :price="2190000" currency="تومان"
stock="low" :stockCount="2" />
{{-- متصل به لایووایر: متد شما پس از چرخش خوشبینانه صدا زده میشود --}}
<x-nx::product-card title="پایهٔ شارژ بیسیم نابو" :price="890000" currency="تومان"
add-action="addToCart" remove-action="removeFromCart" />
{{-- بدون اتصال: رویدادها را خودتان میگیرید --}}
<x-nx::product-card :price="149000" currency="تومان" title="کابل تخت نابو"
x-on:nx-add="$wire.ping('به سبد اضافه شد')" />