react-hybrid-form
Version:
A super simple, straightforward and powerful hybrid form library which combines the benefits of both controlled or uncontrolled form.
137 lines (128 loc) • 3.7 kB
TypeScript
import React from 'react';
type FieldValue = string | string[];
type FieldRef = {
validate?: () => boolean;
getValue: () => FieldValue;
reset: () => void;
};
type Register = (key: string) => (fieldRef: FieldRef | null) => void;
type HybridFormReturn = [
Register,
() => Record<string, FieldValue> | null,
() => void
];
declare function useHybridForm(): HybridFormReturn;
type InputFieldProps = {
type?: "tel" | "url" | "date" | "file" | "text" | "time" | "week" | "color" | "email" | "month" | "range" | "number" | "datetime-local";
name: string;
label?: string;
fieldClass?: string;
inputClass?: string;
labelClass?: string;
errorClass?: string;
placeholder?: string;
defaultValue?: string;
autoComplete?: string;
validate?: (value: string) => string | null;
};
type InputFieldRef = {
validate: () => boolean;
getValue: () => string;
reset: () => void;
};
declare const InputField: React.ForwardRefExoticComponent<InputFieldProps & React.RefAttributes<InputFieldRef>>;
type Option$2 = {
label: string;
value: string;
};
type RadioFieldProps = {
name: string;
label: string;
options: Option$2[];
fieldClass?: string;
labelClass?: string;
optionClass?: string;
optionsClass?: string;
};
type RadioFieldRef = {
reset: () => void;
getValue: () => string;
};
declare const RadioField: React.ForwardRefExoticComponent<RadioFieldProps & React.RefAttributes<RadioFieldRef>>;
type Option$1 = {
label: string;
value: string;
};
type SelectFieldProps = {
name: string;
label: string;
options: Option$1[];
fieldClass?: string;
labelClass?: string;
optionClass?: string;
optionsClass?: string;
};
type SelectFieldRef = {
reset: () => void;
getValue: () => string;
};
declare const SelectField: React.ForwardRefExoticComponent<SelectFieldProps & React.RefAttributes<SelectFieldRef>>;
type Option = {
label: string;
value: string;
};
type CheckBoxFieldProps = {
name: string;
label: string;
options: Option[];
fieldClass?: string;
labelClass?: string;
optionsClass?: string;
optionClass?: string;
};
type CheckBoxFieldRef = {
reset: () => void;
getValue: () => string[];
};
declare const CheckBoxField: React.ForwardRefExoticComponent<CheckBoxFieldProps & React.RefAttributes<CheckBoxFieldRef>>;
type PasswordFieldProps = {
name: string;
label?: string;
fieldClass?: string;
inputClass?: string;
labelClass?: string;
errorClass?: string;
placeholder?: string;
showPasswordIcon?: string;
hidePasswordIcon?: string;
toggleVisibilityClass?: string;
requiresConfirmation?: boolean;
requiresTogglingVisibility?: boolean;
validate: (value: string) => string | null;
};
type PasswordFieldRef = {
reset: () => void;
getValue: () => string;
validate: () => boolean;
};
declare const PasswordField: React.ForwardRefExoticComponent<PasswordFieldProps & React.RefAttributes<PasswordFieldRef>>;
type TextAreaFieldProps = {
name: string;
rows?: number;
cols?: number;
label?: string;
fieldClass?: string;
labelClass?: string;
errorClass?: string;
placeholder?: string;
defaultValue?: string;
textareaClass?: string;
validate?: (value: string) => string | null;
};
type TextAreaFieldRef = {
reset: () => void;
getValue: () => string;
validate: () => boolean;
};
declare const TextAreaField: React.ForwardRefExoticComponent<TextAreaFieldProps & React.RefAttributes<TextAreaFieldRef>>;
export { CheckBoxField, InputField, PasswordField, RadioField, SelectField, TextAreaField, useHybridForm };