31 lines
894 B
TypeScript

import type { TextField } from "@payloadcms/plugin-form-builder/types";
import type { FieldErrorsImpl, FieldValues, UseFormRegister } from "react-hook-form";
import React from "react";
import { Error } from "../Error";
import { Width } from "../Width";
export const Number: React.FC<
{
errors: Partial<
FieldErrorsImpl<{
[x: string]: any;
}>
>;
register: UseFormRegister<any & FieldValues>;
} & TextField
> = ({ name, errors, label, register, required: requiredFromProps, width }) => {
return (
<Width width={width}>
<div className="form-wrap">
<input type="number" className="form-input" id={name} {...register(name, { required: requiredFromProps })} />
<label className="form-label" htmlFor={name}>
{label}
</label>
{requiredFromProps && errors[name] && <Error />}
</div>
</Width>
);
};