UNPKG

@ducor/react

Version:

admin template ui interface

46 lines (45 loc) 1.7 kB
import React from "react"; import { useForm } from "@ducor/helpers"; import Password from "./password"; import Select from "./select"; import Submit from "./submit"; import Email from "./email"; import Textarea from "./textarea"; import { useField } from "../../hook"; type HTTPMethod = "GET" | "POST" | "DELETE" | "PATCH" | "PUT"; type FormFieldValue = string | number | File | Blob | FileList | null; type FormFieldArrayValue = string[] | number[] | FormFieldArrayValue[]; type FieldErrors = Record<string, string | string[]>; type MapOfField = { [key: string]: any; }; interface FormContextType { fieldsMap: Map<string, MapOfField>; pristine: boolean; isDirty: boolean; processing: boolean; method: HTTPMethod; defaults: Record<string, FormFieldValue | FormFieldArrayValue>; values: Record<string, FormFieldValue | FormFieldArrayValue>; errors: Record<string, string[]>; setValue: (name: string, value: any) => void; setError: (name: string, value: any) => void; onChangeField: Record<string, any>; submitting: boolean; submitted: boolean; } interface FromPropsType { method: HTTPMethod; action: string; children?: React.ReactNode; onStart?: () => void; onFinish?: (values: any, errors: FieldErrors) => void; onSuccess?: (response: any) => void; onError?: (errors: FieldErrors) => void; defaultValues?: Record<string, string | string[]>; className?: string; } export declare const FormContext: React.Context<FormContextType | undefined>; declare const Form: React.FC<FromPropsType>; export { Form, Textarea, Select, Password, Submit, Email, useForm, useField }; export { default as Hidden } from "./hidden";