Segmented control

A pill that slides to the chosen segment, its width leading its position.

Features

  • A pill that slides to the chosen segment, its width leading its position.

Use it for

  • View switches.
  • Small filters.

Installation

  1. Get runets.
    git clone https://github.com/ziyam-khan/runets
  2. Copy these files into your project, keeping their folders.
  3. Install what they use.
    pnpm add react motion
  4. Load the styles once. Bring your own base tokens, or use runets’ default theme.
    import 'runets/styles/theme.css'
    import 'runets/styles/kit.css'

Usage

import { SegmentedControl } from 'runets'

<SegmentedControl label="View" value={v} onValueChange={setV} options={[['list', 'List'], ['grid', 'Grid']]} />

API

PropTypeWhat it does
valuestringChosen segment.
onValueChange(v) => voidCalled on change.
options[id, label][]Segments.

Accessibility

Source

The code is in src/kit/controls.tsx in runets, MIT licensed.