UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

86 lines (85 loc) 2.68 kB
import { defineComponent, ref, watch, onMounted, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, createCommentVNode } from "vue"; import "../style/textarea.css"; import "../../form-common.css"; import { useItemValidate } from "../../../hooks/validate.mjs"; import "../../../utils/config.mjs"; import "@vueuse/core"; import { textareaProps, textareaEmits } from "./main.props.mjs"; const _hoisted_1 = ["placeholder", "maxlength", "disabled", "rows"]; const _hoisted_2 = { key: 0, class: "cu-textarea__maxlength" }; const _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: "CuTextarea" }, __name: "main", props: textareaProps, emits: textareaEmits, setup(__props, { emit: __emit }) { const props = __props; const emit = __emit; const { itemValidate } = useItemValidate(); const lock = ref(false); const textareaRef = ref(null); function input(e) { if (lock.value) return; emit("update:modelValue", e.target.value); change(e); } function compositionstart() { lock.value = true; } function compositionend(e) { lock.value = false; input(e); } function change(e) { emit("change", e.target.value); itemValidate("change"); } function blur(e) { emit("blur", e); itemValidate("blur"); } watch( () => props.modelValue, (val) => { if (textareaRef.value) { textareaRef.value.value = val; } } ); onMounted(() => { props.autoFocus && textareaRef.value.focus(); textareaRef.value.value = props.modelValue; }); return (_ctx, _cache) => { var _a; return openBlock(), createElementBlock("div", { class: normalizeClass(["cu-textarea", { "is-disabled": _ctx.disabled }]) }, [ createElementVNode("textarea", { class: "cu-textarea__inner", placeholder: _ctx.placeholder, maxlength: _ctx.maxlength, onInput: input, onFocus: _cache[0] || (_cache[0] = ($event) => emit("focus", $event)), onBlur: blur, onChange: change, onCompositionstart: compositionstart, onCompositionend: compositionend, ref_key: "textareaRef", ref: textareaRef, disabled: _ctx.disabled, rows: _ctx.rows }, null, 40, _hoisted_1), _ctx.maxlength ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString((((_a = _ctx.modelValue) == null ? void 0 : _a.length) || 0) + "/" + _ctx.maxlength), 1)) : createCommentVNode("", true) ], 2); }; } }); export { _sfc_main as default };