feat(Form): new component (#4)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Romain Hamel
2024-03-19 16:09:12 +01:00
committed by GitHub
parent 1cec712fb8
commit de62676647
35 changed files with 2735 additions and 69 deletions

51
src/runtime/types/form.d.ts vendored Normal file
View File

@@ -0,0 +1,51 @@
export interface Form<T> {
validate (path?: string | string[], opts?: { silent?: true }): Promise<T | false>
validate (path?: string | string[], opts?: { silent?: false }): Promise<T | false>
clear (path?: string): void
errors: Ref<FormError[]>
setErrors (errs: FormError[], path?: string): void
getErrors (path?: string): FormError[]
submit (): Promise<void>
disabled: ComputedRef<boolean>
}
export type FormSchema<T extends object> =
| ZodSchema
| YupObjectSchema<T>
| ValibotObjectSchema<T>
| JoiSchema<T>
export type FormInputEvents = 'input' | 'blur' | 'change'
export interface FormError<P extends string = string> {
name: P
message: string
}
export interface FormErrorWithId extends FormError {
id: string
}
export type FormSubmitEvent<T> = SubmitEvent & { data: T }
export type FormErrorEvent = SubmitEvent & { errors: FormErrorWithId[] }
export type FormEventType = FormInputEvents | 'submit'
export interface FormEvent {
type: FormEventType
name?: string
}
export interface InjectedFormFieldOptions {
inputId: Ref<string | number | undefined>
name: Computed<string>
size: Computed<string | number | symbol>
error: Computed<string | boolean | undefined>
eagerValidation: Computed<boolean>
validateOnInputDelay: Computed<number | undefined>
}
export interface InjectedFormOptions {
disabled?: Computed<boolean>
validateOnInputDelay?: Computed<number>
}

View File

@@ -0,0 +1 @@