用法
import { ShopGrid } from './ShopGrid.jsx'
// Without callbacks the grid runs on its sample shelf. Wire it to your shop:
<ShopGrid
locale="en"
currency="USD"
items={catalog.products} // [{ id, type, name, notes, price, was, rating, reviews, stock, badge, image }]
categories={[{ id: 'beans', label: 'Beans' }, { id: 'gear', label: 'Brewing gear' }]}
saved={wishlist.ids}
bagCount={bag.count}
loading={catalog.loading}
error={catalog.error}
onRetry={catalog.reload}
onAdd={(product) => bag.add(product.id)}
onSave={(id, saved) => wishlist.toggle(id, saved)}
onOpenBag={() => router.push('/bag')}
/>属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文字和示例货架的语言。 |
items | Array<{ id, type, name, notes?, price, was?, rating?, reviews?, stock?, badge?: 'new' | 'sale', image?, art?, tone? }> | sample shelf | 商品列表。`type` 把商品归入 `categories` 里的某一类,用来生成分类标签;`image` 是商品图片(不传时画一个素色盒子);有 `was` 时显示划线价和折扣;`stock` 不超过 5 时提示库存紧张。 |
categories | Array<{ id, label }> | labels.types, then any other type on the shelf | 分类标签及其顺序。只显示货架上有商品的分类,并附上数量。 |
currency | string | by locale | 所有价格使用的 ISO 货币代码。 |
saved | string[] | [] | 已收藏的商品 id,对应的心形一开始就是实心。 |
bagCount | number | 0 | 购物袋里已有的件数,显示在购物袋按钮上。 |
loading | boolean | false | 加载时显示骨架卡片。 |
error | boolean | string | false | 显示带重试按钮的错误提示;传字符串可替换说明。 |
onAdd | (item) => Promise<void> | — | 一键加购。卡片按钮会转圈直到完成,然后显示对勾。 |
onSave | (id, saved) => void | — | 收藏或取消收藏时调用。 |
onOpenBag / onRetry | () => void | — | 分别对应购物袋按钮和错误提示里的重试按钮。 |
labels | object | — | 替换任意内置文字(键名见 copy.js),包括分类名称。 |
className | string | — | 加在根元素上;其他属性也会传给根元素。 |
装进你的项目
把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。
ShopGrid.jsxshop-grid.csscopy.jskit.jsxkit.cssui/base-button/ui/like-button/ui/empty-state/ui/status-tag/ui/alert-banner/ui/rating-stars/ui/select/ui/text-input/ui/skeleton-shimmer/ui/sliding-tabs/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。