'use client'; import * as React from 'react'; import { cn } from '@/lib/utils'; interface TabsContextValue { value: string; onValueChange: (value: string) => void; } const TabsContext = React.createContext(undefined); interface TabsProps { defaultValue: string; value?: string; onValueChange?: (value: string) => void; children: React.ReactNode; className?: string; } export function Tabs({ defaultValue, value, onValueChange, children, className }: TabsProps) { const [internalValue, setInternalValue] = React.useState(defaultValue); const currentValue = value ?? internalValue; const handleValueChange = React.useCallback((newValue: string) => { setInternalValue(newValue); onValueChange?.(newValue); }, [onValueChange]); return (
{children}
); } export function TabsList({ children, className }: { children: React.ReactNode; className?: string }) { return (
{children}
); } export function TabsTrigger({ value, children, className }: { value: string; children: React.ReactNode; className?: string }) { const context = React.useContext(TabsContext); if (!context) throw new Error('TabsTrigger must be used within Tabs'); const isActive = context.value === value; return ( ); } export function TabsContent({ value, children, className }: { value: string; children: React.ReactNode; className?: string }) { const context = React.useContext(TabsContext); if (!context) throw new Error('TabsContent must be used within Tabs'); if (context.value !== value) return null; return
{children}
; }