|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import * as React from "react"; |
| 4 | +import * as SelectPrimitive from "@radix-ui/react-select"; |
| 5 | +import { Check, ChevronDown } from "lucide-react"; |
| 6 | + |
| 7 | +import { cn } from "@repo/ui/lib/utils"; |
| 8 | + |
| 9 | +const Select = SelectPrimitive.Root; |
| 10 | + |
| 11 | +const SelectValue = SelectPrimitive.Value; |
| 12 | + |
| 13 | +const SelectTrigger = React.forwardRef< |
| 14 | + React.ElementRef<typeof SelectPrimitive.Trigger>, |
| 15 | + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> |
| 16 | +>(({ className, children, ...props }, ref) => ( |
| 17 | + <SelectPrimitive.Trigger |
| 18 | + ref={ref} |
| 19 | + className={cn( |
| 20 | + "flex h-10 w-full items-center justify-between rounded-md border border-slate-200 bg-white px-3 py-2 text-sm ring-offset-white focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2", |
| 21 | + className, |
| 22 | + )} |
| 23 | + {...props} |
| 24 | + > |
| 25 | + {children} |
| 26 | + <SelectPrimitive.Icon asChild> |
| 27 | + <ChevronDown className="h-4 w-4 shrink-0 opacity-50 data-[state=open]:rotate-180" /> |
| 28 | + </SelectPrimitive.Icon> |
| 29 | + </SelectPrimitive.Trigger> |
| 30 | +)); |
| 31 | +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName; |
| 32 | + |
| 33 | +const SelectContent = React.forwardRef< |
| 34 | + React.ElementRef<typeof SelectPrimitive.Content>, |
| 35 | + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> |
| 36 | +>(({ className, children, position = "popper", ...props }, ref) => ( |
| 37 | + <SelectPrimitive.Portal> |
| 38 | + <SelectPrimitive.Content |
| 39 | + ref={ref} |
| 40 | + className={cn( |
| 41 | + "relative z-50 max-h-96 overflow-hidden rounded-md border border-slate-200 bg-white text-slate-900 shadow-md", |
| 42 | + position === "popper" && "w-[var(--radix-select-trigger-width)]", |
| 43 | + className, |
| 44 | + )} |
| 45 | + position={position} |
| 46 | + {...props} |
| 47 | + > |
| 48 | + <SelectPrimitive.Viewport className="max-h-96 overflow-y-auto p-1"> |
| 49 | + {children} |
| 50 | + </SelectPrimitive.Viewport> |
| 51 | + </SelectPrimitive.Content> |
| 52 | + </SelectPrimitive.Portal> |
| 53 | +)); |
| 54 | +SelectContent.displayName = SelectPrimitive.Content.displayName; |
| 55 | + |
| 56 | +const SelectItem = React.forwardRef< |
| 57 | + React.ElementRef<typeof SelectPrimitive.Item>, |
| 58 | + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item> |
| 59 | +>(({ className, children, ...props }, ref) => ( |
| 60 | + <SelectPrimitive.Item |
| 61 | + ref={ref} |
| 62 | + className={cn( |
| 63 | + "relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-3 pr-8 text-sm outline-none focus:bg-slate-100 data-[state=checked]:font-semibold", |
| 64 | + className, |
| 65 | + )} |
| 66 | + {...props} |
| 67 | + > |
| 68 | + <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText> |
| 69 | + <span className="absolute right-2 flex h-4 w-4 items-center justify-center"> |
| 70 | + <SelectPrimitive.ItemIndicator> |
| 71 | + <Check className="h-4 w-4" /> |
| 72 | + </SelectPrimitive.ItemIndicator> |
| 73 | + </span> |
| 74 | + </SelectPrimitive.Item> |
| 75 | +)); |
| 76 | +SelectItem.displayName = SelectPrimitive.Item.displayName; |
| 77 | + |
| 78 | +export { Select, SelectValue, SelectTrigger, SelectContent, SelectItem }; |
0 commit comments