Select.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from "react";
  2. interface Option {
  3. value: string;
  4. label: string;
  5. id: string;
  6. }
  7. export default function Select({
  8. placeholder,
  9. options,
  10. onChange,
  11. onBlur,
  12. name,
  13. error,
  14. ref,
  15. autoComplete = "off",
  16. className,
  17. }: {
  18. placeholder?: string;
  19. options: Option[];
  20. onChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
  21. onBlur: (e: React.ChangeEvent<HTMLSelectElement>) => void;
  22. name: string;
  23. error?: string;
  24. ref?: React.Ref<HTMLSelectElement>;
  25. autoComplete?: string;
  26. className?:string;
  27. }) {
  28. return (
  29. <div className="w-full relative">
  30. <select className={`appearance-none ly-input ${className ?? ''}`}
  31. onChange={onChange}
  32. onBlur={onBlur}
  33. name={name}
  34. ref={ref}
  35. autoComplete={autoComplete}
  36. >
  37. {placeholder && <option value="">{placeholder}</option>}
  38. {options.map((option) => (
  39. <option key={option.id} value={option.value}>
  40. {option.label}
  41. </option>
  42. ))}
  43. </select>
  44. <svg className="absolute right-2 top-1/2 -translate-y-1/2" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24" fill="none">
  45. <path stroke="rgba(0, 0, 0, 1)" strokeWidth="1.5" strokeLinejoin="round" strokeLinecap="round" d="M18 9L12 15L6 9">
  46. </path>
  47. </svg>
  48. {error && <p className="text-red-500 text-ly-12">{error}</p>}
  49. </div>
  50. );
  51. }