'use client'; import * as React from 'react'; import { motion, type Transition } from 'motion/react'; import { TabGroup as TabGroupPrimitive, TabList as TabListPrimitive, Tab as TabPrimitive, TabPanels as TabPanelsPrimitive, TabPanel as TabPanelPrimitive, type TabGroupProps as TabGroupPrimitiveProps, type TabListProps as TabListPrimitiveProps, type TabProps as TabPrimitiveProps, type TabPanelsProps as TabPanelsPrimitiveProps, type TabPanelProps as TabPanelPrimitiveProps, } from '@headlessui/react'; import { cn } from '@workspace/ui/lib/utils'; import { MotionHighlight, MotionHighlightItem, } from '@/registry/effects/motion-highlight'; type TabGroupProps = TabGroupPrimitiveProps & { className?: string; as?: TTag; }; function TabGroup({ className, ...props }: TabGroupProps) { return ( ); } type TabListProps = TabListPrimitiveProps & { as?: TTag; className?: string; activeClassName?: string; transition?: Transition; }; function TabList({ children, className, activeClassName, transition = { type: 'spring', stiffness: 200, damping: 25, }, ...props }: TabListProps) { return ( {(bag) => ( {typeof children === 'function' ? children(bag) : children} )} ); } type TabProps = Omit< TabPrimitiveProps, 'children' > & Required, 'children'>> & { index: number; className?: string; as?: TTag; }; function Tab(props: TabProps) { const { children, className, index, as = 'button', ...rest } = props; return ( {children} ); } type TabPanelProps = Omit< TabPanelPrimitiveProps, 'transition' > & { children: React.ReactNode; className?: string; as?: TTag; transition?: Transition; }; function TabPanel( props: TabPanelProps, ) { const { className, as = motion.div, transition = { duration: 0.5, ease: 'easeInOut', }, ...rest } = props; return ( ); } type TabPanelsProps = Omit< TabPanelsPrimitiveProps, 'transition' > & { className?: string; as?: TTag; transition?: Transition; }; function TabPanels( props: TabPanelsProps, ) { const { children, className, as = motion.div, transition = { type: 'spring', stiffness: 200, damping: 25 }, ...rest } = props; const containerRef = React.useRef(null); const [height, setHeight] = React.useState(0); React.useEffect(() => { if (!containerRef.current) return; const resizeObserver = new ResizeObserver((entries) => { const newHeight = entries[0]?.contentRect.height ?? 0; requestAnimationFrame(() => { setHeight(newHeight); }); }); resizeObserver.observe(containerRef.current); return () => { resizeObserver.disconnect(); }; }, [children]); React.useLayoutEffect(() => { if (containerRef.current) { const initialHeight = containerRef.current.getBoundingClientRect().height; setHeight(initialHeight); } }, [children]); return (
{children}
); } export { TabGroup, TabList, Tab, TabPanel, TabPanels, type TabGroupProps, type TabListProps, type TabProps, type TabPanelProps, type TabPanelsProps, };