vercel-tabs
jolyui-ui/vercel-tabsFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/vercel-tabs.jsonSource
1"use client";23import type React from "react";4import { useEffect, useRef, useState } from "react";5import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";67interface TabData {8 label: string;9 value: string;10 content: React.ReactNode;11}1213interface VercelTabsProps {14 tabs: TabData[];15 defaultTab?: string;16 className?: string;17}1819export function VercelTabs({ tabs, defaultTab, className }: VercelTabsProps) {20 const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);21 const [activeTab, setActiveTab] = useState(defaultTab || tabs[0]?.value);22 const [hoverStyle, setHoverStyle] = useState({});23 const [activeStyle, setActiveStyle] = useState({ left: "0px", width: "0px" });24 const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);2526 const activeIndex = tabs.findIndex((tab) => tab.value === activeTab);2728 useEffect(() => {29 if (hoveredIndex !== null) {30 const hoveredElement = tabRefs.current[hoveredIndex];31 if (hoveredElement) {32 const { offsetLeft, offsetWidth } = hoveredElement;33 setHoverStyle({34 left: `${offsetLeft}px`,35 width: `${offsetWidth}px`,36 });37 }38 }39 }, [hoveredIndex]);4041 useEffect(() => {42 const activeElement = tabRefs.current[activeIndex];43 if (activeElement) {44 const { offsetLeft, offsetWidth } = activeElement;45 setActiveStyle({46 left: `${offsetLeft}px`,47 width: `${offsetWidth}px`,48 });49 }50 }, [activeIndex]);5152 useEffect(() => {53 requestAnimationFrame(() => {54 const activeElement = tabRefs.current[activeIndex];55 if (activeElement) {56 const { offsetLeft, offsetWidth } = activeElement;57 setActiveStyle({58 left: `${offsetLeft}px`,59 width: `${offsetWidth}px`,60 });61 }62 });63 }, [activeIndex]);6465 return (66 <Tabs67 defaultValue={activeTab}68 onValueChange={setActiveTab}69 className={`flex w-full flex-col items-center ${className}`}70 >71 <TabsList className="relative h-auto select-none gap-[6px] bg-transparent p-0">72 {/* Hover Highlight */}73 <div74 className="absolute top-0 left-0 flex h-[30px] items-center rounded-[6px] bg-[#0e0f1114] transition-all duration-300 ease-out dark:bg-[#ffffff1a]"75 style={{76 ...hoverStyle,77 opacity: hoveredIndex !== null ? 1 : 0,78 }}79 />8081 {/* Active Indicator */}82 <div83// … truncated
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
