buefy
Version:
Lightweight UI components for Vue.js (v3) based on Bulma
3 lines (2 loc) • 5.75 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).Rate={},e.Vue)}(this,(function(e,t){"use strict";let n,i="mdi",o=null;const s={sizes:{default:"mdi-24px","is-small":null,"is-medium":"mdi-36px","is-large":"mdi-48px"},iconPrefix:"mdi-"},l=()=>{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 a=(e,t)=>{const n=e.__vccOpts||e;for(const[e,i]of t)n[e]=i;return n};var r=a(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:s,fa:l(),fas:l(),far:l(),fad:l(),fab:l(),fal:l(),"fa-solid":l(),"fa-regular":l(),"fa-light":l(),"fa-thin":l(),"fa-duotone":l(),"fa-brands":l()}[this.newPack]},iconPrefix(){return this.iconConfig&&this.iconConfig.iconPrefix?this.iconConfig.iconPrefix:""},newIcon(){return`${this.iconPrefix}${this.getEquivalentIconOf(this.icon)}`},newPack(){return this.pack||i},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||o}},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,n,i,o,s,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)}]]);const c=t.defineComponent({name:"BRate",components:{BIcon:r},props:{modelValue:{type:Number,default:0},max:{type:Number,default:5},icon:{type:String,default:"star"},iconPack:String,size:String,spaced:Boolean,rtl:Boolean,disabled:Boolean,showScore:Boolean,showText:Boolean,customText:String,texts:Array,locale:{type:[String,Array],default:()=>n}},emits:{change:e=>!0,"update:modelValue":e=>!0},data(){return{newValue:this.modelValue,hoverValue:0}},computed:{halfStyle(){return`width:${this.valueDecimal}%`},showMe(){let e="";return this.showScore?(e=this.disabled?this.modelValue.toString():this.newValue.toString(),e=0===Number(e)?"":new Intl.NumberFormat(this.locale).format(this.modelValue)):this.showText&&this.texts&&(e=this.texts[Math.ceil(this.newValue)-1]),e},valueDecimal(){return 100*this.modelValue-100*Math.floor(this.modelValue)}},watch:{modelValue(e){this.newValue=e}},methods:{resetNewValue(){this.disabled||(this.hoverValue=0)},previewRate(e,t){this.disabled||(this.hoverValue=e,t.stopPropagation())},confirmValue(e){this.disabled||(this.newValue=e,this.$emit("change",this.newValue),this.$emit("update:modelValue",this.newValue))},checkHalf(e){return this.disabled&&this.valueDecimal>0&&e-1<this.modelValue&&e>this.modelValue},rateClass(e){let t="";return e<=(0!==this.hoverValue?this.hoverValue:this.newValue)?t="set-on":this.disabled&&Math.ceil(this.modelValue)===e&&(t="set-half"),t}}}),u=["onMousemove","onClick"],m={key:0};var h=a(c,[["render",function(e,n,i,o,s,l){const a=t.resolveComponent("b-icon");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["rate",{"is-disabled":e.disabled,"is-spaced":e.spaced,"is-rtl":e.rtl}])},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.max,((i,o)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["rate-item",e.rateClass(i)]),key:o,onMousemove:t=>e.previewRate(i,t),onMouseleave:n[0]||(n[0]=(...t)=>e.resetNewValue&&e.resetNewValue(...t)),onClick:t.withModifiers((t=>e.confirmValue(i)),["prevent"])},[t.createVNode(a,{pack:e.iconPack,icon:e.icon,size:e.size},null,8,["pack","icon","size"]),e.checkHalf(i)?(t.openBlock(),t.createBlock(a,{key:0,class:"is-half",pack:e.iconPack,icon:e.icon,size:e.size,style:t.normalizeStyle(e.halfStyle)},null,8,["pack","icon","size","style"])):t.createCommentVNode("v-if",!0)],42,u)))),128)),e.showText||e.showScore||e.customText?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["rate-text",e.size])},[t.createElementVNode("span",null,t.toDisplayString(e.showMe),1),e.customText&&!e.showText?(t.openBlock(),t.createElementBlock("span",m,t.toDisplayString(e.customText),1)):t.createCommentVNode("v-if",!0)],2)):t.createCommentVNode("v-if",!0)],2)}]]);const f={install(e){((e,t)=>{const n=t.name;if(null==n)throw new Error("Buefy.registerComponent: missing component name");e.component(n,t)})(e,h)}};e.BRate=h,e.default=f,Object.defineProperty(e,"__esModule",{value:!0})}));