form-select.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from 'react';
  2. interface FormSelectProps {
  3. id: string;
  4. label: string;
  5. value: string;
  6. onChange: (value: string) => void;
  7. options: { value: string; label: string }[];
  8. disabled?: boolean;
  9. placeholder?: string;
  10. }
  11. export default function FormSelect({
  12. id,
  13. label,
  14. value,
  15. onChange,
  16. options,
  17. disabled = false,
  18. placeholder
  19. }: FormSelectProps) {
  20. return (
  21. <div>
  22. <label htmlFor={id} className="block text-sm font-medium text-gray-700 mb-1">
  23. {label}
  24. </label>
  25. <select
  26. id={id}
  27. value={value}
  28. onChange={(e) => onChange(e.target.value)}
  29. disabled={disabled}
  30. className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed"
  31. >
  32. {placeholder && (
  33. <option value="" disabled>
  34. {placeholder}
  35. </option>
  36. )}
  37. {options.map((option) => (
  38. <option key={option.value} value={option.value}>
  39. {option.label}
  40. </option>
  41. ))}
  42. </select>
  43. </div>
  44. );
  45. }