UNPKG

@arco-design/web-vue

Version:

Arco Design Vue 2.0: A Vue.js 3 UI Library

117 lines (116 loc) 3.06 kB
"use strict"; var vue = require("vue"); var globalConfig = require("../_utils/global-config.js"); var iconHover = require("../_components/icon-hover.js"); var index$1 = require("../icon/icon-search/index.js"); var index = require("../icon/icon-loading/index.js"); var index$2 = require("../button/index.js"); var input = require("./input.js"); var useSize = require("../_hooks/use-size.js"); var InputSearch = vue.defineComponent({ name: "InputSearch", props: { searchButton: { type: Boolean, default: false }, loading: { type: Boolean, default: false }, disabled: { type: Boolean, default: false }, size: { type: String }, buttonText: { type: String }, buttonProps: { type: Object } }, emits: { search: (value, ev) => true }, setup(props, { emit, slots }) { const { size } = vue.toRefs(props); const prefixCls = globalConfig.getPrefixCls("input-search"); const { mergedSize } = useSize.useSize(size); const inputRef = vue.ref(); const handleClick = (e) => { if (inputRef.value.inputRef) { emit("search", inputRef.value.inputRef.value, e); } }; const renderSuffix = () => { var _a; return vue.createVNode(vue.Fragment, null, [props.loading ? vue.createVNode(index, null, null) : vue.createVNode(iconHover, { "onClick": handleClick }, { default: () => [vue.createVNode(index$1, null, null)] }), (_a = slots.suffix) == null ? void 0 : _a.call(slots)]); }; const renderButton = () => { var _a; let _slots = {}; if (props.buttonText || slots["button-default"] || slots["button-icon"]) { _slots = { default: (_a = slots["button-default"]) != null ? _a : props.buttonText ? () => props.buttonText : void 0, icon: slots["button-icon"] }; } else { _slots = { icon: () => vue.createVNode(index$1, null, null) }; } return vue.createVNode(index$2["default"], vue.mergeProps({ "type": "primary", "class": `${prefixCls}-btn`, "disabled": props.disabled, "size": mergedSize.value, "loading": props.loading }, props.buttonProps, { "onClick": handleClick }), _slots); }; const render = () => vue.createVNode(input, { "ref": inputRef, "class": prefixCls, "size": mergedSize.value, "disabled": props.disabled }, { prepend: slots.prepend, prefix: slots.prefix, suffix: props.searchButton ? slots.suffix : renderSuffix, append: props.searchButton ? renderButton : slots.append }); return { inputRef, render }; }, methods: { focus() { var _a; (_a = this.inputRef) == null ? void 0 : _a.focus(); }, blur() { var _a; (_a = this.inputRef) == null ? void 0 : _a.blur(); } }, render() { return this.render(); } }); module.exports = InputSearch;