UNPKG

buefy

Version:

Lightweight UI components for Vue.js (v3) based on Bulma

3 lines (2 loc) 8.17 kB
/*! 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).Menu={},e.Vue)}(this,(function(e,t){"use strict";var n=t.defineComponent({provide(){return{BMenuItemContainer:this}},data:()=>({menuItems:[]}),methods:{appendMenuItem(e){this.menuItems.push(e)},removeMenuItem(e){const t=this.menuItems.indexOf(e);-1!==t&&this.menuItems.splice(t,1)}}}),o=t.defineComponent({name:"BMenu",mixins:[n],props:{accordion:{type:Boolean,default:!0},activable:{type:Boolean,default:!0}},data:()=>({_isMenu:!0})}),i=(e,t)=>{const n=e.__vccOpts||e;for(const[e,o]of t)n[e]=o;return n};const a={class:"menu"};var l=i(o,[["render",function(e,n,o,i,l,s){return t.openBlock(),t.createElementBlock("section",null,[t.createElementVNode("div",a,[t.renderSlot(e.$slots,"default")])])}]]);let s={defaultIconPack:"mdi",defaultIconComponent:null,defaultCompatFallthrough:!0,defaultLinkTags:["a","button","input","router-link","nuxt-link","n-link","RouterLink","NuxtLink","NLink"]};const r={sizes:{default:"mdi-24px","is-small":null,"is-medium":"mdi-36px","is-large":"mdi-48px"},iconPrefix:"mdi-"},c=()=>{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 u=i(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:r,fa:c(),fas:c(),far:c(),fad:c(),fab:c(),fal:c(),"fa-solid":c(),"fa-regular":c(),"fa-light":c(),"fa-thin":c(),"fa-duotone":c(),"fa-brands":c()}[this.newPack]},iconPrefix(){return this.iconConfig&&this.iconConfig.iconPrefix?this.iconConfig.iconPrefix:""},newIcon(){return`${this.iconPrefix}${this.getEquivalentIconOf(this.icon)}`},newPack(){return this.pack||s.defaultIconPack},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.defaultIconComponent}},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,o,i,a,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)}]]),d=t.defineComponent({name:"BMenuList",components:{BIcon:u},props:{label:String,icon:String,iconPack:String,ariaRole:{type:String,default:""},size:{type:String,default:"is-small"}}});const p={key:0,class:"menu-label"},m=["role"];var f=i(d,[["render",function(e,n,o,i,a,l){const s=t.resolveComponent("b-icon");return t.openBlock(),t.createElementBlock(t.Fragment,null,[e.label||e.$slots.label?(t.openBlock(),t.createElementBlock("p",p,[e.label?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[e.icon?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createVNode(s,{icon:e.icon,pack:e.iconPack,size:e.size},null,8,["icon","pack","size"]),t.createElementVNode("span",null,t.toDisplayString(e.label),1)],64)):(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},[t.createTextVNode(t.toDisplayString(e.label),1)],64))],64)):t.renderSlot(e.$slots,"label",{key:1})])):t.createCommentVNode("v-if",!0),t.createElementVNode("ul",{class:"menu-list",role:"menu"===e.ariaRole?e.ariaRole:void 0},[t.renderSlot(e.$slots,"default")],8,m)],64)}]]),h=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,y=t.defineComponent({inheritAttrs:!1,props:{compatFallthrough:{type:Boolean,default:()=>s.defaultCompatFallthrough}},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:n,id:o}=e;return((e,t)=>{var n={};for(var o in e)g.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&h)for(var o of h(e))t.indexOf(o)<0&&k.call(e,o)&&(n[o]=e[o]);return n})(e,["style","class","id"])}return this.$attrs}}}),B=t.defineComponent({name:"BMenuItem",components:{BIcon:u},mixins:[y,n],inject:{parent:{from:"BMenuItemContainer",default:null}},props:{label:String,modelValue:Boolean,expanded:Boolean,disabled:Boolean,iconPack:String,icon:String,animation:{type:String,default:"slide"},tag:{type:[String,Object],default:"a",validator:e=>"object"==typeof e||s.defaultLinkTags.indexOf(e)>=0},ariaRole:{type:String,default:""},size:{type:String,default:"is-small"}},emits:{"update:modelValue":e=>!0,"update:expanded":e=>!0},data(){return{newActive:this.modelValue,newExpanded:this.expanded}},computed:{ariaRoleMenu(){return"menuitem"===this.ariaRole?this.ariaRole:void 0}},watch:{modelValue(e){this.newActive=e},expanded(e){this.newExpanded=e}},methods:{onClick(){if(this.disabled)return;const e=this.getMenu();this.reset(this.parent,e),this.newExpanded=this.$props.expanded||!this.newExpanded,this.$emit("update:expanded",this.newExpanded),e&&e.activable&&(this.newActive=!0,this.$emit("update:modelValue",this.newActive))},reset(e,t){null!=e&&e.menuItems.forEach((n=>{n!==this&&(this.reset(n,t),(!e.$data._isMenu||e.$data._isMenu&&e.accordion)&&(n.newExpanded=!1,n.$emit("update:expanded",n.newExpanded)),t&&t.activable&&(n.newActive=!1,n.$emit("update:modelValue",n.newActive)))}))},getMenu(){let e=this.parent;for(;e&&!e.$data._isMenu;)e=e.parent;return e}},mounted(){this.parent&&this.parent.appendMenuItem(this)},beforeUnmount(){this.parent&&this.parent.removeMenuItem(this)}});const C=["role"],v={key:1};var x=i(B,[["render",function(e,n,o,i,a,l){const s=t.resolveComponent("b-icon");return t.openBlock(),t.createElementBlock("li",t.mergeProps({role:e.ariaRoleMenu},e.rootAttrs),[(t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.tag),t.mergeProps(e.fallthroughAttrs,{class:{"is-active":e.newActive,"is-expanded":e.newExpanded,"is-disabled":e.disabled,"icon-text":e.icon},onClick:n[0]||(n[0]=t=>e.onClick())}),{default:t.withCtx((()=>[e.icon?(t.openBlock(),t.createBlock(s,{key:0,icon:e.icon,pack:e.iconPack,size:e.size},null,8,["icon","pack","size"])):t.createCommentVNode("v-if",!0),e.label?(t.openBlock(),t.createElementBlock("span",v,t.toDisplayString(e.label),1)):t.renderSlot(e.$slots,"label",{key:2,expanded:e.newExpanded,active:e.newActive})])),_:3},16,["class"])),t.createCommentVNode(" sub menu items "),e.$slots.default?(t.openBlock(),t.createBlock(t.Transition,{key:0,name:e.animation,persisted:""},{default:t.withCtx((()=>[t.withDirectives(t.createElementVNode("ul",null,[t.renderSlot(e.$slots,"default")],512),[[t.vShow,e.newExpanded]])])),_:3},8,["name"])):t.createCommentVNode("v-if",!0)],16,C)}]]);const w=(e,t,n)=>{const o=n||t.name;if(null==o)throw new Error("Buefy.registerComponent: missing component name");e.component(o,t)},b={install(e){w(e,l),w(e,f,"BMenuList"),w(e,x)}};e.BMenu=l,e.BMenuItem=x,e.BMenuList=f,e.default=b,Object.defineProperty(e,"__esModule",{value:!0})}));