klyv-ui

Segmented Control

Component

About

A pill-shaped single-select control for switching between a small set of options, built as an accessible radiogroup with roving arrow-key focus.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Segmented Control to your project and fits it to your theme.

Code

How Segmented Control is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import SegmentedControl, {
  type SegmentedOption,
} from "@/components/ui/segmented-control";
import { useState } from "react";
import { Rows3, AlignJustify, LayoutGrid } from "lucide-react";

type Density = "compact" | "comfortable" | "grid";

const options: SegmentedOption<Density>[] = [
  { value: "compact", label: "Compact", icon: Rows3 },
  { value: "comfortable", label: "Comfortable", icon: AlignJustify },
  { value: "grid", label: "Grid", icon: LayoutGrid },
];

export default function SegmentedControlIconDemo() {
  const [density, setDensity] = useState<Density>("comfortable");

  return (
    <div className="flex min-h-[200px] w-full items-center justify-center bg-background p-10">
      <div className="w-full max-w-sm rounded-full border border-line bg-surface p-1 shadow-[var(--shadow-tile)]">
        <SegmentedControl
          options={options}
          value={density}
          onValueChange={setDensity}
          label="Density"
          bare
          fullWidth
        />
      </div>
    </div>
  );
}

More by klyv-ui

View all
  • Gantt Chart

    Gantt Chart

    63
  • Klyv Animated Beam

    Klyv Animated Beam

    50
  • Shader Canvas

    Shader Canvas

    49
  • Pareto Chart

    Pareto Chart

    44
  • Gooey Loader

    Gooey Loader

    26
  • Sunburst Chart

    Sunburst Chart

    24
  • Fluid Canvas

    Fluid Canvas

    23
  • Morphing Text

    Morphing Text

    21