Please use Desktop to view and interact with components
Components300msspring
Animated Tabs
Tabs with sliding indicator animation
tabsnavigationslideshadcn
Useto navigate between components
Preview
Account settings content goes here
This component requires shadcn/ui
This component uses shadcn/ui components. Make sure you have shadcn/ui set up in your project.
- Install shadcn/ui:
npx shadcn-ui@latest init - Install required components based on the imports in the code (e.g.,
npx shadcn-ui@latest add button) - Ensure your
tailwind.config.tsandglobals.cssare configured as per shadcn/ui documentation
Code
TypeScript + React
'use client'
import { motion } from 'framer-motion'
import { useState } from 'react'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
export function AnimatedTabs() {
const tabs = ['Account', 'Password', 'Settings']
const [activeTab, setActiveTab] = useState(tabs[0])
return (
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-[400px]">
<TabsList className="relative grid w-full grid-cols-3">
{tabs.map((tab) => (
<TabsTrigger
key={tab}
value={tab}
className="relative z-10"
>
{tab}
</TabsTrigger>
))}
<motion.div
layoutId="activeTab"
className="absolute h-8 rounded-sm bg-[var(--card-bg)] shadow-sm"
initial={false}
animate={{
x: tabs.indexOf(activeTab) * 133.33,
width: 133.33,
}}
transition={{ type: 'spring', stiffness: 300, damping: 30 }}
/>
</TabsList>
{tabs.map((tab) => (
<TabsContent key={tab} value={tab} className="mt-4">
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
className="rounded-lg border p-4"
>
<p className="text-sm">{tab} settings content goes here</p>
</motion.div>
</TabsContent>
))}
</Tabs>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Set up shadcn/ui: Install shadcn/ui components used in this code. Check the imports in the code above and install the required components (e.g.,
npx shadcn-ui@latest add button card) - 3Copy the code from above
- 4Paste it into your project and customize as needed
- 5Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file