2020-10-03 16:02:53 +08:00
|
|
|
import type { InjectionKey } from 'vue'
|
2021-09-27 09:57:44 +08:00
|
|
|
import type { ValidateFieldsError } from 'async-validator'
|
2021-08-24 13:36:48 +08:00
|
|
|
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
|
|
|
|
emit: (evt: string, ...args: any[]) => void
|
2021-09-16 21:19:27 +08:00
|
|
|
addField: (field: ElFormItemContext) => void
|
|
|
|
removeField: (field: ElFormItemContext) => void
|
2021-11-23 00:10:54 +08:00
|
|
|
resetFields: () => void
|
|
|
|
clearValidate: (props: string | string[]) => void
|
|
|
|
validateField: (props: string | string[], cb: ValidateFieldCallback) => void
|
2020-10-03 16:02:53 +08:00
|
|
|
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>
|
2021-12-10 17:21:01 +08:00
|
|
|
size?: ComponentSize
|
2020-10-03 16:02:53 +08:00
|
|
|
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-09-27 09:57:44 +08:00
|
|
|
(isValid?: string, invalidFields?: ValidateFieldsError): void
|
2020-10-03 16:02:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ElFormItemContext {
|
|
|
|
prop?: string
|
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
|
2021-09-16 21:19:27 +08:00
|
|
|
evaluateValidationEnabled(): void
|
2020-10-03 16:02:53 +08:00
|
|
|
resetField(): void
|
|
|
|
clearValidate(): void
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:19:27 +08:00
|
|
|
export const elFormKey: InjectionKey<ElFormContext> = Symbol('elForm')
|
2021-09-04 19:29:28 +08:00
|
|
|
export const elFormItemKey: InjectionKey<ElFormItemContext> =
|
2021-09-16 21:19:27 +08:00
|
|
|
Symbol('elFormItem')
|