Skip to content

Commit

Permalink
feat(input component): add input component with react-form-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail-benlaredj committed Nov 4, 2023
1 parent 75ff23e commit ec1b4ff
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/components/input/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import clsx from "clsx";
const Input = ({
name,
type,
labelText,
placeholder,
register,
requiredMessage,
validation,
errors,
}) => {
return (
<>
<label
htmlFor={name}
className='block text-base font-light text-slate-700 -mb-4'
>
{labelText}
</label>
<input
{...register(name, {
required: requiredMessage,
...validation,
})}
placeholder={placeholder}
type={type}
className={clsx(
"p-2 block w-full border rounded-md focus:outline-none focus:ring-2 focus:ring-green",
{
"border-red": errors[name],
"border-slate-300": !errors[name],
},
)}
/>
{errors[name] && (
<span className='text-red'>{errors[name].message}</span>
)}
</>
);
};

export default Input;

0 comments on commit ec1b4ff

Please sign in to comment.