svelte-hook-form
Version:
A better version of form validation.
48 lines (41 loc) • 957 B
TypeScript
import type { SvelteComponentTyped } from "svelte/internal";
import type { Readable } from "svelte/store";
import type { FormControl, RuleExpression } from "../types";
export interface FieldProps<T = any> {
name: string;
defaultValue?: T;
bail?: boolean;
validateOnBlur?: boolean;
validateOnMount?: boolean;
control?: Readable<FormControl<T>> | null;
rules?: RuleExpression;
}
export interface FieldEvents {}
export interface FieldSlots<T = any> {
default: {
pending: false;
valid: false;
dirty: false;
touched: false;
errors: any[];
value: T;
field: any;
onChange: (e: any) => void;
onFocus: () => void;
onBlur: () => void;
};
}
/**
*
* ```svelte
* <Field name="email" rules="required|email" let:field>
* <input type="text" use:field />
* </Field>
* ```
*/
export declare class Field extends SvelteComponentTyped<
FieldProps,
FieldEvents,
FieldSlots
> {}
export default Field;