import React, { createContext, useContext, useState } from "react"; import { cn } from "~/lib/utils"; interface TabsContextType { value: string; onValueChange: (value: string) => void; } const TabsContext = createContext(undefined); interface TabsProps { defaultValue?: string; value?: string; onValueChange?: (value: string) => void; className?: string; children: React.ReactNode; } export function Tabs({ defaultValue, value, onValueChange, className, children, }: TabsProps) { const [internalValue, setInternalValue] = useState(defaultValue || ""); const currentValue = value ?? internalValue; const handleValueChange = onValueChange ?? setInternalValue; return (
{children}
); } interface TabsListProps { className?: string; children: React.ReactNode; } export function TabsList({ className, children }: TabsListProps) { return (
{children}
); } interface TabsTriggerProps { value: string; className?: string; disabled?: boolean; children: React.ReactNode; } export function TabsTrigger({ value, className, disabled, children, }: TabsTriggerProps) { const context = useContext(TabsContext); if (!context) throw new Error("TabsTrigger must be used within Tabs"); const isActive = context.value === value; return ( ); } interface TabsContentProps { value: string; className?: string; children: React.ReactNode; } export function TabsContent({ value, className, children }: TabsContentProps) { const context = useContext(TabsContext); if (!context) throw new Error("TabsContent must be used within Tabs"); if (context.value !== value) return null; return (
{children}
); }