buefy
Version:
Lightweight UI components for Vue.js (v3) based on Bulma
3 lines (2 loc) • 11.6 kB
JavaScript
/*! Buefy v3.0.2 | MIT License | github.com/buefy/buefy */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Input={},e.Vue)}(this,(function(e,t){"use strict";let i,n="mdi",s=null,o="on",l=!0,a=!0,r=!0,c=!0;const u={sizes:{default:"mdi-24px","is-small":null,"is-medium":"mdi-36px","is-large":"mdi-48px"},iconPrefix:"mdi-"},h=()=>{const e="fa-";return{sizes:{default:null,"is-small":null,"is-medium":e+"lg","is-large":e+"2x"},iconPrefix:e,internalIcons:{information:"info-circle",alert:"exclamation-triangle","alert-circle":"exclamation-circle","chevron-right":"angle-right","chevron-left":"angle-left","chevron-down":"angle-down","eye-off":"eye-slash","menu-down":"caret-down","menu-up":"caret-up","close-circle":"times-circle"}}};var p=(e,t)=>{const i=e.__vccOpts||e;for(const[e,n]of t)i[e]=n;return i};var d=p(t.defineComponent({name:"BIcon",props:{type:[String,Object],component:String,pack:String,icon:{type:String,required:!0},size:String,customSize:String,customClass:String,both:Boolean},computed:{iconConfig(){return{mdi:u,fa:h(),fas:h(),far:h(),fad:h(),fab:h(),fal:h(),"fa-solid":h(),"fa-regular":h(),"fa-light":h(),"fa-thin":h(),"fa-duotone":h(),"fa-brands":h()}[this.newPack]},iconPrefix(){return this.iconConfig&&this.iconConfig.iconPrefix?this.iconConfig.iconPrefix:""},newIcon(){return`${this.iconPrefix}${this.getEquivalentIconOf(this.icon)}`},newPack(){return this.pack||n},newType(){if(!this.type)return;let e=[];if("string"==typeof this.type)e=this.type.split("-");else for(const t in this.type)if(this.type[t]){e=t.split("-");break}if(e.length<=1)return;const[,...t]=e;return`has-text-${t.join("-")}`},newCustomSize(){return this.customSize||this.customSizeByPack},customSizeByPack(){if(this.iconConfig&&this.iconConfig.sizes){if(this.size&&void 0!==this.iconConfig.sizes[this.size])return this.iconConfig.sizes[this.size];if(this.iconConfig.sizes.default)return this.iconConfig.sizes.default}return null},useIconComponent(){return this.component||s}},methods:{getEquivalentIconOf(e){if(!this.both)return e;if(null==this.iconConfig)return e;const t=this.iconConfig;return t&&t.internalIcons&&t.internalIcons[e]?t.internalIcons[e]:e}}}),[["render",function(e,i,n,s,o,l){return t.openBlock(),t.createElementBlock("span",{class:t.normalizeClass(["icon",[e.newType,e.size]])},[e.useIconComponent?(t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.useIconComponent),{key:1,icon:[e.newPack,e.newIcon],size:e.newCustomSize,class:t.normalizeClass([e.customClass])},null,8,["icon","size","class"])):(t.openBlock(),t.createElementBlock("i",{key:0,class:t.normalizeClass([e.newPack,e.newIcon,e.newCustomSize,e.customClass])},null,2))],2)}]]),m=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,y=t.defineComponent({inheritAttrs:!1,props:{compatFallthrough:{type:Boolean,default:()=>a}},computed:{rootAttrs(){return this.compatFallthrough?{class:this.$attrs.class,style:this.$attrs.style,id:this.$attrs.id}:{}},fallthroughAttrs(){if(this.compatFallthrough){const e=this.$attrs,{style:t,class:i,id:n}=e;return((e,t)=>{var i={};for(var n in e)g.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&m)for(var n of m(e))t.indexOf(n)<0&&f.call(e,n)&&(i[n]=e[n]);return i})(e,["style","class","id"])}return this.$attrs}}});const k=t.defineComponent({props:{size:String,expanded:Boolean,loading:Boolean,rounded:Boolean,icon:String,iconPack:String,maxlength:[Number,String],useHtml5Validation:{type:Boolean,default:()=>r},validationMessage:String,locale:{type:[String,Array],default:()=>i},statusIcon:{type:Boolean,default:()=>c}},emits:{blur:e=>!0,focus:e=>!0},data(){return{isValid:!0,isFocused:!1,newIconPack:this.iconPack||n,_elementRef:""}},computed:{parentField(){let e=this.$parent;for(let t=0;t<3;t++)e&&!e.$data._isField&&(e=e.$parent);return e},statusType(){const{newType:e}=this.parentField||{};if(e){if("string"==typeof e)return e;for(const t in e)if(e[t])return t}},statusMessage(){if(this.parentField)return this.parentField.newMessage||this.parentField.$slots.message},iconSize(){switch(this.size){case"is-small":return this.size;case"is-medium":return;case"is-large":return"mdi"===this.newIconPack?"is-medium":""}}},methods:{focus(){const e=this.getElement();void 0!==e&&this.$nextTick((()=>{e&&e.focus()}))},onBlur(e){this.isFocused=!1,this.$emit("blur",e),this.checkHtml5Validity()},onFocus(e){this.isFocused=!0,this.$emit("focus",e)},getElement(){let e=this.$refs[this.$data._elementRef];for(;null!=e&&"object"==typeof e&&"$refs"in e;){const t=e;e=t.$refs[t.$data._elementRef]}return e},setInvalid(){const e=this.validationMessage||this.getElement().validationMessage;this.setValidity("is-danger",e)},setValidity(e,t){this.$nextTick((()=>{this.parentField&&(this.parentField.type||(this.parentField.newType=e),this.parentField.message||(this.parentField.newMessage=t))}))},checkHtml5Validity(){if(!this.useHtml5Validation)return!1;const e=this.getElement();return null!=e&&(e.checkValidity()?(this.setValidity(null,null),this.isValid=!0):(this.setInvalid(),this.isValid=!1),this.isValid)}}});var C=t.defineComponent({name:"BInput",components:{BIcon:d},mixins:[y,k],props:{modelValue:{type:[Number,String]},type:{type:String,default:"text"},lazy:{type:Boolean,default:!1},passwordReveal:Boolean,iconClickable:Boolean,hasCounter:{type:Boolean,default:()=>l},customClass:{type:String,default:""},iconRight:String,iconRightClickable:Boolean,iconRightType:String,autocomplete:String},emits:{"icon-click":e=>!0,"icon-right-click":e=>!0,"update:modelValue":e=>!0},data(){return{newValue:this.modelValue,newType:this.type,newAutocomplete:this.autocomplete||o,isPasswordVisible:!1,_elementRef:"textarea"===this.type?"textarea":"input"}},computed:{computedValue:{get(){return this.newValue},set(e){this.newValue=e,this.$emit("update:modelValue",e)}},rootClasses(){return[this.iconPosition,this.size,{"is-expanded":this.expanded,"is-loading":this.loading,"is-clearfix":!this.hasMessage}]},inputClasses(){return[this.statusType,this.size,{"is-rounded":this.rounded}]},hasIconRight(){return this.passwordReveal||this.loading||this.statusIcon&&this.statusTypeIcon||this.iconRight},rightIcon(){return this.passwordReveal?this.passwordVisibleIcon:this.iconRight?this.iconRight:this.statusTypeIcon},rightIconType(){return this.passwordReveal?"is-primary":this.iconRight?this.iconRightType||void 0:this.statusType},iconPosition(){let e="";return this.icon&&(e+="has-icons-left "),this.hasIconRight&&(e+="has-icons-right"),e},statusTypeIcon(){switch(this.statusType){case"is-success":return"check";case"is-danger":return"alert-circle";case"is-info":return"information";case"is-warning":return"alert";default:return}},hasMessage(){return!!this.statusMessage},passwordVisibleIcon(){return this.isPasswordVisible?"eye-off":"eye"},valueLength(){return"string"==typeof this.computedValue?Array.from(this.computedValue).length:"number"==typeof this.computedValue?this.computedValue.toString().length:0}},watch:{modelValue(e){const t=this.computedValue!=e;this.newValue=e,t&&this.$nextTick((()=>{!this.isValid&&this.checkHtml5Validity()}))},type(e){this.newType=e}},methods:{togglePasswordVisibility(){this.isPasswordVisible=!this.isPasswordVisible,this.newType=this.isPasswordVisible?"text":"password",this.$nextTick((()=>{this.focus()}))},iconClick(e,t){this.$emit(e,t),this.$nextTick((()=>{this.focus()}))},rightIconClick(e){this.passwordReveal?this.togglePasswordVisibility():this.iconRightClickable&&this.iconClick("icon-right-click",e)},onInput(){this.lazy||this.revalidate()},onChange(){this.lazy&&this.revalidate()},revalidate(){!this.isValid&&this.checkHtml5Validity()}}});const w=["type","autocomplete","maxlength"],B=["maxlength"],x=["type","autocomplete","maxlength"],V=["maxlength"];var v=p(C,[["render",function(e,i,n,s,o,l){const a=t.resolveComponent("b-icon");return t.openBlock(),t.createElementBlock("div",t.mergeProps({class:["control",e.rootClasses]},e.rootAttrs),[e.lazy?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},["textarea"!==e.type?t.withDirectives((t.openBlock(),t.createElementBlock("input",t.mergeProps({key:0,ref:"input",class:["input",[e.inputClasses,e.customClass]],type:e.newType,autocomplete:e.newAutocomplete,maxlength:e.maxlength,"onUpdate:modelValue":i[0]||(i[0]=t=>e.computedValue=t)},e.fallthroughAttrs,{onInput:i[1]||(i[1]=(...t)=>e.onInput&&e.onInput(...t)),onChange:i[2]||(i[2]=(...t)=>e.onChange&&e.onChange(...t)),onBlur:i[3]||(i[3]=(...t)=>e.onBlur&&e.onBlur(...t)),onFocus:i[4]||(i[4]=(...t)=>e.onFocus&&e.onFocus(...t))}),null,16,w)),[[t.vModelDynamic,e.computedValue,void 0,{lazy:!0}]]):t.withDirectives((t.openBlock(),t.createElementBlock("textarea",t.mergeProps({key:1,ref:"textarea",class:["textarea",[e.inputClasses,e.customClass]],maxlength:e.maxlength,"onUpdate:modelValue":i[5]||(i[5]=t=>e.computedValue=t)},e.fallthroughAttrs,{onInput:i[6]||(i[6]=(...t)=>e.onInput&&e.onInput(...t)),onChange:i[7]||(i[7]=(...t)=>e.onChange&&e.onChange(...t)),onBlur:i[8]||(i[8]=(...t)=>e.onBlur&&e.onBlur(...t)),onFocus:i[9]||(i[9]=(...t)=>e.onFocus&&e.onFocus(...t))}),null,16,B)),[[t.vModelText,e.computedValue,void 0,{lazy:!0}]])],64)):(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},["textarea"!==e.type?t.withDirectives((t.openBlock(),t.createElementBlock("input",t.mergeProps({key:0,ref:"input",class:["input",[e.inputClasses,e.customClass]],type:e.newType,autocomplete:e.newAutocomplete,maxlength:e.maxlength,"onUpdate:modelValue":i[10]||(i[10]=t=>e.computedValue=t)},e.fallthroughAttrs,{onInput:i[11]||(i[11]=(...t)=>e.onInput&&e.onInput(...t)),onChange:i[12]||(i[12]=(...t)=>e.onChange&&e.onChange(...t)),onBlur:i[13]||(i[13]=(...t)=>e.onBlur&&e.onBlur(...t)),onFocus:i[14]||(i[14]=(...t)=>e.onFocus&&e.onFocus(...t))}),null,16,x)),[[t.vModelDynamic,e.computedValue]]):t.withDirectives((t.openBlock(),t.createElementBlock("textarea",t.mergeProps({key:1,ref:"textarea",class:["textarea",[e.inputClasses,e.customClass]],maxlength:e.maxlength,"onUpdate:modelValue":i[15]||(i[15]=t=>e.computedValue=t)},e.fallthroughAttrs,{onInput:i[16]||(i[16]=(...t)=>e.onInput&&e.onInput(...t)),onChange:i[17]||(i[17]=(...t)=>e.onChange&&e.onChange(...t)),onBlur:i[18]||(i[18]=(...t)=>e.onBlur&&e.onBlur(...t)),onFocus:i[19]||(i[19]=(...t)=>e.onFocus&&e.onFocus(...t))}),null,16,V)),[[t.vModelText,e.computedValue]])],64)),e.icon?(t.openBlock(),t.createBlock(a,{key:2,class:t.normalizeClass(["is-left",{"is-clickable":e.iconClickable}]),icon:e.icon,pack:e.iconPack,size:e.iconSize,onClick:i[20]||(i[20]=t=>e.iconClick("icon-click",t))},null,8,["class","icon","pack","size"])):t.createCommentVNode("v-if",!0),!e.loading&&e.hasIconRight&&e.rightIcon?(t.openBlock(),t.createBlock(a,{key:3,class:t.normalizeClass(["is-right",{"is-clickable":e.passwordReveal||e.iconRightClickable}]),icon:e.rightIcon,pack:e.iconPack,size:e.iconSize,type:e.rightIconType,both:"",onClick:e.rightIconClick},null,8,["class","icon","pack","size","type","onClick"])):t.createCommentVNode("v-if",!0),e.maxlength&&e.hasCounter&&"number"!==e.type?(t.openBlock(),t.createElementBlock("small",{key:4,class:t.normalizeClass(["help counter",{"is-invisible":!e.isFocused}])},t.toDisplayString(e.valueLength)+" / "+t.toDisplayString(e.maxlength),3)):t.createCommentVNode("v-if",!0)],16)}]]);const I={install(e){((e,t)=>{const i=t.name;if(null==i)throw new Error("Buefy.registerComponent: missing component name");e.component(i,t)})(e,v)}};e.BInput=v,e.default=I,Object.defineProperty(e,"__esModule",{value:!0})}));