import {tInputHooks} from "./uses/useInputHooks"; import {ComponentEvent, ExtractPropTypes, iMouseEvent, PropType, SimpleFunction, tRefs, tSlotsType} from "@peryl/react-compose"; import {createError} from "../../utils/createError"; import {StyleProps, tStyleComputed} from "../../uses/useStyle"; import {EditProps, tEditComputed} from "../../uses/useEdit"; import {iSelectOptionProps} from "../Select/select.utils"; export const InputPropsOption = { ...StyleProps, ...EditProps, /*public*/ type: { type: String }, // input type modelValue: {}, // 输入框双向绑定值 placeValue: {}, // 与modelValue一起判断当前是否有值 isFocus: { type: Boolean }, // 当前是否为获取焦点的状态 width: { type: [String, Number] as PropType }, // 输入框宽度 suffixIcon: { type: String }, // 右侧图标 prefixIcon: { type: String }, // 左侧图标 align: { type: String as PropType<'left' | 'center' | 'right'> }, // 输入框文本对齐方式 throttleEnter: { type: [Number, Boolean] as PropType }, // enter按键事件节流 asyncHandler: { type: Function as PropType }, // 异步处理函数,会自动开启关闭loading状态 nativeAttrs: { type: Object }, // 传递给input。textarea的原生属性 maxLength: { type: Number }, // 输入的时候的最大文本长度 noMaxLengthSuffix: { type: Boolean }, // 不显示最大文本长度suffix内容 multipleSeparator: { default: /[\s\n,,]/ }, // 多值输入的时候的分隔符。类型为字符串或者正则表达式;有这个分隔符的话,会自动按照这个分隔符对输入的文本分割 fixedWidth: { type: Boolean }, // InputGroup下是否固定宽度 bare: { type: Boolean }, // 去掉包裹节点 loadingType: { type: String }, // loading类型 autoFocus: { type: Boolean }, // 初始化时自动获取焦点 /*clear*/ noClear: { type: Boolean }, // 去掉清空按钮 clearHandler: { type: Function as PropType<(e: iMouseEvent) => void> }, // 自定义处理清空逻辑 /*textarea*/ textarea: { type: Boolean }, // 当前是否为文本域输入框 height: { type: [String, Number] as PropType }, // 文本域固定高度 minHeight: { type: [String, Number] as PropType }, // 文本域最小高度 maxHeight: { type: [String, Number] as PropType }, // 文本域最大高度 /*suffix icon*/ disabledFocusOnClickSuffixIcon: { type: Boolean }, // 禁用在点击suffix icon的时候自动获取焦点 /*multiple*/ multiple: { type: Boolean }, // 是否为多值输入框 handleRemoveTag: { type: Function as PropType }, // 手动处理移除tab handleAddTag: { type: Function as PropType }, // 手动处理添加tag tagsWrap: { type: Boolean }, // 多值标签换行显示 multipleText: {}, // 多值输入时,输入框的绑定文本 /*推荐输入*/ suggestion: { type: [Array, Function] as PropType string[])> }, // 推荐输入文本数组 suggestionIgnoreSearchText: { type: Boolean }, // 推荐输入框忽略搜索关键词 suggestionDisabledOpenOnEnter: { type: Boolean }, // 禁用在回车的时候自动打开推荐面板 } as const; export const InputEmitsOptions = { onUpdateModelValue: (val?: any) => true, onInput: (val: any) => true, onUpdateMultipleText: (val?: any) => true, onFocus: (e: FocusEvent) => true, onBlur: (e: FocusEvent) => true, onEnter: (e: KeyboardEvent) => true, onKeydown: (e: KeyboardEvent) => true, onEsc: (e: KeyboardEvent) => true, onClickSuffixIcon: (e: iMouseEvent) => true, onClickPrefixIcon: (e: iMouseEvent) => true, onClear: (e: iMouseEvent) => true, onSuggestion: (data: { val: string, optionProps: iSelectOptionProps }) => true, } as const; export const InputSlotsOptions = [ 'prefix', 'suffix', 'prefixIconContent', 'suffixIconContent', 'default', ] as const; export const InputRefsOptions = { input: HTMLInputElement, el: HTMLSpanElement } as const; export interface iInputCompositionData { hooks: tInputHooks, props: ExtractPropTypes, editComputed: tEditComputed, styleComputed: tStyleComputed, editState: { loading?: boolean | null, }, model: { value?: any }, emit: ComponentEvent['emit'], refs: tRefs['refs'], slots: tSlotsType, parentPopupId: string | undefined, methods: { focus: () => void, blur: () => void, }, isEmpty: { value: boolean }, } export interface iInputPropsHandleRemoveTag {(scope: { index: number, val: string }): boolean | void | Promise;} export interface iInputPropsHandleAddTag {(val: string): boolean | void | Promise;} export const showInputError = createError('Input'); /** * input内容滚动显示到尾部 * @author 韦胜健 * @date 2022/8/9 12:09 */ export function inputScrollEnd(getInputEl: () => HTMLElement | undefined | null) { const container = getInputEl()?.querySelector('[data-input-el="container"]'); !!container && (container.scrollLeft = container.scrollWidth); } export default {};