Skip to content

Product and order

Screens for the shopper: a product detail page and an order detail with delivery progress.

Installation & usage

npx @youj/cli add commerce-product-detail

Also installs accordion, async-button, badge, breadcrumb, card, carousel, commerce-product-card, commerce-product-render, field, icon-heart, icon-rotate-ccw, icon-ruler, icon-shopping-cart, icon-star, icon-store, icon-truck, number-input, toggle, typography, youj-presets, youj-ui-core.

The CLI copies the block to blocks/commerce/product-detail.tsx with every component it uses, so it’s yours to edit.

Every prop is optional and falls back to the demo, so it renders as you see it until you pass your own. Give it your data, rewrite or translate its strings through copy, and connect its actions:

productDetail-view.tsx
'use client'

import Link from 'next/link'
import { ProductDetail, type ProductDetailProps } from '@/blocks/commerce/product-detail'

export function ProductDetailView({ product, breadcrumbs, perks, sections }: Pick<ProductDetailProps, 'product' | 'breadcrumbs' | 'perks' | 'sections'>) {
  return (
    <ProductDetail
      product={product}
      breadcrumbs={breadcrumbs}
      perks={perks}
      sections={sections}
      copy={{ breadcrumb: 'Shop' }}
      linkComponent={Link}
      onAddToCart={async (line) => {
        // await your API here; the block shows progress until it settles
      }}
      onSave={(product, saved) => {
        // your code
      }}
    />
  )
}

Reference

Props12 props, 3 types

Props

ProductDetail props
PropType
productProduct

The product; required in practice.

default a sample kettle (swap in yours)

a sample kettle (swap in yours)
onAddToCart(line: { product: Product; color: string; size?: string; quantity: number }) => Promise<unknown>

Resolve once the line is in the cart; reject to shake the button. color is the colorway's id.

default a short demo wait

a short demo wait
onSave(product: Product, saved: boolean) => void

Hears "Save for later" being turned on or off.

–
breadcrumbs{ label: string; href: string; }[]

The trail above the title, as links. Default: Shop › the product's category.

–
sizeGuideHrefstring | null

The size guide's page; null hides the link.

default '#size-guide'

'#size-guide'
perksProductPerk[]

The delivery panel's lines. Default: free delivery (arriving three working days from today), pickup and returns.

–
sectionsProductSection[]

The folds at the foot. Default: details, shipping and returns.

–
todayDate | number

Today, for the delivery day.

default the demo's day

the demo's day
currencystring

An ISO 4217 code.

default 'USD'

'USD'
localestring

A BCP 47 locale for prices, dates and counts.

default 'en-US'

'en-US'
linkComponentElementType

Renders breadcrumb and size-guide links, e.g. Next.js Link.

default 'a'

'a'
copyPartial<ProductDetailCopy>

Any of the page's strings, to rewrite or translate.

–

Product

Product props
PropType
idRequiredstring–
nameRequiredstring–
imagestring

A photo's URL: it pictures the product (a colorway's own image wins).

–
anglestring

The product from its other side; hover and keyboard focus turn to it.

–
focusreadonly [number, number]

Where the product sits in its photos, in percent from the top start: a crop of another shape keeps it in frame.

default `[50, 50]`

`[50, 50]`
hrefstring

The product's page.

default `#<id>`

`#<id>`
categoryRequiredstring–
priceRequirednumber–
compareAtnumber–
ratingRequirednumber–
reviewsRequirednumber–
badgestring–
colorsRequiredColorway[]

The colorways it's sold in; the first is the default.

–
sizesstring[]–
soldOutstring[]

Sizes out of stock right now.

–
descriptionRequiredstring–

ProductPerk

ProductPerk props
PropType
iconRequiredComponentType<{ size?: number }>–
titleRequiredstring–
detailRequiredstring–

ProductSection

ProductSection props
PropType
idRequiredstring–
titleRequiredstring–
bodyRequiredReactNode–
Strings32 keys for copy

Strings

copy takes any of these keys; the rest keep their defaults. A key whose text holds a value (a count, a name) takes a function.

breadcrumbphotosviewsslidethumbratedreviewseachwasnowcolorsizesizeGuidesoldOutquantityaddToCartaddingaddedaddErrorsavefreeDeliveryarrivespickUppickUpDetailreturnsreturnsDetaildetailsdetailsBodyshippingshippingBodyreturnsTitlereturnsBody
Built from10 components, 1 blocks
Accessibilityheadings, controls, dialogs

Accessibility

Product detail has one h1. The size choices are radio inputs with a label each (a sold-out size says so in its label), the gallery is a labelled carousel whose slides are labelled by position, and the rating is read as text. Order detail is a main under a header with labelled sections for items, details and shipment, and the shipment progress is a list with a status region. The return flow opens in a dialog that closes with Escape, and row actions sit in a menu with arrow-key navigation. Links and buttons are real a and button elements with the kit’s focus ring.