import clsx from 'clsx'; import * as React from 'react'; import { RegisterOptions, useFormContext } from 'react-hook-form'; import { HiExclamationCircle } from 'react-icons/hi'; export type InputProps = { /** Input label */ label: string; /** * id to be initialized with React Hook Form, * must be the same with the pre-defined types. */ id: string; /** Input placeholder */ placeholder?: string; /** Small text below input, useful for additional information */ helperText?: string; /** * Input type * @example text, email, password */ type?: React.HTMLInputTypeAttribute; /** Disables the input and shows defaultValue (can be set from React Hook Form) */ readOnly?: boolean; /** Disable error style (not disabling error validation) */ hideError?: boolean; /** Manual validation using RHF, it is encouraged to use yup resolver instead */ validation?: RegisterOptions; } & React.ComponentPropsWithoutRef<'input'>; export default function Input({ label, placeholder = '', helperText, id, type = 'text', readOnly = false, hideError = false, validation, ...rest }: InputProps) { const { register, formState: { errors }, } = useFormContext(); return (
{helperText}
} {!hideError && errors[id] && ( {errors[id].message} )}