import { useState } from "react"; import { CircleHelp } from "lucide-react"; import { Badge, Card, CardContent, CardDescription, CardHeader, CardTitle, ListRow, } from "@godxjp/ui/data-display"; import { Field, Label, Switch } from "@godxjp/ui/data-entry"; import { Tooltip, TooltipContent, TooltipTrigger } from "@godxjp/ui/feedback"; import { Button, Icon } from "@godxjp/ui/general"; import { Flex, PageContainer } from "@godxjp/ui/layout"; /** * Switch — a boolean toggle. Wrap in Field (NOT FormField) for a labelled row * with the hidden form input + description; put it in ListRow's `trailing` when * the settings row wants the toggle at the END of the line. Composed only from * real @godxjp/ui components. */ export default function Demo() { // 公開設定は保存に往復が要る。loading 中のトグルは値を変えずに要求だけを拒否する。 const [published, setPublished] = useState(false); const [saving, setSaving] = useState(false); const savePublished = (next: boolean) => { setSaving(true); window.setTimeout(() => { setPublished(next); setSaving(false); }, 1200); }; return ( Labelled rows (Field) Field owns the label, description, and form input. 設定セクション · ListRow の trailing に置く 設定画面の1行は「見出しと説明が左、トグルが右端」。Field は制御を先頭に置くので この並びにはならない。ListRow の trailing に Switch を入れ、title を Label htmlFor にして紐づける。これが無いと、行ごとにトグル位置が揃わず目で追えなくなる。 二要素認証} description="ログイン時にワンタイムコードの入力を求めます。" trailing={} /> レシート OCR ベータ } description="添付画像から金額と日付を読み取って仕訳の下書きを作ります。" trailing={} /> 取引先ポータルへの公開} description="保存に数秒かかります。通信中は loading のまま操作を受け付けません。" trailing={ } /> 会計期間のロック} description="決算確定済みのため解除できません。管理者に依頼してください。" trailing={} /> ラベルの長さ · 2文字と3行が同じ列に並ぶ 同じ設定群に2文字の見出しと3行に折り返す見出しが混ざる。つまみが1行目の中心に 留まるかはここでしか分からない。揃っていないと、長い行だけトグルが沈んで見える。 状態の一覧 オフ / オン / 無効 / 無効かつオン / 保存中 / 不正。readOnly と indeterminate は Switch に存在しない。読み取り専用は disabled で表し、中間状態が要るなら Checkbox の indeterminate を使う。どれが操作できる行なのか、並べないと判別できない。 {/* 不正状態は Field の error スロットが持つ。role=alert のメッセージを出し、 制御に aria-invalid / aria-errormessage / aria-describedby を配線する。 description と error は競合せず、上下に積む。 */} ラベル脇の補助 · labelAddon Badge のような非対話の印は label に直接置ける。押せる補助は labelAddon に渡す。 label は制御を指す本物の <label htmlFor> なので、その中に入れたボタンは 押した瞬間にトグルを反転させる。labelAddon は label の外の兄弟として行内に並ぶ。 {/* 非対話の addon は label の中で足りる。Label は ui-label の gap を持つ。 */} 自動仕訳 ベータ } description="学習済みの仕訳パターンから勘定科目を推定します" > {/* 押せる補助は labelAddon。label の外にあるので押してもトグルは動かない。 */} 税率は支払先の区分と支払額から決まります。確定値は請求書の明細に残ります。 } > size · sm / md sm は一覧行やツールバーなど密度の高い場所、md (既定) は設定画面の行に使う。 Ant Design axes · loading, checkedChildren loading は通信中の状態です。disabled ではなく aria-busy / aria-disabled を使います。disabled はタブ順から外れるため、保存中にキーボードの フォーカスが次の項目へ飛んでしまうからです。 ); }