use react-hook-form

This commit is contained in:
EGOIST
2022-05-12 13:47:10 +08:00
parent 744a47f416
commit baa478a2bf
9 changed files with 122 additions and 181 deletions
+17 -10
View File
@@ -1,14 +1,20 @@
import clsx from "clsx"
import { DetailedHTMLProps, InputHTMLAttributes } from "react"
import { DetailedHTMLProps, forwardRef, InputHTMLAttributes } from "react"
export const Input: React.FC<
DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
label?: string
addon?: string
isBlock?: boolean
error?: string
}
> = ({ label, addon, className, isBlock, error, ...inputProps }) => {
type Props = DetailedHTMLProps<
InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> & {
label?: string
addon?: string
isBlock?: boolean
error?: string
}
export const Input = forwardRef<HTMLInputElement, Props>(function Input(
{ label, addon, className, isBlock, error, ...inputProps },
ref
) {
const hasAddon = !!addon
return (
<div>
@@ -20,6 +26,7 @@ export const Input: React.FC<
<div className="flex items-center">
<input
{...inputProps}
ref={ref}
className={clsx(
"input",
hasAddon && `has-addon`,
@@ -36,4 +43,4 @@ export const Input: React.FC<
{error && <div className="text-sm mt-1 text-red-500">{error}</div>}
</div>
)
}
})