mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
21a7089ec5
* refactor(build): use type unsafe * fix: windows
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import type { InjectionKey, SetupContext, UnwrapRef } from 'vue'
|
|
import type {
|
|
RuleItem,
|
|
ValidateError,
|
|
ValidateFieldsError,
|
|
} from 'async-validator'
|
|
import type { ComponentSize } from '@element-plus/constants'
|
|
import type {
|
|
FormEmits,
|
|
FormItemProp,
|
|
FormItemProps,
|
|
FormLabelWidthContext,
|
|
FormProps,
|
|
} from '@element-plus/components/form'
|
|
import type { Arrayable } from '@element-plus/utils'
|
|
|
|
export interface FormItemRule extends RuleItem {
|
|
trigger?: Arrayable<string>
|
|
}
|
|
export type FormRules = Partial<Record<string, Arrayable<FormItemRule>>>
|
|
|
|
export type FormValidationResult = Promise<boolean>
|
|
export type FormValidateCallback = (
|
|
isValid: boolean,
|
|
invalidFields?: ValidateFieldsError
|
|
) => void
|
|
export interface FormValidateFailure {
|
|
errors: ValidateError[] | null
|
|
fields: ValidateFieldsError
|
|
}
|
|
|
|
export type FormContext = FormProps &
|
|
UnwrapRef<FormLabelWidthContext> & {
|
|
emit: SetupContext<FormEmits>['emit']
|
|
|
|
// expose
|
|
addField: (field: FormItemContext) => void
|
|
removeField: (field: FormItemContext) => void
|
|
resetFields: (props?: Arrayable<FormItemProp>) => void
|
|
clearValidate: (props?: Arrayable<FormItemProp>) => void
|
|
validateField: (
|
|
props?: Arrayable<FormItemProp>,
|
|
callback?: FormValidateCallback
|
|
) => FormValidationResult
|
|
}
|
|
|
|
export interface FormItemContext extends FormItemProps {
|
|
$el: HTMLDivElement | undefined
|
|
size: ComponentSize
|
|
validateState: string
|
|
isGroup: boolean
|
|
labelId: string
|
|
inputIds: string[]
|
|
addInputId: (id: string) => void
|
|
removeInputId: (id: string) => void
|
|
validate: (
|
|
trigger: string,
|
|
callback?: FormValidateCallback
|
|
) => FormValidationResult
|
|
resetField(): void
|
|
clearValidate(): void
|
|
}
|
|
|
|
export const formContextKey: InjectionKey<FormContext> =
|
|
Symbol('formContextKey')
|
|
export const formItemContextKey: InjectionKey<FormItemContext> =
|
|
Symbol('formItemContextKey')
|