Open this example in the interactive library
Live preview
Source code
// components/StockAvailabilityLabel.tsx
export default function StockAvailabilityLabel({ stock = 8 }: { stock?: number } = {}) {
return (
<span role="status">
{stock === 0 ? "Sold out" : stock < 4 ? "Only " + stock + " left" : "In stock"}
</span>
);
}
