Openstatus
www.openstatus.dev
1"use client";
2
3import * as SelectPrimitive from "@radix-ui/react-select";
4import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
5import type * as React from "react";
6
7import { cn } from "@/lib/utils";
8
9function Select({
10 ...props
11}: React.ComponentProps<typeof SelectPrimitive.Root>) {
12 return <SelectPrimitive.Root data-slot="select" {...props} />;
13}
14
15function SelectGroup({
16 ...props
17}: React.ComponentProps<typeof SelectPrimitive.Group>) {
18 return <SelectPrimitive.Group data-slot="select-group" {...props} />;
19}
20
21function SelectValue({
22 ...props
23}: React.ComponentProps<typeof SelectPrimitive.Value>) {
24 return <SelectPrimitive.Value data-slot="select-value" {...props} />;
25}
26
27function SelectTrigger({
28 className,
29 size = "default",
30 children,
31 ...props
32}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
33 size?: "sm" | "default";
34}) {
35 return (
36 <SelectPrimitive.Trigger
37 data-slot="select-trigger"
38 data-size={size}
39 className={cn(
40 "flex w-fit items-center justify-between gap-2 whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-xs outline-none transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[size=default]:h-9 data-[size=sm]:h-8 data-[placeholder]:text-muted-foreground *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:hover:bg-input/50 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
41 className,
42 )}
43 {...props}
44 >
45 {children}
46 <SelectPrimitive.Icon asChild>
47 <ChevronDownIcon className="size-4 opacity-50" />
48 </SelectPrimitive.Icon>
49 </SelectPrimitive.Trigger>
50 );
51}
52
53function SelectContent({
54 className,
55 children,
56 position = "popper",
57 ...props
58}: React.ComponentProps<typeof SelectPrimitive.Content>) {
59 return (
60 <SelectPrimitive.Portal>
61 <SelectPrimitive.Content
62 data-slot="select-content"
63 className={cn(
64 "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 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=closed]:animate-out data-[state=open]:animate-in",
65 position === "popper" &&
66 "data-[side=left]:-translate-x-1 data-[side=top]:-translate-y-1 data-[side=right]:translate-x-1 data-[side=bottom]:translate-y-1",
67 className,
68 )}
69 position={position}
70 {...props}
71 >
72 <SelectScrollUpButton />
73 <SelectPrimitive.Viewport
74 className={cn(
75 "p-1",
76 position === "popper" &&
77 "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1",
78 )}
79 >
80 {children}
81 </SelectPrimitive.Viewport>
82 <SelectScrollDownButton />
83 </SelectPrimitive.Content>
84 </SelectPrimitive.Portal>
85 );
86}
87
88function SelectLabel({
89 className,
90 ...props
91}: React.ComponentProps<typeof SelectPrimitive.Label>) {
92 return (
93 <SelectPrimitive.Label
94 data-slot="select-label"
95 className={cn("px-2 py-1.5 text-muted-foreground text-xs", className)}
96 {...props}
97 />
98 );
99}
100
101function SelectItem({
102 className,
103 children,
104 ...props
105}: React.ComponentProps<typeof SelectPrimitive.Item>) {
106 return (
107 <SelectPrimitive.Item
108 data-slot="select-item"
109 className={cn(
110 "relative flex w-full cursor-default select-none items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
111 className,
112 )}
113 {...props}
114 >
115 <span className="absolute right-2 flex size-3.5 items-center justify-center">
116 <SelectPrimitive.ItemIndicator>
117 <CheckIcon className="size-4" />
118 </SelectPrimitive.ItemIndicator>
119 </span>
120 <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
121 </SelectPrimitive.Item>
122 );
123}
124
125function SelectSeparator({
126 className,
127 ...props
128}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
129 return (
130 <SelectPrimitive.Separator
131 data-slot="select-separator"
132 className={cn("-mx-1 pointer-events-none my-1 h-px bg-border", className)}
133 {...props}
134 />
135 );
136}
137
138function SelectScrollUpButton({
139 className,
140 ...props
141}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
142 return (
143 <SelectPrimitive.ScrollUpButton
144 data-slot="select-scroll-up-button"
145 className={cn(
146 "flex cursor-default items-center justify-center py-1",
147 className,
148 )}
149 {...props}
150 >
151 <ChevronUpIcon className="size-4" />
152 </SelectPrimitive.ScrollUpButton>
153 );
154}
155
156function SelectScrollDownButton({
157 className,
158 ...props
159}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
160 return (
161 <SelectPrimitive.ScrollDownButton
162 data-slot="select-scroll-down-button"
163 className={cn(
164 "flex cursor-default items-center justify-center py-1",
165 className,
166 )}
167 {...props}
168 >
169 <ChevronDownIcon className="size-4" />
170 </SelectPrimitive.ScrollDownButton>
171 );
172}
173
174export {
175 Select,
176 SelectContent,
177 SelectGroup,
178 SelectItem,
179 SelectLabel,
180 SelectScrollDownButton,
181 SelectScrollUpButton,
182 SelectSeparator,
183 SelectTrigger,
184 SelectValue,
185};