UNPKG

dk-plus

Version:
2 lines (1 loc) 4.81 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("vue"),S=require("../../_tokens/component/index.js"),c=require("../public/get-color/index.js"),I=require("../public/get-StyleList/index.js"),x=require("../public/set-size/index.js");require("../../_icon/index.js");const J=e=>{let n=["type","size","personality","personalityType"];const t={...u.toRaw(e)},s=u.useSlots(),d=e.prependText||e.prependIcon||s.prepend,r=e.appendText||e.appendIcon||s.append;!t.personality&&r&&d?(t.appendText="wrapper-pend_text",t.prependText=""):(!t.personality&&r&&(t.appendText="wrapper-append_text"),!t.personality&&d&&(t.prependText="wrapper-prepend_text"));const i=t;u.computed(()=>t.disabled).value&&(n=[...n,"disabled"]);let h="input";t.personality&&S.DK_INPUT_PERSONALITY_TYPE.includes(t.personalityType)&&(h="input-personality");const{classes:C}=I.getStyleList(i,h),R=C([...n],"dk-"+h),j=u.computed(()=>{const{width:a,height:w,fontSize:b,borderRadius:L,textColor:m,iconSize:_,align:M,borderColor:Y,focusBorderColor:W,border:F,labelText:G}=t;let g=Y,P=W;const z={warning:"#faad14",error:"#ff4d4f"};t.status&&S.DK_INPUT_STATUS.includes(t.status)&&(g=z[t.status],P=z[t.status]);let A="transparent",B="transparent",$="transparent";(H=>{H!=="none"&&(A=g?c.getColor(g).getDodge(0):null,B=g?c.getColor(g).getDodge(.4):null,$=P?c.getColor(P).getDodge(0):null)})(F);const o={"--input-align":M||"left"};return G&&(o["--input-margin-top"]=b?x.setSize(b):"18px"),P&&(o["--input-focus-border"]=$),g&&(o["--input-border"]=A,o["--input-hover-border"]=B),a&&(o["--input-width"]=x.setSize(a)),w&&(o["--input-height"]=x.setSize(w)),b&&(o["--input-font-size"]=x.setSize(b)),L&&(o["--input-border-radius"]=x.setSize(L)),m&&(o["--input-text-color"]=c.getColor(m).getDeepen(0)),_&&(o["--input-icon-size"]=x.setSize(_)),o});let y=["appendText","prependText","readonly"];t.status&&S.DK_INPUT_STATUS.includes(t.status)&&(y=[...y,"status"]);const q=C([...y],`dk-${h}-wrapper`),v=I.getStyleList(i,"input").classes,E=v([...[]],`dk-${h}_inner`),O=["clearable"],U=I.getStyleList(i,"input").classes,V=U([...O],"dk-input"),K=u.computed(()=>{const{appendBackground:a,appendColor:w}=t;return{"--pend-background":a?c.getColor(a).getDeepen(0):null,"--pend-hover-background":a?c.getColor(a).getDeepen(.4):null,"--pend-color":w?c.getColor(w).getDeepen(0):null}});return{classList:R,styleList:j,wrapperClassList:q,innerClassList:E,clearableClassList:V,pendStyleList:K}},l=e=>e.length==0?!1:e.find(t=>!t)===void 0,p=e=>e.length==0?!1:e.find(t=>t)!==void 0,f=e=>{if(!e)return!1;if(Array.isArray(e)){if(e.length===0)return!1}else if(e=e.toString().trim(),typeof e=="string"&&e.length===0)return!1;return!0},Q=(e,n)=>{let t=e;return e==="password"?n?t="text":t="password":t=e,t},k=(e,n,t)=>{const s=p([f(e),f(n)]);return l([s,!t])},N=(e,n,t)=>l([!n,t!=="textarea",t!=="password",e]),X=(e,n,t,s,d)=>{typeof e=="number"&&(e=e.toString());let r=e;if(n&&!t){const i=new RegExp(`^${n}`);r=r.replace(i,"")}if(s&&!d){const i=new RegExp(`${s}$`);r=r.replace(i,"")}return r},Z=(e,n,t,s,d)=>{typeof e=="number"&&(e=e.toString());let r=e;return n&&!t&&(new RegExp(`^${n}`).test(e)||(r=n+e)),s&&!d&&(new RegExp(`${s}$`).test(e)||(r=r+s)),r},D=(e,n)=>{if(!e.showLengthProp)return!1;let s=!1;const i=p([n==="textarea",n==="text"]),T=!e.maxlengthProp;return s=l([i,T]),s},ee=(e,n,t)=>u.reactive({isPrepend:p([!!n.prepend,f(e.prependText),!!e.prependIcon]),isPrependIcon:l([f(e.prependIcon),!n.prepend]),isAppendIcon:l([!n.append,!!e.appendIcon]),isAppend:p([!!n.append,f(e.appendText),!!e.appendIcon]),isPrefixIcon:l([!!e.prefixIcon,!n.prefix]),isAppendTextLen:f(e.appendText),isPrefix:p([!!n.prefix,!!e.prefixIcon]),isClear:N(e.clearable,e.disabledProp,t),inputmode:t==="number"?"numeric":"text",isSuffix:p([!!n.suffix,!!e.suffixIcon]),isSuffixIcon:l([!!e.suffixIcon,!n.suffix]),isShowPassword:l([t==="password",e.showPassword]),isLength:k(e.maxlengthProp,e.minlengthProp,e.disabledProp),rows:e.rowsProp||2,showLength:D(e,t),labelText:e.labelTextProp,personality:e.personalityProp}),te=e=>u.reactive({prependText:e.prependText,appendText:e.appendText,placeholder:e.placeholder,clearable:e.clearable,showPassword:e.showPassword,prependIcon:e.prependIcon,appendIcon:e.appendIcon,disabledProp:e.disabled,typeProp:e.type,prefixIcon:e.prefixIcon,suffixIcon:e.suffixIcon,maxlengthProp:e.maxlength,minlengthProp:e.minlength,autosizeProp:e.autosize,rowsProp:e.rows,readonlyProp:e.readonly,showLengthProp:e.showLength,labelTextProp:e.labelText,personalityProp:e.personality});exports.getBooleanAnd=l;exports.getBooleanOr=p;exports.getInput=J;exports.getIsClear=N;exports.getNull=f;exports.getPendValue=Z;exports.getValue=X;exports.isShowLength=k;exports.setData=ee;exports.setPropData=te;exports.verifyInputType=Q;