export type SegmentedControlSize = "content" | "equal"; export type SegmentedControlWidth = "inline" | "fill"; export type SegmentedControlOption = { id: TValue; label: React.ReactNode; disabled?: boolean; title?: string; ariaLabel?: string; }; export type SegmentedControlProps = { options: Array>; value: TValue; onChange: (value: TValue) => void; ariaLabel?: string; ariaLabelledBy?: string; className?: string; optionClassName?: string; disabled?: boolean; role?: "group" | "tablist"; size?: SegmentedControlSize; width?: SegmentedControlWidth; }; export default function SegmentedControl({ options, value, onChange, ariaLabel, ariaLabelledBy, className = "", optionClassName = "", disabled = false, role = "tablist", size = "content", width = "inline" }: SegmentedControlProps) { const rootClassName = [ "segmented-control", `segmented-control-size-${size}`, `segmented-control-width-${width}`, className ].filter(Boolean).join(" "); const optionRole = role === "tablist" ? "tab" : undefined; return (
{options.map((option) => { const selected = option.id === value; const buttonClassName = [ "segmented-control-option", selected ? "is-active" : "", optionClassName ].filter(Boolean).join(" "); return ( ); })}
); }