UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 6.52 kB
{"version":3,"file":"form.mjs","names":[],"sources":["../../../../../../packages/components/form/src/form.ts"],"sourcesContent":["import { componentSizes } from '@element-plus/constants'\nimport {\n buildProps,\n definePropType,\n isArray,\n isBoolean,\n isString,\n} from '@element-plus/utils'\n\nimport type { ExtractPublicPropTypes } from 'vue'\nimport type { ComponentSize } from '@element-plus/constants'\nimport type { FormItemProp } from './form-item'\nimport type { FormRules } from './types'\n\nexport interface FormMetaProps {\n /**\n * @description Control the size of components in this form.\n */\n size?: ComponentSize\n /**\n * @description Whether to disable all components in this form. If set to `true`, it will override the `disabled` prop of the inner component.\n */\n disabled?: boolean\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `FormMetaProps` instead.\n */\nexport const formMetaProps = buildProps({\n /**\n * @description Control the size of components in this form.\n */\n size: {\n type: String,\n values: componentSizes,\n },\n /**\n * @description Whether to disable all components in this form. If set to `true`, it will override the `disabled` prop of the inner component.\n */\n disabled: Boolean,\n} as const)\n\nexport interface FormProps extends FormMetaProps {\n /**\n * @description Data of form component.\n */\n model?: Record<string, any>\n /**\n * @description Validation rules of form.\n */\n rules?: FormRules\n /**\n * @description Position of label. If set to `'left'` or `'right'`, `label-width` prop is also required.\n */\n labelPosition?: 'left' | 'right' | 'top'\n /**\n * @description Position of asterisk.\n */\n requireAsteriskPosition?: 'left' | 'right'\n /**\n * @description Width of label, e.g. `'50px'`. All its direct child form items will inherit this value. `auto` is supported.\n */\n labelWidth?: string | number\n /**\n * @description Suffix of the label.\n */\n labelSuffix?: string\n /**\n * @description Whether the form is inline.\n */\n inline?: boolean\n /**\n * @description Whether to display the error message inline with the form item.\n */\n inlineMessage?: boolean\n /**\n * @description Whether to display an icon indicating the validation result.\n */\n statusIcon?: boolean\n /**\n * @description Whether to show the error message.\n */\n showMessage?: boolean\n /**\n * @description Whether to trigger validation when the `rules` prop is changed.\n */\n validateOnRuleChange?: boolean\n /**\n * @description Whether to hide required fields should have a red asterisk (star) beside their labels.\n */\n hideRequiredAsterisk?: boolean\n /**\n * @description When validation fails, scroll to the first error form entry.\n */\n scrollToError?: boolean\n /**\n * @description When validation fails, it scrolls to the first error item based on the scrollIntoView option.\n */\n scrollIntoViewOptions?: ScrollIntoViewOptions | boolean\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `FormProps` instead.\n */\nexport const formProps = buildProps({\n ...formMetaProps,\n /**\n * @description Data of form component.\n */\n model: Object,\n /**\n * @description Validation rules of form.\n */\n rules: {\n type: definePropType<FormRules>(Object),\n },\n /**\n * @description Position of label. If set to `'left'` or `'right'`, `label-width` prop is also required.\n */\n labelPosition: {\n type: String,\n values: ['left', 'right', 'top'],\n default: 'right',\n },\n /**\n * @description Position of asterisk.\n */\n requireAsteriskPosition: {\n type: String,\n values: ['left', 'right'],\n default: 'left',\n },\n /**\n * @description Width of label, e.g. `'50px'`. All its direct child form items will inherit this value. `auto` is supported.\n */\n labelWidth: {\n type: [String, Number],\n default: '',\n },\n /**\n * @description Suffix of the label.\n */\n labelSuffix: {\n type: String,\n default: '',\n },\n /**\n * @description Whether the form is inline.\n */\n inline: Boolean,\n /**\n * @description Whether to display the error message inline with the form item.\n */\n inlineMessage: Boolean,\n /**\n * @description Whether to display an icon indicating the validation result.\n */\n statusIcon: Boolean,\n /**\n * @description Whether to show the error message.\n */\n showMessage: {\n type: Boolean,\n default: true,\n },\n /**\n * @description Whether to trigger validation when the `rules` prop is changed.\n */\n validateOnRuleChange: {\n type: Boolean,\n default: true,\n },\n /**\n * @description Whether to hide required fields should have a red asterisk (star) beside their labels.\n */\n hideRequiredAsterisk: Boolean,\n /**\n * @description When validation fails, scroll to the first error form entry.\n */\n scrollToError: Boolean,\n /**\n * @description When validation fails, it scrolls to the first error item based on the scrollIntoView option.\n */\n scrollIntoViewOptions: {\n type: definePropType<ScrollIntoViewOptions | boolean>([Object, Boolean]),\n default: true,\n },\n} as const)\n\n/**\n * @deprecated Removed after 3.0.0, Use `FormProps` instead.\n */\nexport type FormPropsPublic = ExtractPublicPropTypes<typeof formProps>\n\n/**\n * @deprecated Removed after 3.0.0, Use `FormMetaProps` instead.\n */\nexport type FormMetaPropsPublic = ExtractPublicPropTypes<typeof formMetaProps>\n\nexport const formEmits = {\n validate: (prop: FormItemProp, isValid: boolean, message: string) =>\n (isArray(prop) || isString(prop)) &&\n isBoolean(isValid) &&\n isString(message),\n}\nexport type FormEmits = typeof formEmits\n"],"mappings":";;;;;;;;AA4BA,MAAa,gBAAgB,WAAW;CAItC,MAAM;EACJ,MAAM;EACN,QAAQ;EACT;CAID,UAAU;CACX,CAAU;;;;AAgEX,MAAa,YAAY,WAAW;CAClC,GAAG;CAIH,OAAO;CAIP,OAAO,EACL,MAAM,eAA0B,OAAO,EACxC;CAID,eAAe;EACb,MAAM;EACN,QAAQ;GAAC;GAAQ;GAAS;GAAM;EAChC,SAAS;EACV;CAID,yBAAyB;EACvB,MAAM;EACN,QAAQ,CAAC,QAAQ,QAAQ;EACzB,SAAS;EACV;CAID,YAAY;EACV,MAAM,CAAC,QAAQ,OAAO;EACtB,SAAS;EACV;CAID,aAAa;EACX,MAAM;EACN,SAAS;EACV;CAID,QAAQ;CAIR,eAAe;CAIf,YAAY;CAIZ,aAAa;EACX,MAAM;EACN,SAAS;EACV;CAID,sBAAsB;EACpB,MAAM;EACN,SAAS;EACV;CAID,sBAAsB;CAItB,eAAe;CAIf,uBAAuB;EACrB,MAAM,eAAgD,CAAC,QAAQ,QAAQ,CAAC;EACxE,SAAS;EACV;CACF,CAAU;AAYX,MAAa,YAAY,EACvB,WAAW,MAAoB,SAAkB,aAC9C,QAAQ,KAAK,IAAI,SAAS,KAAK,KAChC,UAAU,QAAQ,IAClB,SAAS,QAAQ,EACpB"}