跳到正文
简体中文

用法

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

// Edit an existing record in one column, or create a new one in steps with a review:
<FormPage
  locale="en"
  mode={project ? 'single' : 'steps'}
  initialValues={project ?? undefined}   // { name, client, description, start, due, amount, billing }
  // Optional: the same fields for another record, renamed one key at a time.
  fields={{ name: { label: 'Roast name', placeholder: 'e.g. Ethiopia Guji' }, client: { label: 'Origin', placeholder: 'Choose an origin' } }}
  groups={{ budget: { title: 'Price', hint: 'Per bag, before tax.' } }}
  clients={[{ value: 'eth', label: 'Ethiopia' }, { value: 'col', label: 'Colombia' }]}
  billingOptions={[{ value: 'bag', label: 'Per bag' }, { value: 'sub', label: 'Subscription' }]}
  currencySign="€"
  onSubmit={async (values) => {
    const response = await fetch('/api/projects', { method: 'POST', body: JSON.stringify(values) })
    return response.ok                   // false keeps every value and shows "Couldn't save"
  }}
  onCancel={() => router.back()}
/>

属性

属性类型默认值作用
locale'en' | 'zh-CN' | 'es' | 'ja''en'内置文字和示例数据的语言。
mode'single' | 'steps''single'单列分组,或每组一步、最后核对。
initialValuesobject—记录当前的值。“重置”回到最近一次保存的值。
fields{ [id]: { label?, placeholder?, hint?, required? } }—逐个字段覆盖内置文字(只改给出的键);字段 id 为 name、client、description、start、due、amount、billing。
groups{ basics | schedule | budget: { title?, hint? } }—逐个覆盖三个分组(也是三个步骤)的标题和提示。
clientsArray<{ value, label }>sample clients`client` 下拉框的选项。
billingOptionsArray<{ value, label, description? }>fixed, hourly`billing` 单选卡片的选项;新建时默认选中第一个。
currencySignstringby locale金额前的货币符号,例如 €。
loading / errorboolean—记录加载中显示占位;上次保存失败时显示提示和重试。
onSubmit(values) => Promise<boolean | void>—点击保存且所有字段有效时调用。保存失败时返回 false 或抛出错误。
onCancel() => void—点击取消时调用。
labelsobject—替换任意内置文字(键名见 copy.js)。

装进你的项目

把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。

FormPage.jsxform-page.csscopy.jskit.jsxkit.cssui/base-button/ui/alert-banner/ui/radio-group/ui/select/ui/text-input/ui/textarea/ui/skeleton-shimmer/ui/step-progress/tokens.cssREADME.md

区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。