-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.tsx
More file actions
63 lines (61 loc) · 2.08 KB
/
select.tsx
File metadata and controls
63 lines (61 loc) · 2.08 KB
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
import { cn } from "@cooper/ui";
import { X } from "lucide-react";
interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
options: { value: string | number; label: string | number }[];
placeholder?: string;
className?: string;
onClear?: () => void;
}
export const Select: React.FC<SelectProps> = ({
options,
placeholder,
className,
onClear,
...props
}) => {
return (
<div className="relative w-full">
<select
className={cn(
"h-9 w-full appearance-none rounded-lg border border-cooper-gray-150 bg-transparent px-4 pr-10 text-sm text-cooper-gray-350 shadow-none placeholder:text-muted-foreground hover:bg-accent focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
{...props}
>
{placeholder && (
<option value="" disabled hidden>
{placeholder}
</option>
)}
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
{/* Icons container - X and Chevron on the same line */}
<div className="pointer-events-none absolute inset-y-0 right-3 flex items-center gap-2">
{onClear && (
<button
type="button"
onClick={(e) => {
e.stopPropagation();
onClear();
}}
className="pointer-events-auto flex items-center justify-center rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none"
aria-label="Clear selection"
>
<X className="h-4 w-4" />
</button>
)}
{/* Chevron */}
<svg
className="h-4 w-4 fill-current flex-shrink-0 text-cooper-gray-600"
viewBox="0 0 20 20"
>
<path d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" />
</svg>
</div>
</div>
);
};