View Switch

Switches between views of the same data, like list and board, with icons only. Built on ui-sdk's SegmentedControl: Tab reaches the chosen view and the arrow keys move it, and the white segment slides across. For choices in forms and filters, use SegmentedControl.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { ViewSwitch } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

size

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it to switch between views of the same data, like opportunities as a list or a board, or a chart as bars or a pie.
DoGive every option a label that names the view, like List or Board. The segment shows only the icon, so the label is its accessible name.
DoName the whole switch with aria-label, like View, and use xs in section headers and sm everywhere else.
Don'tUse it for choices in forms and filters, like open or closed matters. Use SegmentedControl, whose segments carry text.

Props

Also takes ui-sdk's SegmentedControl props: value, defaultValue, onValueChange, disabled, readOnly, name and loop.

PropTypeDefaultDescription
options *ViewSwitchOption<T>[]—The views: value, label (its accessible name) and icon.
size"sm" | "xs""sm"sm (32 px) by default; xs (28 px) in section headers.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import { ViewSwitch } from "@leap-crm/design-system";

<ViewSwitch options={views} defaultValue="list" aria-label="View" />

More views

Any number of views: here a chart switches between bar and pie.

Disabled

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { ChartBar, ChartPie, SquareKanban, TableOfContents } from "lucide-react";

import { ViewSwitch } from "@leap-crm/design-system";

const views = [
  { value: "list", label: "List", icon: <TableOfContents /> },
  { value: "board", label: "Board", icon: <SquareKanban /> },
];

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TabLands on the chosen view, and the next Tab leaves.
Arrow keysChoose the next view, wrapping at the ends.