# Product page

A product detail for an insulated jacket: a gallery with thumbnail buttons, the name in a `Heading`, a star rating and review `Link`, color swatches, a size `RadioGroup` with one size sold out, a quantity `InputSelect` and an Add to bag `Button` that confirms with a toast. Shipping, returns and care sit in native disclosures with a chevron that turns when they open.

**Example: Ridgeline insulated jacket** (`examples/recipes/product-page.tsx`)

```tsx
'use client'

import {
  BodySmall,
  Button,
  Heading,
  InputLabel,
  InputSelect,
  Label,
  Link,
  Radio,
  RadioGroup,
  Stack,
  Text,
  toastSuccess,
} from '@blocks/design-system'
import { ChevronDown, ShoppingBag, Star } from 'lucide-react'
import { type FormEvent, useId, useState } from 'react'
import styles from './product-page.module.css'

type View = 'front' | 'back' | 'detail' | 'packed'

const views: { value: View; label: string }[] = [
  { value: 'front', label: 'Front' },
  { value: 'back', label: 'Back' },
  { value: 'detail', label: 'Zip detail' },
  { value: 'packed', label: 'Packed in its pocket' },
]

const colors = [
  { value: 'spruce', label: 'Spruce' },
  { value: 'ochre', label: 'Ochre' },
  { value: 'glacier', label: 'Glacier' },
  { value: 'basalt', label: 'Basalt' },
] as const

type Color = (typeof colors)[number]['value']

const sizes = [
  { value: 'XS', inStock: true },
  { value: 'S', inStock: true },
  { value: 'M', inStock: true },
  { value: 'L', inStock: true },
  { value: 'XL', inStock: false },
  { value: 'XXL', inStock: true },
]

const policies = [
  { title: 'Shipping', body: 'Free 3–5 day shipping on orders over $150. Ships from Bend, Oregon, within one business day.' },
  { title: 'Returns', body: 'Return unworn gear within 60 days for a full refund. Worn it on a trip and it failed? We repair it for free.' },
  {
    title: 'Materials and care',
    body: 'Recycled nylon ripstop shell with a PFC-free finish, 120 g recycled synthetic fill. 480 g in size M. Machine wash cold.',
  },
]

const rating = 4.6

// A product detail page: a drawn gallery, color and size choices, quantity
// and an Add to bag that confirms with a toast. The art is app-owned SVG.
export default function ProductPage() {
  const [view, setView] = useState<View>('front')
  const [color, setColor] = useState<Color>('spruce')
  const [size, setSize] = useState<string | null>(null)
  const [quantity, setQuantity] = useState('1')
  const [sizeMissing, setSizeMissing] = useState(false)
  const id = useId()

  const colorLabel = colors.find((option) => option.value === color)?.label
  const viewLabel = views.find((option) => option.value === view)?.label

  function addToBag(event: FormEvent<HTMLFormElement>) {
    event.preventDefault()
    if (!size) {
      setSizeMissing(true)
      return
    }
    toastSuccess('Added to your bag', { description: `${quantity} × Ridgeline insulated jacket, ${colorLabel}, size ${size}` })
  }

  return (
    <article aria-labelledby={`${id}-name`} className={styles.root}>
      <div className={styles.layout}>
        <Stack gap="sm">
          <div className={styles.stage}>
            <JacketArt view={view} color={color} label={`Ridgeline insulated jacket in ${colorLabel}, ${viewLabel?.toLowerCase()}`} />
          </div>
          <div className={styles.thumbnails}>
            {views.map((option) => (
              <button
                key={option.value}
                type="button"
                aria-label={option.label}
                aria-pressed={view === option.value}
                onClick={() => setView(option.value)}
                className={styles.thumbnail}
              >
                <JacketArt view={option.value} color={color} />
              </button>
            ))}
          </div>
        </Stack>

        <Stack as="form" gap="lg" onSubmit={addToBag} aria-label="Choose options">
          <Stack gap="sm">
            <Text fontSize="xs" fontWeight="semibold" color="text-muted">
              Northfold Outfitters
            </Text>
            <Heading as="h2" id={`${id}-name`} fontSize="xl">
              Ridgeline insulated jacket
            </Heading>
            <Stack direction="row" gap="sm" align="center" wrap="wrap">
              <Stars value={rating} />
              <Link href="#product-page-reviews" fontSize="sm">
                {rating} · 214 reviews
              </Link>
            </Stack>
            <Text fontSize="xl" fontWeight="semibold">
              $248
            </Text>
            <BodySmall margin="none" color="text-muted">
              Synthetic insulation that stays warm when it’s wet, in a shell that packs into its own chest pocket.
            </BodySmall>
          </Stack>

          <fieldset className={styles.fieldset}>
            <legend className={styles.legend}>
              Color: <Text fontWeight="body">{colorLabel}</Text>
            </legend>
            <div className={styles.swatches}>
              {colors.map((option) => (
                <label key={option.value} className={styles.swatch}>
                  <input
                    type="radio"
                    name="color"
                    value={option.value}
                    checked={color === option.value}
                    onChange={() => setColor(option.value)}
                    className={styles.visuallyHidden}
                  />
                  <span aria-hidden className={`${styles.chip} ${styles[option.value]}`} />
                  <span className={styles.visuallyHidden}>{option.label}</span>
                </label>
              ))}
            </div>
          </fieldset>

          <Stack gap="sm">
            <Stack direction="row" justify="space-between" align="baseline">
              <InputLabel id={`${id}-size`}>Size</InputLabel>
              <Link href="#product-page-size-guide" fontSize="sm">
                Size guide
              </Link>
            </Stack>
            <RadioGroup
              aria-labelledby={`${id}-size`}
              aria-describedby={`${id}-size-note`}
              value={size}
              onValueChange={(value) => {
                setSize(String(value))
                setSizeMissing(false)
              }}
              dangerouslySetClassName={styles.sizes}
            >
              {sizes.map((option) => (
                <Radio key={option.value} value={option.value} disabled={!option.inStock} dangerouslySetClassName={styles.sizeInput}>
                  {option.value}
                  {!option.inStock && <span className={styles.visuallyHidden}>, sold out</span>}
                </Radio>
              ))}
            </RadioGroup>
            {sizeMissing ? (
              <BodySmall id={`${id}-size-note`} role="alert" margin="none" color="danger-text">
                Choose a size to add the jacket to your bag.
              </BodySmall>
            ) : (
              <BodySmall id={`${id}-size-note`} margin="none" color="text-muted">
                XL is sold out. Fits true to size with room for a fleece.
              </BodySmall>
            )}
          </Stack>

          <Stack direction="row" gap="md" align="end">
            <Stack gap="xs">
              <Label htmlFor={`${id}-quantity`}>Quantity</Label>
              <InputSelect id={`${id}-quantity`} size="lg" value={quantity} onChange={(event) => setQuantity(event.target.value)}>
                {['1', '2', '3', '4'].map((count) => (
                  <option key={count}>{count}</option>
                ))}
              </InputSelect>
            </Stack>
            <Button type="submit" variant="primary" size="lg" dangerouslySetClassName={styles.addToBag}>
              <ShoppingBag aria-hidden className={styles.icon} />
              Add to bag
            </Button>
          </Stack>

          <div className={styles.details}>
            {policies.map((policy) => (
              <details key={policy.title}>
                <summary>
                  {policy.title}
                  <ChevronDown aria-hidden className={styles.chevron} />
                </summary>
                <BodySmall margin="none" color="text-muted">
                  {policy.body}
                </BodySmall>
              </details>
            ))}
          </div>
        </Stack>
      </div>
    </article>
  )
}

function Stars({ value }: { value: number }) {
  return (
    <span role="img" aria-label={`Rated ${value} out of 5`} className={styles.stars}>
      {[1, 2, 3, 4, 5].map((star) => (
        <Star key={star} aria-hidden className={star <= Math.round(value) ? styles.starFilled : styles.star} />
      ))}
    </span>
  )
}

// App-owned product art. With a label it's an image; without, decoration.
function JacketArt({ view, color, label }: { view: View; color: Color; label?: string }) {
  return (
    <svg
      viewBox="0 0 160 160"
      role={label ? 'img' : undefined}
      aria-label={label}
      aria-hidden={label ? undefined : true}
      className={`${styles.art} ${styles[color]}`}
    >
      {view === 'front' && (
        <>
          <path d="M58 30 L80 38 L102 30 L128 42 L144 100 L128 106 L118 74 L118 138 Q80 144 42 138 L42 74 L32 106 L16 100 L32 42 Z" />
          <path className={styles.shade} d="M58 30 Q80 18 102 30 L96 40 Q80 33 64 40 Z" />
          <path className={styles.seam} d="M42 58 H118 M42 78 H118 M42 98 H118 M42 118 H118 M50 102 L58 120 M110 102 L102 120" />
          <path className={styles.zip} d="M80 38 V140" />
        </>
      )}
      {view === 'back' && (
        <>
          <path d="M58 30 L80 34 L102 30 L128 42 L144 100 L128 106 L118 74 L118 138 Q80 144 42 138 L42 74 L32 106 L16 100 L32 42 Z" />
          <path className={styles.shade} d="M58 32 Q80 4 102 32 Q80 44 58 32 Z" />
          <path className={styles.seam} d="M42 58 H118 M42 78 H118 M42 98 H118 M42 118 H118" />
        </>
      )}
      {view === 'detail' && (
        <>
          <rect x="12" y="12" width="136" height="136" rx="16" />
          <path className={styles.seam} d="M12 44 H148 M12 80 H148 M12 116 H148" />
          <path className={styles.teeth} d="M80 12 V148" />
          <rect className={styles.pull} x="72" y="56" width="16" height="34" rx="6" />
        </>
      )}
      {view === 'packed' && (
        <>
          <rect x="44" y="46" width="72" height="92" rx="26" />
          <path className={styles.seam} d="M48 76 H112 M46 104 H114" />
          <path className={styles.cord} d="M66 46 Q80 22 94 46" />
          <rect className={styles.pull} x="74" y="26" width="12" height="14" rx="4" />
        </>
      )}
    </svg>
  )
}
```

## How it works

- The gallery is app-owned SVG. The large view is an image with a label that names the color and the view; the thumbnails are buttons with `aria-pressed`, so the current view is announced as well as outlined.
- Color swatches are native radios in a `fieldset`. The radio is visually hidden but keeps focus and arrow keys, each swatch has the color name as hidden text, and the legend shows the chosen color in words, so color is never the only cue.
- Sizes are a `RadioGroup` drawn as tiles. XL is a disabled `Radio` whose name ends in “sold out” for screen readers, struck through on screen, and explained in the description under the group.
- Add to bag submits the form. With no size chosen it shows an alert under the sizes instead of a toast; with one, `toastSuccess` confirms the quantity, color and size.
- A container query puts the gallery beside the options once the example is 34rem wide and stacks them on a phone.

## App-owned CSS

`examples/recipes/product-page.module.css`:

```css
.root {
  container-type: inline-size;
}

/* Gallery beside the options once the example is wide enough. */
.layout {
  display: grid;
  gap: var(--ds-space-xl);
}

@container (min-width: 34rem) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}

/* Gallery */
.stage {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: var(--ds-space-xl);
  background-color: var(--ds-color-bg-subtle);
  border-radius: var(--ds-border-radius-xl);
}

.thumbnails {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--ds-space-sm);
}

.thumbnail {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: var(--ds-space-sm);
  background-color: var(--ds-color-bg-subtle);
  border: var(--ds-border-width-md) solid transparent;
  border-radius: var(--ds-border-radius-md);
  cursor: pointer;

  &:hover {
    border-color: var(--ds-color-border);
  }

  &[aria-pressed="true"] {
    border-color: var(--ds-color-accent);
  }

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-space-xs);
  }
}

/* Product art. Colors come from the fixed palette, so the jacket is the
   same color in light and dark themes. */
.art {
  width: 100%;
  height: auto;
  fill: currentColor;
}

.spruce {
  color: var(--ds-green-11);
}

.ochre {
  color: var(--ds-amber-11);
}

.glacier {
  color: var(--ds-blue-11);
}

.basalt {
  color: var(--ds-slate-12);
}

.shade {
  fill: color-mix(in srgb, currentColor 70%, var(--ds-slate-12));
}

.seam {
  fill: none;
  stroke: color-mix(in srgb, currentColor 65%, var(--ds-slate-12));
  stroke-width: 2;
  stroke-linecap: round;
}

.zip,
.cord {
  fill: none;
  stroke: var(--ds-slate-3);
  stroke-width: 2;
  stroke-linecap: round;
}

.teeth {
  fill: none;
  stroke: var(--ds-slate-3);
  stroke-width: 8;
  stroke-dasharray: 3 3;
}

.pull {
  fill: var(--ds-slate-3);
}

/* Rating */
.stars {
  display: inline-flex;
  gap: var(--ds-space-xxs);
}

.star,
.starFilled {
  width: var(--ds-icon-size-sm);
  height: var(--ds-icon-size-sm);
  color: var(--ds-color-warning);
}

.starFilled {
  fill: currentColor;
}

.star {
  color: var(--ds-color-border-strong);
}

/* Color swatches: native radios, visually hidden, with the chip as the target. */
.fieldset {
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
}

.legend {
  padding: 0;
  margin-bottom: var(--ds-space-sm);
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-md);
}

.swatch {
  position: relative;
  display: inline-flex;
  padding: var(--ds-space-xs);
  border: var(--ds-border-width-md) solid transparent;
  border-radius: var(--ds-border-radius-circle);
  cursor: pointer;

  &:has(:checked) {
    border-color: var(--ds-color-text);
  }

  &:has(:focus-visible) {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-space-xs);
  }
}

.chip {
  width: var(--ds-control-height-sm);
  height: var(--ds-control-height-sm);
  background-color: currentColor;
  /* A visible ring keeps dark swatches distinct on a dark page. */
  border: var(--ds-border-width-sm) solid var(--ds-color-border-strong);
  border-radius: var(--ds-border-radius-circle);
}

/* Sizes: a RadioGroup drawn as tiles in one row, the radio dot visually hidden. */
.root .sizes {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--ds-space-sm);
}

.root .sizes > label {
  position: relative;
  justify-content: center;
  min-height: var(--ds-control-height-lg);
  font-weight: var(--ds-font-weight-medium);
  border: var(--ds-border-width-sm) solid var(--ds-color-border);
  border-radius: var(--ds-border-radius-md);

  &:hover:not(:has([data-disabled])) {
    border-color: var(--ds-color-border-strong);
  }

  &:has([data-checked]) {
    color: var(--ds-color-accent-text);
    background-color: var(--ds-color-accent-subtle);
    border-color: var(--ds-color-accent);
  }

  &:has([data-disabled]) {
    text-decoration: line-through;
    background-color: var(--ds-color-bg-subtle);
  }

  &:has(:focus-visible) {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-space-xs);
  }
}

.visuallyHidden,
.root .sizeInput {
  position: absolute;
  width: var(--ds-space-xxs);
  height: var(--ds-space-xxs);
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.addToBag {
  flex: 1;
}

.icon {
  width: var(--ds-icon-size-sm);
  height: var(--ds-icon-size-sm);
}

/* Shipping, returns and care */
.details {
  border-top: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);

  & details {
    padding-block: var(--ds-space-md);
    border-bottom: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
  }

  /* The default disclosure triangle gives way to a chevron on the right. */
  & summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-md);
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-semibold);
    list-style: none;
    cursor: pointer;
  }

  & summary::-webkit-details-marker {
    display: none;
  }

  & summary:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: var(--ds-space-xs);
  }

  & details[open] summary {
    margin-bottom: var(--ds-space-sm);
  }
}

.chevron {
  flex-shrink: 0;
  width: var(--ds-icon-size-sm);
  height: var(--ds-icon-size-sm);
  color: var(--ds-color-text-muted);
  transition: rotate var(--ds-duration-normal) var(--ds-easing-standard);

  details[open] & {
    rotate: 180deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chevron {
    transition: none;
  }
}
```
