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