Animated Tab
Animated Tab is a React and Tailwind CSS navigation component from Bund UI, licensed MIT. Copy it and paste it into your project.
Bund UI
MIT
navigation
What it is
Animated Tab is a React and Tailwind CSS navigation component from Bund UI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion
Licence
This component comes from Bund UI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Animated Tab
"use client";
import React, { useState } from "react";
import { motion, AnimatePresence } from "motion/react";
type AnimatedTab = {
name: string;
content: React.ReactNode | string;
};
export function AnimatedTab({ tabs }: { tabs: AnimatedTab[] }) {
const [selected, setSelected] = useState(0);
const duration = 0.3;
const handleSelect = (index: number) => {
setSelected(index);
};
return (
<div className="mx-auto w-full max-w-md">
{/* Tab Buttons */}
<div className="relative mb-4 flex">
{tabs.map(({ name }, i) => (
<motion.div
key={i}
className="relative cursor-pointer px-4 py-1"
transition={{ duration }}
onClick={() => handleSelect(i)}>
<span className="relative z-10">{name}</span>
{i === selected && (
<motion.div
className="bg-muted absolute top-0 left-0 h-full w-full rounded-xl"
layoutId="selected"
transition={{ duration }}
/>
)}
</motion.div>
))}
</div>
{/* Tab Content */}
<div className="relative h-32">
<AnimatePresence mode="wait">
<motion.div
key={selected}
className="bg-muted absolute inset-0 rounded-xl p-4"
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
transition={{ duration: 0.3 }}>
{tabs[selected].content}
</motion.div>
</AnimatePresence>
</div>
</div>
);
}
import { AnimatedTab } from "./animated-tab";
import { Button } from "@/components/ui/button";
export default function AnimatedTabExample() {
return (
<AnimatedTab
tabs={[
{
name: "Overview",
content: "This is the overview tab content."
},
{
name: "Reviews",
content: (
<div>
<p>This is the reviews tab content.</p>
<Button>Go it!</Button>
</div>
)
},
{
name: "Details",
content: "This is the details tab content."
},
{
name: "Feedback",
content: "This is the feedback tab content."
}
]}
/>
);
}