2 lines
3.2 KiB
JavaScript
2 lines
3.2 KiB
JavaScript
|
import{p as j,d as S,a as d,bw as T,s as _,bx as g,E as c,q as f,o as E,b as p,j as v,f as q,m as A,l as D,e as F,x as I,B as J,z as w,t as K}from"./index-7b3f5fdc.js";const L={class:"layui-textarea-wrapper"},P=["rows","cols","value","placeholder","name","disabled","maxlength"],Q={key:0,class:"layui-textarea-clear"},Z={key:1,class:"layui-texterea-count"},U=j(S({name:"LayTextarea",__name:"index",props:{modelValue:{},name:{},placeholder:{},disabled:{type:Boolean},showCount:{type:Boolean,default:!1},allowClear:{type:Boolean},cols:{},rows:{},maxlength:{},autosize:{type:[Boolean,Object],default:!1}},emits:["blur","input","update:modelValue","change","focus","clear"],setup(y,{expose:b,emit:H}){const l=y,u=H,n=d(),h=d(!1),z=T(),t=d({width:l.cols?"":"100%",height:l.rows?"":"auto",minHeight:l.rows?"":"100px",maxHeight:l.autosize?"":"auto",transition:"height 0.2s",...z}),x=function(e){const a=e.target;h.value||(u("update:modelValue",a.value),c(()=>u("input",a.value)))},s=e=>{const a=Number(n.value.style.lineHeight)||20;let o=a*e+8;return o+=o%a,o};_(()=>l.modelValue,(e,a)=>{if(g(l.autosize)){const o=(a??"").split(/\n/g).length>(e??"").split(/\n/g).length?"inc":"dec";let i=s((e==null?void 0:e.split(/\n/g).length)??0);if(n.value.clientHeight>i&&o=="dec"||n.value.clientHeight<i&&o=="inc")return;t.value.height=`${i}px`,c(()=>{var r;return n.value.scrollTo(0,((r=n.value)==null?void 0:r.scrollHeight)??0)})}});const C=function(e){u("focus",e)},V=function(e){u("blur",e)},B=e=>{const a=e.target;u("change",a.value)},$=function(){u("update:modelValue",""),u("clear")},k=()=>{h.value=!0},O=e=>{h.value=!1,x(e)},N=f(()=>{var e;return((e=l.modelValue)==null?void 0:e.length)>0}),R=f(()=>{var e;let a=String(((e=l.modelValue)==null?void 0:e.length)??0);return l.maxlength&&(a+="/"+l.maxlength),a}),M=()=>{var e;let a=Number((e=n.value)==null?void 0:e.style.height),o=0,i=0;if(g(l.autosize))if(Object.hasOwn(l.autosize,"maxHeight")){let{minHeight:r,maxHeight:m}=l.autosize;o=r,i=m}else{let{minRow:r,maxRow:m}=l.autosize;o=s(r),i=s(m)}a<o&&(a=o),a>i&&(a=i),c(()=>t.value.height=`${a}px`)};return E(()=>{if(g(l.autosize))if(Object.hasOwn(l.autosize,"maxHeight")){let{minHeight:e,maxHeight:a}=l.autosize;t.value.minHeight=`${e}px`,t.value.height=`${e}px`,t.value.maxHeight=`${a}px`}else{let{minRow:e,maxRow:a}=l.autosize;t.value.minHeight=`${s(e)}px`,t.value.height=`${s(e)}px`,t.value.maxHeight=`${s(a)}px`}l.rows&&(t.value.height=s(l.rows)+"px",t.value.maxHeight=s(l.rows)+"px")}),b({focus:()=>{c(()=>{var e;(e=n.value)==null||e.focus()})},blur:()=>{c(()=>{var e;(e=n.value)==null||e.blur()})}}),(e,a)=>(p(),v("div",L,[q("textarea",{ref_key:"textareaRef",ref:n,class:A(["layui-textarea",{"layui-textarea-disabled":e.disabled}]),rows:e.rows,cols:e.cols,value:e.modelValue,placeholder:e.placeholder,name:e.name,disabled:e.disabled,maxlength:e.maxlength,style:D(t.value),onCompositionstart:k,onCompositionend:O,onInput:x,onFocus:C,onChange:B,onBlur:V,onMouseenter:M,onMousedown:a[0]||(a[0]=()=>t.value.transition="none"),onMouseup:a[1]||(a[1]=()=>t.value.transition="height 0.2s")},null,46,P),e.allowClear&&N.value?(p(),v("span",Q,[F(I(J),{type:"layui-icon-close-fill",onClick:$})])):w("",!0),e.showCount?(p(),v("div",Z,K(R.value),1)):w("",!0)]))}}));export{U as Z};
|