|
| 1 | +import { Content, Portal, ScrollDownButton, ScrollUpButton, Viewport } from '@radix-ui/react-select'; |
| 2 | +import { ChevronDown, ChevronUp } from 'lucide-react'; |
| 3 | +import type { ComponentRef } from 'react'; |
| 4 | +import { forwardRef } from 'react'; |
| 5 | + |
| 6 | +import { cn } from '@/lib/utils'; |
| 7 | + |
| 8 | +import { selectVariants } from './select-variants'; |
| 9 | +import type { SelectContentProps } from './types'; |
| 10 | + |
| 11 | +const SelectContent = forwardRef<ComponentRef<typeof Content>, SelectContentProps>((props, ref) => { |
| 12 | + const { |
| 13 | + children, |
| 14 | + className, |
| 15 | + classNames, |
| 16 | + position = 'popper', |
| 17 | + scrollDownButton, |
| 18 | + scrollUpButton, |
| 19 | + size, |
| 20 | + ...rest |
| 21 | + } = props; |
| 22 | + |
| 23 | + const { |
| 24 | + content, |
| 25 | + scrollDownButton: scrollDownButtonCls, |
| 26 | + scrollUpButton: scrollUpButtonCls, |
| 27 | + viewport: viewportCls |
| 28 | + } = selectVariants({ position, size }); |
| 29 | + |
| 30 | + const mergedCls = { |
| 31 | + contentCls: cn(content(), className || classNames?.content), |
| 32 | + scrollDownButtonCls: cn(scrollDownButtonCls(), classNames?.scrollDownButton), |
| 33 | + scrollUpButtonCls: cn(scrollUpButtonCls(), classNames?.scrollUpButton), |
| 34 | + viewportCls: cn(viewportCls(), classNames?.viewport) |
| 35 | + }; |
| 36 | + |
| 37 | + return ( |
| 38 | + <Portal> |
| 39 | + <Content |
| 40 | + {...rest} |
| 41 | + className={mergedCls.contentCls} |
| 42 | + data-slot="select-content" |
| 43 | + position={position} |
| 44 | + ref={ref} |
| 45 | + > |
| 46 | + <ScrollUpButton |
| 47 | + asChild |
| 48 | + className={mergedCls.scrollUpButtonCls} |
| 49 | + data-slot="scroll-up-button" |
| 50 | + > |
| 51 | + {scrollUpButton || <ChevronUp />} |
| 52 | + </ScrollUpButton> |
| 53 | + |
| 54 | + <Viewport |
| 55 | + className={mergedCls.viewportCls} |
| 56 | + data-slot="viewport" |
| 57 | + > |
| 58 | + {children} |
| 59 | + </Viewport> |
| 60 | + |
| 61 | + <ScrollDownButton |
| 62 | + asChild |
| 63 | + className={mergedCls.scrollDownButtonCls} |
| 64 | + data-slot="scroll-down-button" |
| 65 | + > |
| 66 | + {scrollDownButton || <ChevronDown />} |
| 67 | + </ScrollDownButton> |
| 68 | + </Content> |
| 69 | + </Portal> |
| 70 | + ); |
| 71 | +}); |
| 72 | + |
| 73 | +SelectContent.displayName = Content.displayName; |
| 74 | + |
| 75 | +export default SelectContent; |
0 commit comments