"use client"; import * as React from "react"; import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"; import { cn } from "../lib/cn"; export interface SegmentedControlProps { /** `lang` on an option whose label is a word of another language (the * name of a language in that language): a screen reader then says it right. */ options: Array< string | { value: string; label: React.ReactNode; lang?: string } >; value: string; onChange?: (value: string) => void; /** Accessible name of the group. */ label?: string; /** Names the group by an element already on the page, instead of `label`. */ labelledBy?: string; /** md: 46px segments. sm: 36px segments with a soft shadow, for phones. */ size?: "md" | "sm"; /** The choice is shown and read out, and cannot be changed. */ disabled?: boolean; className?: string; } // The design system's SegmentedControl: one choice among two or three that // change what is shown beside it (a term, a period, a grouping). A white pill // holds the segments; the chosen one is navy with white text. // // It is a radio group: one tab stop, the arrows move the choice. For more // options, or ones that do not fit a row, use a `Select`. function SegmentedControl({ options, value, onChange, label, labelledBy, size = "md", disabled = false, className, }: SegmentedControlProps) { const small = size === "sm"; return ( {options.map((option) => { const item = typeof option === "string" ? { value: option, label: option, lang: undefined } : option; return ( {item.label} ); })} ); } export { SegmentedControl };