Skip to content

Segmented Control

One choice out of a few, always one selected (a click on the selected segment does nothing).

Base UI3.0 kB gzipSource Registry JSON

Range

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/segmented-control.json

The CLI writes components/ikada/segmented-control.tsx and merges the ikada theme into your CSS. Or take it from the package: import { SegmentedControl } from "@sproutboat/ikada";

Usage

import { SegmentedControl } from "@/components/ikada/segmented-control";

const ranges = [
  { value: "1h", label: "1h" },
  { value: "24h", label: "24h" },
  { value: "7d", label: "7d" },
  { value: "30d", label: "30d" },
];

const [value, setValue] = useState("24h");

<SegmentedControl aria-label="Range" options={ranges} value={value} onValueChange={setValue} />

Examples

Range

One raised pebble on a recessed tray slides to the choice on the snappy spring.

Small

Props

SegmentedControlProps
PropTypeDescription
optionsrequiredreadonly SegmentedOption<T>[]The segments, in order: value and label.
valuerequiredstringThe chosen segment's value (controlled).
onValueChangerequired(value: T) => voidCalled with the newly chosen value.
aria-labelrequiredstringNames the group, e.g. "Theme". Required.
size"sm" | "md"Control height: sm or md (the default).
classNamestringClasses merged onto the root element, after ikada's own.

Also takes every prop of <T extends string = string>.

Source: src/components/segmented-control.tsx