ErrorMessage } from "../ErrorMessage";
export type Props = {
name: string;
type?: string;
placeholder: string;
error: string | undefined;
} & typeof defaultProps;
const defaultProps = {
type: "text",
};
type Ref = HTMLInputElement;
export const Input = React.forwardRef<Ref, Props>((props, ref) => {
const { name, type, placeholder, error } = props;
return (
<input
name={name}
type={type}
className={clsx(
"form-control form-control-lg shadow-none",
error && "border-danger"
)}
placeholder={placeholder}
ref={ref}
/>
);
});
Input.defaultProps = defaultProps;
export const InputWithError = React.forwardRef<Ref, Props>((props, ref) => {
const { error } = props;
return (
<>
<Input {...props} ref={ref} />
<ErrorMessage message={error} className="mt-2" />
</>
);
});
InputWithError.defaultProps = defaultProps;
Обсуждают сегодня