Animated Tabs
NewInstallation
npx shadcn@latest add https://uibrik.com/r/animated-tabs.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/animated-tabs/animated-tabs.tsx"use client"; import { useId, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import { AnimatePresence, MotionConfig, motion } from "motion/react"; import { cn } from "@/lib/utils"; // Animated tabs. The indicator (an underline or a pill) springs from tab to // tab, and a soft highlight follows the pointer across the ones it passes. // The new panel slides in from the side you moved toward while the old one // leaves the other way, so the direction of travel is always readable, and // the panel area eases to the new panel's height instead of jumping. // // Follows the tabs pattern: arrows, Home and End move between tabs and show // each as they go, and only the tab that's showing is a Tab stop. export type AnimatedTab = { value: string; label: ReactNode; icon?: ReactNode; /** The panel shown while this tab is selected. */ content: ReactNode; disabled?: boolean; };
Adds the files to
components/uibrik/animated-tabs and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/animated-tabs.Props
AnimatedTabs- variant
- Type "underline" | "pill"
- "underline"
- A line under the selected tab, or a filled shape behind it.
- hover
- Type boolean
- true
- A highlight that follows the pointer across the tabs.
- duration
- Type number
- 0.4
- How long the indicator and panels take to move.
- slide
- Type number
- 24
- How far a panel slides on its way in or out. 0 cross-fades.
- tabsrequired
- Type { value; label; icon?; content; disabled? }[]
- –
- Tabs in order, each with the panel it shows.
- value / onChange
- Type string / (value) => void
- –
- Controlled selection.
- defaultValue
- Type string
- –
- Selected tab on mount when uncontrolled. Defaults to the first.
- label
- Type string
- –
- Names the tab list for screen readers.
- className
- Type string
- –
- Classes for the wrapper.
- panelClassName
- Type string
- –
- Classes for each panel.