2023-01-26 18:12:20 +00:00
|
|
|
import * as React from "react";
|
2023-04-21 19:29:57 +00:00
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
// types
|
2023-04-21 19:29:57 +00:00
|
|
|
import { Props } from "./types";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
export const Input: React.FC<Props> = ({
|
|
|
|
label,
|
|
|
|
value,
|
|
|
|
name,
|
|
|
|
register,
|
|
|
|
validations,
|
|
|
|
error,
|
|
|
|
mode = "primary",
|
|
|
|
onChange,
|
|
|
|
className = "",
|
|
|
|
type,
|
|
|
|
id,
|
|
|
|
size = "rg",
|
|
|
|
fullWidth = true,
|
|
|
|
...rest
|
|
|
|
}) => (
|
|
|
|
<>
|
|
|
|
{label && (
|
2023-07-10 07:17:00 +00:00
|
|
|
<label htmlFor={id} className="text-custom-text-200 mb-2">
|
2023-01-26 18:12:20 +00:00
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
)}
|
|
|
|
<input
|
|
|
|
type={type}
|
|
|
|
id={id}
|
|
|
|
value={value}
|
|
|
|
{...(register && register(name, validations))}
|
|
|
|
onChange={(e) => {
|
|
|
|
register && register(name).onChange(e);
|
|
|
|
onChange && onChange(e);
|
|
|
|
}}
|
2023-07-13 11:21:08 +00:00
|
|
|
className={`block rounded-md bg-transparent text-sm focus:outline-none placeholder-custom-text-400 ${
|
2023-01-26 18:12:20 +00:00
|
|
|
mode === "primary"
|
2023-07-17 10:58:23 +00:00
|
|
|
? "rounded-md border border-custom-border-200"
|
2023-01-26 18:12:20 +00:00
|
|
|
: mode === "transparent"
|
2023-07-10 07:17:00 +00:00
|
|
|
? "rounded border-none bg-transparent ring-0 transition-all focus:ring-1 focus:ring-custom-primary"
|
2023-02-01 15:03:18 +00:00
|
|
|
: mode === "trueTransparent"
|
|
|
|
? "rounded border-none bg-transparent ring-0"
|
2023-01-26 18:12:20 +00:00
|
|
|
: ""
|
2023-04-24 05:49:43 +00:00
|
|
|
} ${error ? "border-red-500" : ""} ${error && mode === "primary" ? "bg-red-500/20" : ""} ${
|
2023-01-26 18:12:20 +00:00
|
|
|
fullWidth ? "w-full" : ""
|
|
|
|
} ${size === "rg" ? "px-3 py-2" : size === "lg" ? "p-3" : ""} ${className}`}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
{error?.message && <div className="text-sm text-red-500">{error.message}</div>}
|
|
|
|
</>
|
|
|
|
);
|