|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { cn } from "@/lib/utils"; |
| 4 | +import * as SelectPrimitive from "@radix-ui/react-select"; |
| 5 | +import { Check, ChevronDown } from "lucide-react"; |
| 6 | +import React from "react"; |
| 7 | + |
| 8 | +const Select = SelectPrimitive.Root; |
| 9 | + |
| 10 | +const SelectTrigger = ({ |
| 11 | + className, |
| 12 | + children, |
| 13 | + ...props |
| 14 | +}: SelectPrimitive.SelectTriggerProps) => { |
| 15 | + return ( |
| 16 | + <SelectPrimitive.Trigger |
| 17 | + className={cn( |
| 18 | + "flex h-10 min-w-40 items-center shadow-md justify-between border-2 border-input border-black bg-transparent px-4 py-2 ring-offset-background placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50", |
| 19 | + className |
| 20 | + )} |
| 21 | + {...props} |
| 22 | + > |
| 23 | + {children} |
| 24 | + <SelectPrimitive.Icon asChild> |
| 25 | + <ChevronDown className="ml-2 h-4 w-4" /> |
| 26 | + </SelectPrimitive.Icon> |
| 27 | + </SelectPrimitive.Trigger> |
| 28 | + ); |
| 29 | +}; |
| 30 | + |
| 31 | +const SelectValue = SelectPrimitive.Value; |
| 32 | + |
| 33 | +const SelectIcon = SelectPrimitive.Icon; |
| 34 | + |
| 35 | +const SelectContent = ({ |
| 36 | + className, |
| 37 | + children, |
| 38 | + position = "popper", |
| 39 | + ...props |
| 40 | +}: SelectPrimitive.SelectContentProps) => { |
| 41 | + return ( |
| 42 | + <SelectPrimitive.Portal> |
| 43 | + <SelectPrimitive.Content |
| 44 | + className={cn( |
| 45 | + "relative z-50 min-w-[8rem] overflow-hidden border border-black bg-white text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", |
| 46 | + position === "popper" && |
| 47 | + "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", |
| 48 | + className |
| 49 | + )} |
| 50 | + position={position} |
| 51 | + {...props} |
| 52 | + > |
| 53 | + <SelectPrimitive.Viewport |
| 54 | + className={cn( |
| 55 | + position === "popper" && |
| 56 | + "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]" |
| 57 | + )} |
| 58 | + > |
| 59 | + {children} |
| 60 | + </SelectPrimitive.Viewport> |
| 61 | + </SelectPrimitive.Content> |
| 62 | + </SelectPrimitive.Portal> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
| 66 | +const SelectGroup = SelectPrimitive.Group; |
| 67 | + |
| 68 | +const SelectItem = ({ |
| 69 | + className, |
| 70 | + children, |
| 71 | + ...props |
| 72 | +}: SelectPrimitive.SelectItemProps) => ( |
| 73 | + <SelectPrimitive.Item |
| 74 | + className={cn( |
| 75 | + "relative flex w-full cursor-default select-none items-center py-1.5 px-2 outline-none hover:bg-primary-400 data-[disabled]:pointer-events-none data-[disabled]:opacity-50", |
| 76 | + className |
| 77 | + )} |
| 78 | + {...props} |
| 79 | + > |
| 80 | + <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText> |
| 81 | + |
| 82 | + <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 83 | + <SelectPrimitive.ItemIndicator> |
| 84 | + <Check className="h-4 w-4 text-foreground" /> |
| 85 | + </SelectPrimitive.ItemIndicator> |
| 86 | + </span> |
| 87 | + </SelectPrimitive.Item> |
| 88 | +); |
| 89 | +const SelectLabel = SelectPrimitive.Label; |
| 90 | +const SelectSeparator = SelectPrimitive.Separator; |
| 91 | + |
| 92 | +const SelectObj = Object.assign(Select, { |
| 93 | + Trigger: SelectTrigger, |
| 94 | + Value: SelectValue, |
| 95 | + Icon: SelectIcon, |
| 96 | + Content: SelectContent, |
| 97 | + Group: SelectGroup, |
| 98 | + Item: SelectItem, |
| 99 | + Label: SelectLabel, |
| 100 | + Separator: SelectSeparator, |
| 101 | +}); |
| 102 | + |
| 103 | +export { SelectObj as Select }; |
0 commit comments