comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
120 lines (119 loc) • 4.53 kB
JavaScript
import { defineComponent, inject, computed, openBlock, createElementBlock, normalizeClass, renderSlot, createCommentVNode, createElementVNode, unref, createBlock, resolveDynamicComponent, withDirectives, createVNode, vShow } from "vue";
import "../style/input.css";
import "../../form-common.css";
import { FORM_PROVIDE } from "../../form/src/type.mjs";
import { useGlobal } from "../../../utils/config.mjs";
import { isVueComponent } from "../../../utils/typescript.mjs";
import "@vueuse/core";
import { useItemValidate } from "../../../hooks/validate.mjs";
import { inputProps, inputEmits } from "./main.props.mjs";
import "../../../icons/index.mjs";
import { CloseOne } from "../../../icons/components/components.mjs";
const _hoisted_1 = {
key: 0,
class: "prefix-slot"
};
const _hoisted_2 = { class: "cu-input__content" };
const _hoisted_3 = {
key: 0,
class: "prefix-icon"
};
const _hoisted_4 = ["value", "placeholder", "type", "disabled", "maxlength", "minlength"];
const _hoisted_5 = {
key: 1,
class: "clearable"
};
const _hoisted_6 = {
key: 2,
class: "suffix-icon"
};
const _hoisted_7 = {
key: 1,
class: "suffix-slot"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "CuInput"
},
__name: "main",
props: inputProps,
emits: inputEmits,
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const { itemValidate } = useItemValidate();
const { globalSize } = useGlobal();
const form = inject(FORM_PROVIDE, void 0);
const currentSize = computed(() => {
return props.size ?? (form == null ? void 0 : form.props.size) ?? (globalSize == null ? void 0 : globalSize.value);
});
function inputEvent(e) {
let val = e.target.value;
if (props.type === "number") {
val = Number(val);
}
emit("update:modelValue", val);
change(val);
emit("input", val);
}
function clear() {
emit("update:modelValue", "");
change("");
emit("clear");
}
function blur(e) {
emit("blur", e);
itemValidate("blur");
}
function change(val) {
emit("change", val);
itemValidate("change");
}
return (_ctx, _cache) => {
return openBlock(), createElementBlock("span", {
class: normalizeClass(["cu-input", [currentSize.value, { "is-disabled": _ctx.disabled }]])
}, [
_ctx.$slots.prefix ? (openBlock(), createElementBlock("span", _hoisted_1, [
renderSlot(_ctx.$slots, "prefix")
])) : createCommentVNode("", true),
createElementVNode("span", _hoisted_2, [
_ctx.prefixIcon || _ctx.$slots["prefix-icon"] ? (openBlock(), createElementBlock("span", _hoisted_3, [
renderSlot(_ctx.$slots, "prefix-icon", {}, () => [
unref(isVueComponent)(_ctx.prefixIcon) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.prefixIcon), { key: 0 })) : createCommentVNode("", true)
])
])) : createCommentVNode("", true),
createElementVNode("input", {
class: "cu-input__inner",
value: _ctx.modelValue,
onInput: inputEvent,
onFocus: _cache[0] || (_cache[0] = ($event) => emit("focus", $event)),
onBlur: blur,
onChange: _cache[1] || (_cache[1] = ($event) => change($event.target.value)),
placeholder: _ctx.placeholder,
type: _ctx.type,
disabled: _ctx.disabled,
autocomplete: "off",
maxlength: _ctx.maxlength,
minlength: _ctx.minlength
}, null, 40, _hoisted_4),
_ctx.clearable ? (openBlock(), createElementBlock("span", _hoisted_5, [
withDirectives(createVNode(unref(CloseOne), { onClick: clear }, null, 512), [
[vShow, _ctx.modelValue]
])
])) : createCommentVNode("", true),
_ctx.suffixIcon || _ctx.$slots["suffix-icon"] ? (openBlock(), createElementBlock("span", _hoisted_6, [
renderSlot(_ctx.$slots, "suffix-icon", {}, () => [
unref(isVueComponent)(_ctx.suffixIcon) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.suffixIcon), { key: 0 })) : createCommentVNode("", true)
])
])) : createCommentVNode("", true)
]),
_ctx.$slots.suffix ? (openBlock(), createElementBlock("span", _hoisted_7, [
renderSlot(_ctx.$slots, "suffix")
])) : createCommentVNode("", true)
], 2);
};
}
});
export {
_sfc_main as default
};