| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 1 | import * as React from "react"; |
| 2 | import { CaretSortIcon, CheckIcon, ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons"; |
| 3 | import * as SelectPrimitive from "@radix-ui/react-select"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 4 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 5 | import { cn } from "@/lib/utils"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 6 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 7 | const Select = SelectPrimitive.Root; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 8 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 9 | const SelectGroup = SelectPrimitive.Group; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 10 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 11 | const SelectValue = SelectPrimitive.Value; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 12 | |
| 13 | const SelectTrigger = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 14 | React.ElementRef<typeof SelectPrimitive.Trigger>, |
| 15 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 16 | >(({ className, children, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 17 | <SelectPrimitive.Trigger |
| 18 | ref={ref} |
| 19 | className={cn( |
| 20 | "flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", |
| 21 | className, |
| 22 | )} |
| 23 | {...props} |
| 24 | > |
| 25 | {children} |
| 26 | <SelectPrimitive.Icon asChild> |
| 27 | <CaretSortIcon className="h-4 w-4 opacity-50" /> |
| 28 | </SelectPrimitive.Icon> |
| 29 | </SelectPrimitive.Trigger> |
| 30 | )); |
| 31 | SelectTrigger.displayName = SelectPrimitive.Trigger.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 32 | |
| 33 | const SelectScrollUpButton = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 34 | React.ElementRef<typeof SelectPrimitive.ScrollUpButton>, |
| 35 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 36 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 37 | <SelectPrimitive.ScrollUpButton |
| 38 | ref={ref} |
| 39 | className={cn("flex cursor-default items-center justify-center py-1", className)} |
| 40 | {...props} |
| 41 | > |
| 42 | <ChevronUpIcon /> |
| 43 | </SelectPrimitive.ScrollUpButton> |
| 44 | )); |
| 45 | SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 46 | |
| 47 | const SelectScrollDownButton = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 48 | React.ElementRef<typeof SelectPrimitive.ScrollDownButton>, |
| 49 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 50 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 51 | <SelectPrimitive.ScrollDownButton |
| 52 | ref={ref} |
| 53 | className={cn("flex cursor-default items-center justify-center py-1", className)} |
| 54 | {...props} |
| 55 | > |
| 56 | <ChevronDownIcon /> |
| 57 | </SelectPrimitive.ScrollDownButton> |
| 58 | )); |
| 59 | SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 60 | |
| 61 | const SelectContent = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 62 | React.ElementRef<typeof SelectPrimitive.Content>, |
| 63 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 64 | >(({ className, children, position = "popper", ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 65 | <SelectPrimitive.Portal> |
| 66 | <SelectPrimitive.Content |
| 67 | ref={ref} |
| 68 | className={cn( |
| 69 | "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover 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", |
| 70 | position === "popper" && |
| 71 | "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", |
| 72 | className, |
| 73 | )} |
| 74 | position={position} |
| 75 | {...props} |
| 76 | > |
| 77 | <SelectScrollUpButton /> |
| 78 | <SelectPrimitive.Viewport |
| 79 | className={cn( |
| 80 | "p-1", |
| 81 | position === "popper" && |
| 82 | "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]", |
| 83 | )} |
| 84 | > |
| 85 | {children} |
| 86 | </SelectPrimitive.Viewport> |
| 87 | <SelectScrollDownButton /> |
| 88 | </SelectPrimitive.Content> |
| 89 | </SelectPrimitive.Portal> |
| 90 | )); |
| 91 | SelectContent.displayName = SelectPrimitive.Content.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 92 | |
| 93 | const SelectLabel = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 94 | React.ElementRef<typeof SelectPrimitive.Label>, |
| 95 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 96 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 97 | <SelectPrimitive.Label ref={ref} className={cn("px-2 py-1.5 text-sm font-semibold", className)} {...props} /> |
| 98 | )); |
| 99 | SelectLabel.displayName = SelectPrimitive.Label.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 100 | |
| 101 | const SelectItem = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 102 | React.ElementRef<typeof SelectPrimitive.Item>, |
| 103 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 104 | >(({ className, children, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 105 | <SelectPrimitive.Item |
| 106 | ref={ref} |
| 107 | className={cn( |
| 108 | "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", |
| 109 | className, |
| 110 | )} |
| 111 | {...props} |
| 112 | > |
| 113 | <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 114 | <SelectPrimitive.ItemIndicator> |
| 115 | <CheckIcon className="h-4 w-4" /> |
| 116 | </SelectPrimitive.ItemIndicator> |
| 117 | </span> |
| 118 | <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText> |
| 119 | </SelectPrimitive.Item> |
| 120 | )); |
| 121 | SelectItem.displayName = SelectPrimitive.Item.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 122 | |
| 123 | const SelectSeparator = React.forwardRef< |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 124 | React.ElementRef<typeof SelectPrimitive.Separator>, |
| 125 | React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 126 | >(({ className, ...props }, ref) => ( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 127 | <SelectPrimitive.Separator ref={ref} className={cn("-mx-1 my-1 h-px bg-muted", className)} {...props} /> |
| 128 | )); |
| 129 | SelectSeparator.displayName = SelectPrimitive.Separator.displayName; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 130 | |
| 131 | export { |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 132 | Select, |
| 133 | SelectGroup, |
| 134 | SelectValue, |
| 135 | SelectTrigger, |
| 136 | SelectContent, |
| 137 | SelectLabel, |
| 138 | SelectItem, |
| 139 | SelectSeparator, |
| 140 | SelectScrollUpButton, |
| 141 | SelectScrollDownButton, |
| 142 | }; |