Discrete Tabs Free React component
Compact icon tabs: the active one widens to reveal its label while the others shrink back to icons, with a springy width animation.
Original component by Watermelon UI · MIT licence
Get the code
npx shadcn@latest add https://registry.watermelon.sh/r/discrete-tabs.jsonInstalls from the Watermelon UI registry through the shadcn CLI. Needs Tailwind CSS and the motion package, which the command adds for you.
import { DiscreteTabs } from '../discrete-tabs';
import { FaBell } from 'react-icons/fa6';
import { HiCalendarDays } from 'react-icons/hi2';
import { MdMailOutline } from 'react-icons/md';
const tabs = [
{
id: 'mail',
icon: <MdMailOutline size={24} />,
label: 'Inbox',
activeColor: 'text-blue-500',
},
{
id: 'planner',
icon: <HiCalendarDays size={24} />,
label: 'Planner',
activeColor: 'text-yellow-500',
},
{
id: 'mail2',
icon: <FaBell size={24} />,
label: 'Alerts',
activeColor: 'text-red-500',
},
];
function DiscreteTabsDemo() {
return (
<div className="flex flex-col items-center justify-center gap-10 bg-transparent p-10">
<DiscreteTabs tabs={tabs} defaultTab="mail" />
</div>
);
}
export default DiscreteTabsDemo;
// discrete-tabs, from Watermelon UI: https://ui.watermelon.sh/animated-components/discrete-tabs
// MIT License. Copyright (c) 2025-present Watermelon Contributors.
"use client";
import { useState, useEffect, type FC, type ReactNode } from "react";
import { motion, AnimatePresence } from "motion/react";
interface TabItem {
id: string;
icon: ReactNode;
label: string;
activeColor: string;
}
interface DiscreteTabsProps {
tabs: TabItem[];
onTabChange?: (tabId: string) => void;
defaultTab?: string;
}
export const DiscreteTabs: FC<DiscreteTabsProps> = ({ tabs, onTabChange, defaultTab }) => {
const [activeTab, setActiveTab] = useState<string>(defaultTab || tabs[0]?.id);
const [shine, setShine] = useState<boolean>(false);
const handleTabClick = (tabId: string) => {
setActiveTab(tabId);
if (onTabChange) onTabChange(tabId);
};
useEffect(() => {
const timer = setTimeout(() => setShine(true), 600);
return () => {
clearTimeout(timer);
setShine(false);
};
}, [activeTab]);
return (
<div className="flex items-center justify-center gap-2 rounded-full py-6 overflow-hidden w-fit mx-auto">
{tabs.map((tab) => {
const isActive = tab.id === activeTab;
return (
<button
key={tab.id}
onClick={() => handleTabClick(tab.id)}
className="relative focus:outline-none"
>
<motion.div
layout="position"
transition={{ type: "spring", stiffness: 210, damping: 18, mass: 1 }}
className={`relative flex h-16 ${isActive ? "w-40" : "w-full"} items-center justify-center`}
>
{isActive && (
<motion.div
layoutId="activeBg"
className="absolute inset-0 rounded-full bg-white dark:bg-zinc-800 shadow-md"
transition={{ type: "spring", stiffness: 220, damping: 26 }}
/>
)}
<div className="relative z-10 flex items-center gap-1 pr-3 cursor-pointer">
<motion.div
animate={{ scale: isActive ? 1.08 : 1 }}
className={`flex h-14 w-14 items-center justify-center rounded-full ${
isActive ? tab.activeColor : "bg-white dark:bg-zinc-900 text-gray-800"
}`}
>
{tab.icon}
</motion.div>
<motion.span
animate={{ width: isActive ? "auto" : 0, opacity: isActive ? 1 : 0 }}
className={`relative overflow-hidden whitespace-nowrap text-xl font-semibold ${
isActive ? tab.activeColor : "text-black dark:text-white"
}`}
>
{tab.label}
<AnimatePresence>
{isActive && shine && (
<motion.span
initial={{ left: "-120%" }}
animate={{ left: "120%" }}
className="absolute top-0 bottom-0 w-16 bg-gradient-to-r from-transparent via-white/60 to-transparent"
/>
)}
</AnimatePresence>
</motion.span>
</div>
</motion.div>
</button>
);
})}
</div>
);
};Paste this into Claude, ChatGPT, Cursor, Lovable or v0 to build it from scratch.
Build a React component called "Discrete Tabs" with Tailwind CSS and Motion (motion/react). Compact icon tabs: the active one widens to reveal its label while the others shrink back to icons, with a springy width animation. Use spring transitions, keep it accessible with keyboard focus and aria labels, respect prefers-reduced-motion, and make it work on touch screens. Export it as a single .tsx file with sensible default props so it renders a complete demo on its own.How the discrete tabs works
Compact icon tabs: the active one widens to reveal its label while the others shrink back to icons, with a springy width animation. The component is a single TypeScript file built with React, Tailwind CSS and Motion, so the animation runs on springs and shared layouts instead of hand-written keyframes.
It comes from Watermelon UI, an open-source component library released under the MIT licence. Install it with the shadcn command above, or copy the source from the code tab into your project.
Frequently asked questions
Want motion like this on your website?
We design and build custom websites with motion, 3D and SEO built in. Websites from $500.