使い方
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' | グループ分けした 1 列か、1 ステップ 1 グループで最後に確認。 |
initialValues | object | — | レコードの現在の値。リセットで最後に保存した値に戻ります。 |
fields | { [id]: { label?, placeholder?, hint?, required? } } | — | 組み込みの文言の上に項目ごとに上書きします(渡したキーだけ)。id は name、client、description、start、due、amount、billing。 |
groups | { basics | schedule | budget: { title?, hint? } } | — | 3 つのグループ(ステップ)の見出しとヒントを個別に上書きします。 |
clients | Array<{ value, label }> | sample clients | `client` 選択肢のオプション。 |
billingOptions | Array<{ value, label, description? }> | fixed, hourly | `billing` のカード型選択肢。新規作成では最初のものが選ばれます。 |
currencySign | string | by locale | 金額の前の通貨記号(例: €)。 |
loading / error | boolean | — | 読み込み中はプレースホルダー、前回の保存が失敗したときは再試行つきの通知。 |
onSubmit | (values) => Promise<boolean | void> | — | 保存が押され、すべての項目が有効なとき。失敗したら false を返すか例外を投げます。 |
onCancel | () => void | — | キャンセルが押されたとき。 |
labels | object | — | 組み込みの文言を置き換えます(キーは copy.js と同じ)。 |
プロジェクトに追加
プロンプトを Codex や Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込むファイルを示してから、使っているコンポーネントと一緒にブロックを追加します。
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 が 1 つのフォルダにまとめて入ります。