Option Chooser
A radio group of chips for finishes, packs and sizes, with optional colour swatches, a hint line and a note under the chips.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/option-chooser.jsonFinish: Natural oak
In stockships in 2 to 4 days
Pack size: 6 pack
Eggs are packed the morning of delivery.
Usage
option-chooser-example.tsx
"use client";
import { useState } from "react";
import { OptionChooser, StockBadge } from "@dbs/ui";
const FINISHES = [
{ id: "oak", label: "Natural oak", hint: "Included", swatch: "#c9a574" },
{ id: "walnut", label: "Walnut", hint: "+200 MAD", swatch: "#5b3a29" },
{ id: "ash", label: "Black ash", hint: "+200 MAD · Made to order", swatch: "#2b2b2b" },
];
const PACKS = [
{ id: "p6", label: "6 pack", hint: "48 MAD" },
{ id: "p12", label: "12 pack", hint: "88 MAD" },
{ id: "p24", label: "24 pack", hint: "160 MAD · Low stock" },
];
export default function OptionChooserExample() {
const [finish, setFinish] = useState("oak");
const [pack, setPack] = useState("p6");
return (
<div className="flex w-full max-w-md flex-col gap-8">
<div>
<OptionChooser label="Finish" valueLabel={FINISHES.find((f) => f.id === finish)?.label} options={FINISHES} value={finish} onChange={setFinish} />
<StockBadge className="mt-4" status={finish === "ash" ? "made-to-order" : "in-stock"} detail={finish === "ash" ? "about 3 weeks" : "ships in 2 to 4 days"} />
</div>
<OptionChooser label="Pack size" valueLabel={PACKS.find((p) => p.id === pack)?.label} options={PACKS} value={pack} onChange={setPack} note="Eggs are packed the morning of delivery." />
</div>
);
}