2022-11-19 14:21:26 +00:00
|
|
|
import React from "react";
|
|
|
|
// types
|
|
|
|
import { Props } from "./types";
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
export const Select: React.FC<Props> = ({
|
2022-11-19 14:21:26 +00:00
|
|
|
id,
|
|
|
|
label,
|
|
|
|
value,
|
2022-12-06 14:38:28 +00:00
|
|
|
className = "",
|
2022-11-19 14:21:26 +00:00
|
|
|
name,
|
|
|
|
register,
|
|
|
|
disabled,
|
|
|
|
validations,
|
|
|
|
error,
|
|
|
|
options,
|
2022-12-19 18:22:01 +00:00
|
|
|
size = "rg",
|
|
|
|
fullWidth = true,
|
2023-01-26 18:12:20 +00:00
|
|
|
}) => (
|
2022-11-19 14:21:26 +00:00
|
|
|
<>
|
|
|
|
{label && (
|
|
|
|
<label htmlFor={id} className="text-gray-500 mb-2">
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
)}
|
|
|
|
<select
|
|
|
|
id={id}
|
|
|
|
name={name}
|
|
|
|
value={value}
|
|
|
|
{...(register && register(name, validations))}
|
|
|
|
disabled={disabled}
|
2022-12-19 18:22:01 +00:00
|
|
|
className={`mt-1 block text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md bg-transparent ${
|
|
|
|
fullWidth ? "w-full" : ""
|
2023-01-26 18:12:20 +00:00
|
|
|
} ${
|
|
|
|
size === "rg" ? "px-3 py-2" : size === "lg" ? "p-3" : ""
|
|
|
|
} ${className}`}
|
2022-11-19 14:21:26 +00:00
|
|
|
>
|
|
|
|
{options.map((option, index) => (
|
|
|
|
<option value={option.value} key={index}>
|
|
|
|
{option.label}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
2023-01-26 18:12:20 +00:00
|
|
|
{error?.message && (
|
|
|
|
<div className="text-red-500 text-sm">{error.message}</div>
|
|
|
|
)}
|
2022-11-19 14:21:26 +00:00
|
|
|
</>
|
|
|
|
);
|