element-plus
Version:
A Component Library for Vue 3
1 lines • 9.25 kB
Source Map (JSON)
{"version":3,"file":"input.mjs","sources":["../../../../../../packages/components/input/src/input.ts"],"sourcesContent":["import {\n buildProps,\n definePropType,\n iconPropType,\n isString,\n mutable,\n} from '@element-plus/utils'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { useAriaProps, useSizeProp } from '@element-plus/hooks'\nimport { CircleClose } from '@element-plus/icons-vue'\n\nimport type {\n ExtractPropTypes,\n ExtractPublicPropTypes,\n HTMLAttributes,\n StyleValue,\n} from 'vue'\n\nexport type InputModelModifiers = {\n lazy?: boolean\n number?: boolean\n trim?: boolean\n}\nexport type InputAutoSize = { minRows?: number; maxRows?: number } | boolean\n// Some commonly used values for input type\nexport type InputType =\n | 'text'\n | 'textarea'\n | 'number'\n | 'password'\n | 'email'\n | 'search'\n | 'tel'\n | 'url'\n | (string & NonNullable<unknown>)\n\nexport const inputProps = buildProps({\n /**\n * @description native input id\n */\n id: {\n type: String,\n default: undefined,\n },\n /**\n * @description input box size\n */\n size: useSizeProp,\n /**\n * @description whether to disable\n */\n disabled: {\n type: Boolean,\n default: undefined,\n },\n /**\n * @description binding value\n */\n modelValue: {\n type: definePropType<string | number | null | undefined>([\n String,\n Number,\n Object,\n ]),\n default: '',\n },\n /**\n * @description v-model modifiers, reference [Vue modifiers](https://vuejs.org/guide/essentials/forms.html#modifiers)\n */\n modelModifiers: {\n type: definePropType<InputModelModifiers>(Object),\n default: () => ({}),\n },\n /**\n * @description same as `maxlength` in native input\n */\n maxlength: {\n type: [String, Number],\n },\n /**\n * @description same as `minlength` in native input\n */\n minlength: {\n type: [String, Number],\n },\n /**\n * @description type of input, see more in [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types)\n */\n type: {\n type: definePropType<InputType>(String),\n default: 'text',\n },\n /**\n * @description control the resizability\n */\n resize: {\n type: String,\n values: ['none', 'both', 'horizontal', 'vertical'],\n },\n /**\n * @description whether textarea has an adaptive height\n */\n autosize: {\n type: definePropType<InputAutoSize>([Boolean, Object]),\n default: false,\n },\n /**\n * @description native input autocomplete\n */\n autocomplete: {\n type: definePropType<HTMLInputElement['autocomplete']>(String),\n default: 'off',\n },\n /**\n * @description format content\n */\n formatter: {\n type: Function,\n },\n /**\n * @description parse content\n */\n parser: {\n type: Function,\n },\n /**\n * @description placeholder\n */\n placeholder: {\n type: String,\n },\n /**\n * @description native input form\n */\n form: {\n type: String,\n },\n /**\n * @description native input readonly\n */\n readonly: Boolean,\n /**\n * @description whether to show clear button\n */\n clearable: Boolean,\n /**\n * @description custom clear icon component\n */\n clearIcon: {\n type: iconPropType,\n default: CircleClose,\n },\n /**\n * @description toggleable password input\n */\n showPassword: Boolean,\n /**\n * @description word count\n */\n showWordLimit: Boolean,\n /**\n * @description word count position, valid when `show-word-limit` is true\n */\n wordLimitPosition: {\n type: String,\n values: ['inside', 'outside'],\n default: 'inside',\n },\n /**\n * @description suffix icon\n */\n suffixIcon: {\n type: iconPropType,\n },\n /**\n * @description prefix icon\n */\n prefixIcon: {\n type: iconPropType,\n },\n /**\n * @description container role, internal properties provided for use by the picker component\n */\n containerRole: {\n type: String,\n default: undefined,\n },\n /**\n * @description input tabindex\n */\n tabindex: {\n type: [String, Number],\n default: 0,\n },\n /**\n * @description whether to trigger form validation\n */\n validateEvent: {\n type: Boolean,\n default: true,\n },\n /**\n * @description input or textarea element style\n */\n inputStyle: {\n type: definePropType<StyleValue>([Object, Array, String]),\n default: () => mutable({} as const),\n },\n /**\n * @description native input autofocus\n */\n autofocus: Boolean,\n rows: {\n type: Number,\n default: 2,\n },\n ...useAriaProps(['ariaLabel']),\n /**\n * @description native input mode for virtual keyboards\n */\n inputmode: {\n type: definePropType<HTMLAttributes['inputmode']>(String),\n default: undefined,\n },\n /**\n * @description same as `name` in native input\n */\n name: String,\n} as const)\nexport type InputProps = ExtractPropTypes<typeof inputProps>\nexport type InputPropsPublic = ExtractPublicPropTypes<typeof inputProps>\n\nexport const inputEmits = {\n [UPDATE_MODEL_EVENT]: (value: string) => isString(value),\n input: (value: string) => isString(value),\n change: (value: string, evt?: Event) =>\n isString(value) && (evt instanceof Event || evt === undefined),\n focus: (evt: FocusEvent) => evt instanceof FocusEvent,\n blur: (evt: FocusEvent) => evt instanceof FocusEvent,\n clear: () => true,\n mouseleave: (evt: MouseEvent) => evt instanceof MouseEvent,\n mouseenter: (evt: MouseEvent) => evt instanceof MouseEvent,\n // NOTE: when autofill by browser, the keydown event is instanceof Event, not KeyboardEvent\n // relative bug report https://github.com/element-plus/element-plus/issues/6665\n keydown: (evt: KeyboardEvent | Event) => evt instanceof Event,\n compositionstart: (evt: CompositionEvent) => evt instanceof CompositionEvent,\n compositionupdate: (evt: CompositionEvent) => evt instanceof CompositionEvent,\n compositionend: (evt: CompositionEvent) => evt instanceof CompositionEvent,\n}\nexport type InputEmits = typeof inputEmits\n"],"names":[],"mappings":";;;;;;;;;AAoCO,MAAM,aAAa,UAAW,CAAA;AAAA,EAInC,EAAI,EAAA;AAAA,IACF,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA,KAAA,CAAA;AAAA,GACX;AAAA,EAIA,IAAM,EAAA,WAAA;AAAA,EAIN,QAAU,EAAA;AAAA,IACR,IAAM,EAAA,OAAA;AAAA,IACN,OAAS,EAAA,KAAA,CAAA;AAAA,GACX;AAAA,EAIA,UAAY,EAAA;AAAA,IACV,MAAM,cAAmD,CAAA;AAAA,MACvD,MAAA;AAAA,MACA,MAAA;AAAA,MACA,MAAA;AAAA,KACD,CAAA;AAAA,IACD,OAAS,EAAA,EAAA;AAAA,GACX;AAAA,EAIA,cAAgB,EAAA;AAAA,IACd,IAAA,EAAM,eAAoC,MAAM,CAAA;AAAA,IAChD,OAAA,EAAS,OAAO,EAAC,CAAA;AAAA,GACnB;AAAA,EAIA,SAAW,EAAA;AAAA,IACT,IAAA,EAAM,CAAC,MAAA,EAAQ,MAAM,CAAA;AAAA,GACvB;AAAA,EAIA,S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