mirror of
https://github.com/patdelphi/suanming.git
synced 2026-03-10 02:23:12 +08:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import React, { SelectHTMLAttributes } from 'react';
|
|
import { cn } from '../../lib/utils';
|
|
|
|
interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
|
|
label?: string;
|
|
error?: string;
|
|
options: { value: string; label: string }[];
|
|
}
|
|
|
|
export const Select: React.FC<SelectProps> = ({
|
|
className,
|
|
label,
|
|
error,
|
|
options,
|
|
...props
|
|
}) => {
|
|
return (
|
|
<div className="space-y-1">
|
|
{label && (
|
|
<label className="block text-sm font-medium text-gray-700">
|
|
{label}
|
|
</label>
|
|
)}
|
|
<select
|
|
className={cn(
|
|
'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500 bg-white',
|
|
error && 'border-red-300 focus:border-red-500 focus:ring-red-500',
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{options.map((option) => (
|
|
<option key={option.value} value={option.value}>
|
|
{option.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
{error && (
|
|
<p className="text-sm text-red-600">{error}</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}; |