+(function(e,d){typeof exports=="object"&&typeof module<"u"?d(require("vue")):typeof define=="function"&&define.amd?define(["vue"],d):(e=typeof globalThis<"u"?globalThis:e||self,d(e.Vue))})(this,function(e){"use strict";const d="",W="",y={key:0,class:"float-label__label float-label--no-click"},E={class:"float-label__label__text"},V=["for"],g={key:0,class:"float-label__label__bg"},N=e.createTextVNode(),T={class:"float-label__label__text"},s={__name:"FloatLabel",props:{label:{type:String,default:""},float:{type:Boolean,default:null},onFocus:{type:Boolean,default:!1}},setup(_){const a=_;let u=e.ref(null),r=e.ref(""),o=e.ref("");e.ref(a.label);let t=e.ref({}),c=e.ref(""),n=e.ref(""),f=e.ref(!1),m=e.ref(!1),h=e.ref(!1);const L="[type=date], [type=datetime-local], [type=datetime], [type=email], [type=month], [type=number], [type=password], [type=search], [type=tel], [type=text], [type=time], [type=url], [type=week], textarea, select",b=e.computed(()=>a.label),U=e.computed(()=>n.value==="select"?!0:o.value&&r.value!==o.value),$=e.computed(()=>{let l=!1;return a.float?l=!0:l=f.value&&f.value!=="0",l}),x=()=>{r.value=b.value?a.label:o.value},j=()=>t.value.getAttribute("id"),A=()=>([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,i=>(i^crypto.getRandomValues(new Uint8Array(1))[0]&15>>i/4).toString(16)),I=()=>{switch(n.value){case"input":case"textarea":return t.value.placeholder;case"select":let l=t.value.querySelector("option:disabled");return l?l.innerHTML:"";default:return""}},M=()=>{c.value||(c.value=A(),t.value.id=c.value)},q=()=>{n.value==="select"?t.value.addEventListener("change",p):t.value.addEventListener("input",p)},D=()=>{n.value==="select"?t.value.removeEventListener("change",p):t.value.removeEventListener("input",p)},p=l=>{f.value=l.target.value.length>0};return e.watch(b,(l,i)=>{x()}),e.onMounted(()=>{t.value=u.value.querySelector(L),m.value=!!t.value,h.value=a.float===null,m.value?(c.value=j(),n.value=t.value?t.value.tagName.toLowerCase():"",f.value=!!t.value.value,o.value=I(),M(),h.value===!0&&setTimeout(()=>{q()},200)):o.value="",x()}),e.onBeforeUnmount(()=>{m.value&&D()}),(l,i)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["float-label",{"float-label--fade-anim":e.unref(U),"float-label--on-focus":a.onFocus,"float-label--fixed":e.unref($)}]),ref_key:"root",ref:u},[e.renderSlot(l.$slots,"default"),e.unref(n)===""?(e.openBlock(),e.createElementBlock("div",y,[e.createElementVNode("span",E,e.toDisplayString(e.unref(r)),1)])):(e.openBlock(),e.createElementBlock("label",{key:1,class:e.normalizeClass(["float-label__label",{"float-label--no-click":e.unref(n)==="select"}]),for:e.unref(c)},[e.unref(n)==="textarea"?(e.openBlock(),e.createElementBlock("span",g)):e.createCommentVNode("",!0),N,e.createElementVNode("span",T,e.toDisplayString(e.unref(r)),1)],10,V))],2))}},k=e.createElementVNode("input",{id:"justin-id",type:"text",placeholder:"This is placeholder text"},null,-1),w=e.createElementVNode("input",{type:"text"},null,-1),C=e.createElementVNode("textarea",{name:"textarea",id:"textarea",cols:"30",rows:"10",placeholder:"This is a text area"},null,-1),B=e.createElementVNode("select",{name:"justins-select",id:"justins-select"},[e.createElementVNode("option",{value:"",disabled:"disabled",selected:""},"Select a number"),e.createElementVNode("option",{value:"1"},"one"),e.createElementVNode("option",{value:"2"},"two"),e.createElementVNode("option",{value:"3"},"three"),e.createElementVNode("option",{value:"4"},"four"),e.createElementVNode("option",{value:"5"},"five")],-1),F=e.createElementVNode("div",{style:{padding:"24px",border:"1px solid red"}},null,-1),S={__name:"App",setup(_){let a=e.ref("This is existing v-model text");return(u,r)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createVNode(s,{label:"This is label text"},{default:e.withCtx(()=>[k]),_:1}),e.createVNode(s,{label:"This has no placeholder but a :label prop"},{default:e.withCtx(()=>[w]),_:1}),e.createVNode(s,null,{default:e.withCtx(()=>[C]),_:1}),e.createVNode(s,{label:"Select a big number"},{default:e.withCtx(()=>[B]),_:1}),e.createVNode(s,null,{default:e.withCtx(()=>[e.withDirectives(e.createElementVNode("input",{type:"text","onUpdate:modelValue":r[0]||(r[0]=o=>e.isRef(a)?a.value=o:a=o),placeholder:"Pre-filled Text"},null,512),[[e.vModelText,e.unref(a)]])]),_:1}),e.createVNode(s,{label:"This is a <div> with a red border"},{default:e.withCtx(()=>[F]),_:1})],64))}};e.createApp(S).mount("#app")});
0 commit comments