本文へ移動
日本語

使い方

import { ShopProduct } from './ShopProduct.jsx'

// Without callbacks the page runs on its sample tea. Your own pictures and facts replace the drawings:
const product = {
  id: 'house-blend', name: 'House blend', kind: 'Coffee beans · medium roast', rating: 4.6, reviews: 88,
  images: [{ src: '/img/blend-bag.jpg', label: 'The bag' }, { src: '/img/blend-beans.jpg', label: 'The beans' }],
  specs: [{ icon: 'globe', label: 'Origin', value: 'Colombia' }, { icon: 'clock', label: 'Roasted', value: 'This week' }],
  sizes: [{ id: '250', label: '250 g', price: 12, note: 'about 16 cups' }, { id: '1k', label: '1 kg', price: 38, stock: 4 }],
}

<ShopProduct
  locale="en"
  currency="USD"
  freeFrom={80}
  product={product}
  soldOut={product.stock === 0}
  saved={wishlist.has(product.id)}
  bagCount={bag.count}
  loading={loading}
  error={error}
  onRetry={reload}
  onAdd={({ id, size, qty }) => bag.add(id, size, qty)}
  onSave={(id, saved) => wishlist.toggle(id, saved)}
  onNotify={(email, id) => restock.subscribe(email, id)}
  onViewBag={() => router.push('/bag')}
/>

プロパティ

プロパティ型既定値説明
locale'en' | 'zh-CN' | 'es' | 'ja''en'組み込みの文言とサンプル商品の言語。
product{ id, name, kind?, rating?, reviews?, tone?, notes?, notesLabel?, images?: Array<{ id?, src, label?, alt? }>, specs?: Array<{ icon?, label, value }>, specsLabel?, size?, sizes: Array<{ id, label, price, stock?, note?, noteIcon?, pack?: 'pouch' | 'tin' | 'big', cups? }>, brew? }sample tea商品の情報。`images` は商品画像(なければサンプルのイラスト)、`specs` はボタン下の仕様で、各項目に kit のアイコン名か独自の要素を指定できます。容量の `note` は価格の横に表示。容量ごとに価格があり、`size` は最初に選ばれる容量、`stock` が 5 以下なら残り数を表示します。サンプルの `pack`・`cups`・`brew` も引き続き使えます。
currencystringby localeすべての価格に使う ISO 通貨コード。
freeFromnumberby locale送料無料になる金額。在庫の横に表示します。
soldOutbooleanfalse売り切れとして表示し、カート追加の代わりに入荷お知らせを出します。
saved / bagCountboolean / numberfalse / 0ハートを塗った状態で始めるか、カートにすでにある点数。
loadingbooleanfalse読み込み中はスケルトンを表示します。
errorboolean | stringfalse再試行ボタン付きのエラーを表示。文字列を渡すと説明を置き換えます。
onAdd({ id, size, qty }) => Promise<void>—カートに追加します。完了までボタンが回り、完了後に確認の行が出ます。
onSave(id, saved) => void—ハートを付けた・外したとき。
onNotify(email, id) => Promise<void>—売り切れ商品の入荷お知らせ用メールを保存します。
onViewBag / onRetry() => void—追加後のカートへのリンクと、エラー表示の再試行ボタン。
labelsobject—組み込みの文言を置き換えます(キーは copy.js と同じ)。
classNamestring—ルート要素に付けます。その他の属性もルートに渡ります。

プロジェクトに追加

プロンプトを Codex や Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込むファイルを示してから、使っているコンポーネントと一緒にブロックを追加します。

ShopProduct.jsxshop-product.csscopy.jskit.jsxkit.cssui/base-button/ui/like-button/ui/rolling-number/ui/status-tag/ui/alert-banner/ui/success-check/ui/number-input/ui/radio-group/ui/rating-stars/ui/text-input/ui/skeleton-shimmer/tokens.cssREADME.md

ブロック本体、スタイルと文言、共通の kit、使っているコンポーネント、tokens.css が 1 つのフォルダにまとめて入ります。