asafefe.dev
Lab

Lab/03

Animated Tabs

One spring moves a shared-layout pill between tabs while the panels crossfade underneath.

  • Motion
  • Layout
Pick a tab

A sliding indicator that animates between tabs with a shared layout id, so the pill travels instead of snapping.

Installation

Add Animated Tab Panels to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-animated-tabs

Or by URL: https://asafefe.dev/r/lab-animated-tabs.json

Brings along

  • motion
  • utils
  • @soultel/use-reduced-motion-safe

Usage

example.tsx13 lines
import { AnimatedTabPanels } from "@/components/lab/animated-tabs"

export function Example() {
  return (
    <AnimatedTabPanels
      tabs={[
        { id: "overview", label: "Overview", content: <p>Overview panel</p> },
        { id: "activity", label: "Activity", content: <p>Activity panel</p> },
        { id: "settings", label: "Settings", content: <p>Settings panel</p> },
      ]}
    />
  )
}

Props

PropTypeDefaultDescription
tabs{ id: string; label: ReactNode; content: ReactNode }[]-Tabs and their panels.
value / defaultValuestring-Controlled or initial active tab id.
onValueChange(id: string) => void-Called when the tab changes.
dotbooleantrueSmall dot next to the active label.
listClassName / panelClassNamestring-Classes for the tab list and the panel.