import * as React from "react" import { cn } from "../../lib/utils" const TabContext = React.createContext({ selectedTab: '', setSelectedTab: () => {} }) const Tabs = React.forwardRef(({ defaultValue, value, onValueChange, className, children, ...props }, ref) => { const [selectedTab, setSelectedTab] = React.useState(value || defaultValue); React.useEffect(() => { if (value !== undefined) { setSelectedTab(value); } }, [value]); const handleTabChange = (newValue) => { if (value === undefined) { setSelectedTab(newValue); } onValueChange?.(newValue); }; return (
{children}
); }); Tabs.displayName = "Tabs" const TabsList = React.forwardRef(({ className, ...props }, ref) => (
)) TabsList.displayName = "TabsList" const TabsTrigger = React.forwardRef(({ className, value, children, ...props }, ref) => { const { selectedTab, setSelectedTab } = React.useContext(TabContext); const isSelected = selectedTab === value; return ( ); }); TabsTrigger.displayName = "TabsTrigger" const TabsContent = React.forwardRef(({ className, value, children, ...props }, ref) => { const { selectedTab } = React.useContext(TabContext); const isSelected = selectedTab === value; if (!isSelected) return null; return (
{children}
); }); TabsContent.displayName = "TabsContent" export { Tabs, TabsList, TabsTrigger, TabsContent }