tapcn
Components

Segmented Control

An iOS-style segmented control for switching between options.

Day
Week
Month

Segmented Control

An iOS-style segmented control that allows users to switch between a set of mutually exclusive options. Features a smooth animated indicator that slides between segments.

Installation

npx @tapcn/cli add segmented-control

Or using shadcn directly:

npx shadcn@latest add https://tapcn.vercel.app/r/segmented-control.json

Usage

import { SegmentedControl } from '~/components/ui/segmented-control';
import * as React from 'react';

export function SegmentedControlExample() {
  const [selectedIndex, setSelectedIndex] = React.useState(0);

  return (
    <SegmentedControl
      segments={['Daily', 'Weekly', 'Monthly']}
      selectedIndex={selectedIndex}
      onIndexChange={setSelectedIndex}
    />
  );
}

Props

PropTypeDefaultDescription
segmentsstring[]-Array of segment labels to display.
selectedIndexnumber-The index of the currently selected segment.
onIndexChange(index: number) => void-Callback fired when a segment is selected.
classNamestring-Additional CSS classes for the container.

Dependencies

  • react-native-reanimated

On this page