48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
|
|
"use client";
|
||
|
|
|
||
|
|
import * as React from "react";
|
||
|
|
import { cn } from "@/lib/utils";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Lightweight native <select>-based select. Radix's `Select` adds a lot of
|
||
|
|
* complexity and a11y plumbing we don't need for these admin forms. We use
|
||
|
|
* native select for simplicity and consistent keyboard support.
|
||
|
|
*/
|
||
|
|
|
||
|
|
export interface SelectOption {
|
||
|
|
value: string;
|
||
|
|
label: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
|
||
|
|
options: SelectOption[];
|
||
|
|
placeholder?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
|
||
|
|
({ className, options, placeholder, ...props }, ref) => {
|
||
|
|
return (
|
||
|
|
<select
|
||
|
|
ref={ref}
|
||
|
|
className={cn(
|
||
|
|
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
||
|
|
className
|
||
|
|
)}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
{placeholder && (
|
||
|
|
<option value="" disabled>
|
||
|
|
{placeholder}
|
||
|
|
</option>
|
||
|
|
)}
|
||
|
|
{options.map((opt) => (
|
||
|
|
<option key={opt.value} value={opt.value}>
|
||
|
|
{opt.label}
|
||
|
|
</option>
|
||
|
|
))}
|
||
|
|
</select>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
);
|
||
|
|
Select.displayName = "Select";
|