-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathselect.tsx
124 lines (116 loc) · 4.16 KB
/
select.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as React from "react";
import {
Content,
Icon,
Item,
ItemIndicator,
ItemText,
Portal,
Root,
ScrollDownButton,
ScrollUpButton,
Trigger,
Value,
Viewport
} from "@radix-ui/react-select";
import { Check, ChevronDown, ChevronUp, ChevronsUpDown } from "lucide-react";
import { twMerge } from "tailwind-merge";
const Select = Root;
const SelectValue = Value;
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof Trigger>,
React.ComponentPropsWithoutRef<typeof Trigger>
>(({ className, children, ...props }, ref) => (
<Trigger
ref={ref}
className={twMerge(
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-gray-200 bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
className
)}
{...props}
>
{children}
<Icon asChild>
<ChevronsUpDown className="h-4 w-4 opacity-50" />
</Icon>
</Trigger>
));
SelectTrigger.displayName = Trigger.displayName;
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof ScrollUpButton>
>(({ className, ...props }, ref) => (
<ScrollUpButton
ref={ref}
className={twMerge("flex cursor-default items-center justify-center py-1", className)}
{...props}
>
<ChevronUp />
</ScrollUpButton>
));
SelectScrollUpButton.displayName = ScrollUpButton.displayName;
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof ScrollDownButton>
>(({ className, ...props }, ref) => (
<ScrollDownButton
ref={ref}
className={twMerge("flex cursor-default items-center justify-center py-1", className)}
{...props}
>
<ChevronDown />
</ScrollDownButton>
));
SelectScrollDownButton.displayName = ScrollDownButton.displayName;
const SelectContent = React.forwardRef<
React.ElementRef<typeof Content>,
React.ComponentPropsWithoutRef<typeof Content>
>(({ className, children, position = "popper", ...props }, ref) => (
<Portal>
<Content
ref={ref}
className={twMerge(
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-gray-200 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",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<Viewport
className={twMerge(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
)}
>
{children}
</Viewport>
<SelectScrollDownButton />
</Content>
</Portal>
));
SelectContent.displayName = Content.displayName;
const SelectItem = React.forwardRef<React.ElementRef<typeof Item>, React.ComponentPropsWithoutRef<typeof Item>>(
({ className, children, ...props }, ref) => (
<Item
ref={ref}
className={twMerge(
"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",
className
)}
{...props}
>
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
<ItemIndicator>
<Check className="h-4 w-4" />
</ItemIndicator>
</span>
<ItemText>{children}</ItemText>
</Item>
)
);
SelectItem.displayName = Item.displayName;
export { Select, SelectValue, SelectTrigger, SelectContent, SelectItem };