import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@godxjp/ui/data-display"; import { FormField, Slider } from "@godxjp/ui/data-entry"; import { Flex, PageContainer, ResponsiveGrid } from "@godxjp/ui/layout"; import { Text } from "@godxjp/ui/general"; /** * Slider — react-aria-components underneath, the antd 6 API on top. * `value` is a plain number for one thumb and an array for a `range`; the Radix-era * `number[]` + `onValueChange` spelling still compiles and still works. * Use `onChange` for live UI and `onChangeComplete` for the expensive work. * Composed only from real @godxjp/ui components. */ const yen = (value: number) => new Intl.NumberFormat("ja-JP", { style: "currency", currency: "JPY" }).format(value); export default function Demo() { const [taxRate, setTaxRate] = useState(10); const [amountRange, setAmountRange] = useState([50000, 300000]); const [committedRange, setCommittedRange] = useState([50000, 300000]); const [plan, setPlan] = useState(30); const [allocation, setAllocation] = useState([40]); const [bands, setBands] = useState([25, 60]); const [volume, setVolume] = useState(60); return ( 単一スライダー · 税率設定 antd と同じ書き味: value に数値を渡し、onChange が数値を返す。tooltip.formatter は 吹き出しの表記であると同時に読み上げ (aria-valuetext) にもなる。 `${value}%` }} /> レンジスライダー · 請求金額フィルタ range を明示すると、値が未到着でも [min, max] の 2 つのつまみで描画される。 再取得のような重い処理は onChangeComplete に置く。 確定値 (onChangeComplete): {yen(committedRange[0])} 〜 {yen(committedRange[1])} 目盛りだけを値にする · step={"{null}"} marks と step={"{null}"} を組み合わせると、つまみは目盛り・min・max にしか止まらない。 dots は目盛りごとの点で、included の範囲内だけが濃くなる。 予算配分 · Radix 時代の書き方も有効 number[] の value と onValueChange / onValueCommit はそのまま動く。name を付ければ JavaScript なしでフォーム送信できる (つまみが複数なら name[])。 編集できるレンジ · range={"{{ editable: true }}"} レール上を押すとつまみが増え、Delete / Backspace で減る (minCount 〜 maxCount)。 included=false は「ここまで」を塗らない目盛り専用のレール。 縦・逆向き・無効 vertical は下が min、reverse は向きを入れ替える (矢印キーも一緒に反転)。 disabled は配列でつまみ単位にもできる。 ); }