SegmentedControl

Radio group as a sliding pill. One pill glides between segments; arrow keys move and select. Inputs.

Open playground

About

SegmentedControl is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { SegmentedControl } from "@ashutoshswamy/smoui" and set options, value, defaultValue among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { SegmentedControl } from "@ashutoshswamy/smoui";

<SegmentedControl
  label="View"
  options={[{ value: "day", label: "Day" }, { value: "week", label: "Week" }]}
  onChange={setView}
/>

Props 5

options

Segments.

{ value: string; label: string }[]
value

Controlled value.

string
defaultValue

Initial value when uncontrolled. Defaults to the first option.

string
onChange

Called on change.

(value: string) => void
label

Accessible name.

string