2020-10-03 16:02:53 +08:00
|
|
|
import type { InjectionKey } from 'vue'
|
2021-09-04 19:29:28 +08:00
|
|
|
import type { FieldErrorList } from 'async-validator'
|
2021-08-24 13:36:48 +08:00
|
|
|
import type { Emitter } from 'mitt'
|
|
|
|
import type { ComponentSize } from '@element-plus/utils/types'
|
2020-10-03 16:02:53 +08:00
|
|
|
|
|
|
|
export interface ElFormContext {
|
|
|
|
registerLabelWidth(width: number, oldWidth: number): void
|
|
|
|
deregisterLabelWidth(width: number): void
|
|
|
|
autoLabelWidth: string | undefined
|
|
|
|
formMitt: Emitter
|
|
|
|
emit: (evt: string, ...args: any[]) => void
|
|
|
|
labelSuffix: string
|
|
|
|
inline?: boolean
|
2021-08-24 13:36:48 +08:00
|
|
|
inlineMessage?: boolean
|
2020-10-03 16:02:53 +08:00
|
|
|
model?: Record<string, unknown>
|
|
|
|
size?: string
|
|
|
|
showMessage?: boolean
|
|
|
|
labelPosition?: string
|
2021-08-24 13:36:48 +08:00
|
|
|
labelWidth?: string | number
|
2020-10-03 16:02:53 +08:00
|
|
|
rules?: Record<string, unknown>
|
|
|
|
statusIcon?: boolean
|
|
|
|
hideRequiredAsterisk?: boolean
|
2020-10-30 23:26:33 +08:00
|
|
|
disabled?: boolean
|
2020-10-03 16:02:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ValidateFieldCallback {
|
2021-08-24 13:36:48 +08:00
|
|
|
(isValid?: string, invalidFields?: FieldErrorList): void
|
2020-10-03 16:02:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ElFormItemContext {
|
|
|
|
prop?: string
|
2020-10-30 23:26:33 +08:00
|
|
|
formItemMitt: Emitter
|
2021-08-26 14:18:57 +08:00
|
|
|
size?: ComponentSize
|
2020-11-02 11:05:08 +08:00
|
|
|
validateState: string
|
2021-08-28 20:00:19 +08:00
|
|
|
$el: HTMLDivElement
|
2021-08-24 09:45:51 +08:00
|
|
|
validate(trigger: string, callback?: ValidateFieldCallback): void
|
2020-10-03 16:02:53 +08:00
|
|
|
updateComputedLabelWidth(width: number): void
|
|
|
|
addValidateEvents(): void
|
|
|
|
removeValidateEvents(): void
|
|
|
|
resetField(): void
|
|
|
|
clearValidate(): void
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: change it to symbol
|
|
|
|
export const elFormKey: InjectionKey<ElFormContext> = 'elForm' as any
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
export const elFormItemKey: InjectionKey<ElFormItemContext> =
|
|
|
|
'elFormItem' as any
|
2020-10-03 16:02:53 +08:00
|
|
|
|
|
|
|
export const elFormEvents = {
|
|
|
|
addField: 'el.form.addField',
|
|
|
|
removeField: 'el.form.removeField',
|
|
|
|
} as const
|