Back to components
ElementForm & InputFree

Content Switch React component

A switch that swaps the content below it: a pill or underline thumb slides to the chosen option, the new panel slides in from that side (or fades or blurs in), and the box eases to the new height instead of jumping.

About the Content Switch component

Content Switch is a small segmented switch with a content area under it, for flipping between a few views of the same thing, such as preview and code or monthly and yearly. Choosing an option slides its panel in from that option's side, or fades or blurs it in, and the box eases to the new content's height instead of jumping.

options takes objects with value, label, an optional icon and the content to show. value or defaultValue with onValueChange set and report the choice. variant picks pill, a filled thumb that slides behind the labels, or underline, a line that slides under them. transition picks slide, fade or blur, and align puts the switch at the start or the center. It is a tablist, so arrow keys move between options and each panel is labelled by its tab.

When to use it

Use Content Switch when a section shows one of a few alternative views of the same thing: preview / code, personal / business plans, map / list, before / after.

For full-page navigation between unrelated sections, use Tabs or real links instead.

Installation

Add the Content Switch component to your project with the shadcn CLI. It lands in components/content-switch.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/content-switch

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Floating Label Input
Free
Variant Swatches
Free
Input Group
Free
Masked Input
Free
Blockquote
Free
Basic Table
Free