blob: c8081267be011f05a9d84280e953bd5ba21c71d4 [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001import * as React from "react";
2import { CaretSortIcon, CheckIcon, ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons";
3import * as SelectPrimitive from "@radix-ui/react-select";
gio5f2f1002025-03-20 18:38:48 +04004
giod0026612025-05-08 13:00:36 +00005import { cn } from "@/lib/utils";
gio5f2f1002025-03-20 18:38:48 +04006
giod0026612025-05-08 13:00:36 +00007const Select = SelectPrimitive.Root;
gio5f2f1002025-03-20 18:38:48 +04008
giod0026612025-05-08 13:00:36 +00009const SelectGroup = SelectPrimitive.Group;
gio5f2f1002025-03-20 18:38:48 +040010
giod0026612025-05-08 13:00:36 +000011const SelectValue = SelectPrimitive.Value;
gio5f2f1002025-03-20 18:38:48 +040012
13const SelectTrigger = React.forwardRef<
giod0026612025-05-08 13:00:36 +000014 React.ElementRef<typeof SelectPrimitive.Trigger>,
15 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
gio5f2f1002025-03-20 18:38:48 +040016>(({ className, children, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000017 <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));
31SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
gio5f2f1002025-03-20 18:38:48 +040032
33const SelectScrollUpButton = React.forwardRef<
giod0026612025-05-08 13:00:36 +000034 React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
35 React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
gio5f2f1002025-03-20 18:38:48 +040036>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000037 <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));
45SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
gio5f2f1002025-03-20 18:38:48 +040046
47const SelectScrollDownButton = React.forwardRef<
giod0026612025-05-08 13:00:36 +000048 React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
49 React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
gio5f2f1002025-03-20 18:38:48 +040050>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000051 <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));
59SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
gio5f2f1002025-03-20 18:38:48 +040060
61const SelectContent = React.forwardRef<
giod0026612025-05-08 13:00:36 +000062 React.ElementRef<typeof SelectPrimitive.Content>,
63 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
gio5f2f1002025-03-20 18:38:48 +040064>(({ className, children, position = "popper", ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000065 <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));
91SelectContent.displayName = SelectPrimitive.Content.displayName;
gio5f2f1002025-03-20 18:38:48 +040092
93const SelectLabel = React.forwardRef<
giod0026612025-05-08 13:00:36 +000094 React.ElementRef<typeof SelectPrimitive.Label>,
95 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
gio5f2f1002025-03-20 18:38:48 +040096>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000097 <SelectPrimitive.Label ref={ref} className={cn("px-2 py-1.5 text-sm font-semibold", className)} {...props} />
98));
99SelectLabel.displayName = SelectPrimitive.Label.displayName;
gio5f2f1002025-03-20 18:38:48 +0400100
101const SelectItem = React.forwardRef<
giod0026612025-05-08 13:00:36 +0000102 React.ElementRef<typeof SelectPrimitive.Item>,
103 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
gio5f2f1002025-03-20 18:38:48 +0400104>(({ className, children, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +0000105 <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));
121SelectItem.displayName = SelectPrimitive.Item.displayName;
gio5f2f1002025-03-20 18:38:48 +0400122
123const SelectSeparator = React.forwardRef<
giod0026612025-05-08 13:00:36 +0000124 React.ElementRef<typeof SelectPrimitive.Separator>,
125 React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
gio5f2f1002025-03-20 18:38:48 +0400126>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +0000127 <SelectPrimitive.Separator ref={ref} className={cn("-mx-1 my-1 h-px bg-muted", className)} {...props} />
128));
129SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
gio5f2f1002025-03-20 18:38:48 +0400130
131export {
giod0026612025-05-08 13:00:36 +0000132 Select,
133 SelectGroup,
134 SelectValue,
135 SelectTrigger,
136 SelectContent,
137 SelectLabel,
138 SelectItem,
139 SelectSeparator,
140 SelectScrollUpButton,
141 SelectScrollDownButton,
142};