# React Native Product Card (Pro)

> A React Native product card for iOS, Android and the web: photo with sale and stock badges, wishlist heart, rating, struck-through sale price, color swatches that swap the photo, and Add to cart that turns into a quantity stepper. Vertical, horizontal, compact and overlay.

# Product card Pro

A product in a grid or list: its photo with sale and stock badges and a wishlist heart that fills with a pop, the title, rating and price (struck through on sale, read as "$32, was $40"), color swatches that swap the photo, and Add to cart, which says Added and then becomes a quantity stepper once it's in the cart. Prices are in cents.

```tsx
import { ProductCard } from '@patine-ui/pro';
```

```tsx live full
import { ProductCard } from '@patine-ui/pro';

const mug = {
  id: 'mug',
  title: 'Speckled stoneware mug',
  subtitle: 'Ouro Studio',
  image: 'https://picsum.photos/id/225/600/600',
  price: 3200,
  compareAtPrice: 4000,
  rating: 4.6,
  reviewCount: 128,
  stockCount: 3,
  badges: ['New'],
  swatches: [
    { value: 'sand', label: 'Sand', color: '#E8DCC8' },
    { value: 'ink', label: 'Ink', color: '#1F2937', image: 'https://picsum.photos/id/1060/600/600' },
    { value: 'sage', label: 'Sage', color: '#A3B18A' },
  ],
};

export default function Example() {
  const [qty, setQty] = React.useState(0);
  return (
    <ProductCard
      product={mug}
      onPress={() => {}}
      onFavoriteChange={() => {}}
      onAddToCart={() => setQty(1)}
      quantity={qty}
      onQuantityChange={setQty}
      style={{ width: 280 }}
    />
  );
}
```

## Example: a shop's grid

A product listing: the cards share one row height, the wishlist hearts and quantities are the page's own state, and the cart total in the header adds them up.

```tsx live wide
import { useState } from 'react';
import { View } from 'react-native';
import { HStack, Text } from 'patine-ui';
import { ProductCard } from '@patine-ui/pro';

const PRODUCTS = [
  { id: 'mug', title: 'Speckled stoneware mug', subtitle: 'Ouro Studio', image: 'https://picsum.photos/id/225/600/600', price: 3200, rating: 4.6, reviewCount: 128 },
  { id: 'tote', title: 'Waxed canvas tote', subtitle: 'Field & Co.', image: 'https://picsum.photos/id/21/600/600', price: 5900, compareAtPrice: 7400, badges: ['Sale'], rating: 4.8, reviewCount: 64 },
  { id: 'lamp', title: 'Brass desk lamp', subtitle: 'Lumen', image: 'https://picsum.photos/id/180/600/600', price: 12900, stockCount: 2, rating: 4.4, reviewCount: 22 },
];

export default function Example() {
  const [cart, setCart] = useState<Record<string, number>>({});
  const items = Object.values(cart).reduce((a, b) => a + b, 0);
  const total = PRODUCTS.reduce((sum, p) => sum + (cart[p.id] ?? 0) * p.price, 0);
  return (
    <View style={{ width: '100%', gap: 12 }}>
      <HStack justify="space-between">
        <Text weight="semibold">Home goods</Text>
        <Text color="textSecondary">{items ? `${items} in cart · €${(total / 100).toFixed(2)}` : 'Cart is empty'}</Text>
      </HStack>
      <View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 12 }}>
        {PRODUCTS.map((p) => (
          <ProductCard
            key={p.id}
            product={p}
            currency="EUR"
            onPress={() => {}}
            onFavoriteChange={() => {}}
            onAddToCart={() => setCart((c) => ({ ...c, [p.id]: 1 }))}
            quantity={cart[p.id] ?? 0}
            onQuantityChange={(q) => setCart((c) => ({ ...c, [p.id]: q }))}
            style={{ flexGrow: 1, flexBasis: 180, maxWidth: 260 }}
          />
        ))}
      </View>
    </View>
  );
}
```

## Variants

`variant` is `'vertical'` (photo on top), `'horizontal'` (photo beside, for lists and carts), `'compact'` (a small tile with the price) or `'overlay'` (the text over the photo, for featured products). `size` is `'sm'`, `'md'` or `'lg'`, and `aspectRatio` sets the photo's shape.

```tsx live full
import { ProductCard } from '@patine-ui/pro';

const products = [
  { id: '1', title: 'Linen apron', subtitle: 'Studio basics', image: 'https://picsum.photos/id/1080/400/400', price: 4800, rating: 4.8, reviewCount: 52 },
  { id: '2', title: 'Ceramic vase', image: 'https://picsum.photos/id/1067/400/400', price: 6400, compareAtPrice: 8000 },
  { id: '3', title: 'Walnut tray', image: 'https://picsum.photos/id/1070/400/400', price: 5600, stockCount: 0 },
];

export default function Example() {
  return (
    <View style={{ gap: 24 }}>
      <View style={{ flexDirection: 'row', gap: 12 }}>
        {products.map((p) => (
          <ProductCard key={p.id} product={p} variant="compact" style={{ width: 150 }} />
        ))}
      </View>
      <ProductCard product={products[0]} variant="horizontal" onAddToCart={() => {}} onFavoriteChange={() => {}} style={{ width: 420 }} />
      <ProductCard product={products[1]} variant="overlay" size="lg" onFavoriteChange={() => {}} style={{ width: 260 }} />
    </View>
  );
}
```

## Wishlist, swatches and the cart

`favorite`, `defaultFavorite` and `onFavoriteChange` drive the heart (shown when `onFavoriteChange` is set, or with `showFavorite`); it's a switch for screen readers. `swatch`, `defaultSwatch` and `onSwatchChange` pick a color; a swatch with an `image` swaps the photo. `onAddToCart(product, swatch)` adds; give `quantity` and `onQuantityChange` and a stepper takes its place once it's above zero. Sold-out products (`inStock: false` or `stockCount: 0`) dim their photo and can't be added; under `lowStockAt` (5) they say "Only 3 left".

## A grid that loads

```tsx live full
import { ProductCard } from '@patine-ui/pro';

const items = [
  { id: 'a', title: 'Stoneware bowl', image: 'https://picsum.photos/id/292/400/400', price: 2800, rating: 4.4, reviewCount: 31 },
  { id: 'b', title: 'Tea set', image: 'https://picsum.photos/id/431/400/400', price: 12000, compareAtPrice: 15000, rating: 4.9, reviewCount: 210 },
];

export default function Example() {
  const [loading, setLoading] = React.useState(true);
  React.useEffect(() => {
    const id = setTimeout(() => setLoading(false), 1500);
    return () => clearTimeout(id);
  }, []);
  return (
    <View style={{ flexDirection: 'row', gap: 16 }}>
      {items.map((p) => (
        <ProductCard key={p.id} product={p} loading={loading} onAddToCart={() => {}} size="sm" style={{ width: 200 }} />
      ))}
    </View>
  );
}
```

## Your own image component

`renderImage({ source, style })` draws the photo yourself, e.g. with `expo-image` for caching.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `product` | `ProductCardData` | — | `{ id, title, subtitle?, image?, price, compareAtPrice?, rating?, reviewCount?, badges?, swatches?, inStock?, stockCount? }` |
| `variant` | `'vertical'` \| `'horizontal'` \| `'compact'` \| `'overlay'` | `'vertical'` | |
| `size` | `'sm'` \| `'md'` \| `'lg'` | `'md'` | |
| `aspectRatio` | `number` | `1` (`4/5` overlay) | |
| `onPress` | `(product) => void` | — | The card is a button. |
| `showFavorite` / `favorite` / `defaultFavorite` / `onFavoriteChange` | | | The heart. |
| `swatch` / `defaultSwatch` / `onSwatchChange` | `string` | first swatch | |
| `onAddToCart` | `(product, swatch) => void` | — | |
| `quantity` / `onQuantityChange` | `number` | — | A stepper once in the cart. |
| `currency` / `locale` / `priceFormatter` | | `'USD'` | |
| `lowStockAt` | `number` | `5` | |
| `showRating` / `showDiscount` | `boolean` | `true` | |
| `loading` | `boolean` | `false` | A placeholder of the card. |
| `renderImage` | `({ source, style }) => ReactNode` | — | |
| `density` / `labels` / `design` / `theme` / `style` | | | |
