'use client' import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area' import { forwardRef } from 'react' import { tv } from 'tailwind-variants' import type { Merge } from 'type-fest' const scrollArea = tv({ slots: { root: 'relative overflow-hidden', viewport: 'h-full w-full rounded-[inherit]', scrollbar: 'flex touch-none select-none transition-colors', thumb: 'relative flex-1 rounded-full bg-border', }, variants: { orientation: { vertical: { scrollbar: 'h-full w-2.5 border-l border-l-transparent p-[0.0625rem]', }, horizontal: { scrollbar: 'h-2.5 flex-col border-t border-t-transparent p-[0.0625rem]', }, }, }, }) const ScrollArea = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { viewportProps?: React.ComponentProps cornerProps?: React.ComponentProps orientation?: 'vertical' | 'horizontal' verticalScrollbarProps?: React.ComponentProps horizontalScrollbarProps?: React.ComponentProps } > >( ( { viewportProps, cornerProps, orientation, verticalScrollbarProps, horizontalScrollbarProps, children, ...props }, ref, ) => { const { root, viewport } = scrollArea() return ( {children} {!orientation || orientation === 'horizontal' ? ( ) : null} {!orientation || orientation === 'vertical' ? ( ) : null} ) }, ) ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName const ScrollBar = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { thumbProps?: React.ComponentProps } > >(({ thumbProps, ...props }, ref) => { const { scrollbar, thumb } = scrollArea({ orientation: props.orientation }) return ( ) }) ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName export default ScrollArea export { scrollArea, ScrollAreaPrimitive }