Lab/03
Animated Tabs
One spring moves a shared-layout pill between tabs while the panels crossfade underneath.
- Motion
- Layout
Pick a tab
lab/animated-tabsA 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-tabsOr by URL: https://asafefe.dev/r/lab-animated-tabs.json
Brings along
- motion
- utils
- @soultel/use-reduced-motion-safe
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| tabs | { id: string; label: ReactNode; content: ReactNode }[] | - | Tabs and their panels. |
| value / defaultValue | string | - | Controlled or initial active tab id. |
| onValueChange | (id: string) => void | - | Called when the tab changes. |
| dot | boolean | true | Small dot next to the active label. |
| listClassName / panelClassName | string | - | Classes for the tab list and the panel. |
