UNPKG

buefy

Version:

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

3 lines (2 loc) 12 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).Tabs={},e.Vue)}(this,(function(e,t){"use strict";let i="mdi",n=null,s=!1,o=!0,a=null;function l(e,t){return(e&t)===t}function r(e,t,i){return Math.max(t,Math.min(i,e))}const c={sizes:{default:"mdi-24px","is-small":null,"is-medium":"mdi-36px","is-large":"mdi-48px"},iconPrefix:"mdi-"},u=()=>{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 d=(e,t)=>{const i=e.__vccOpts||e;for(const[e,n]of t)i[e]=n;return i};var h=d(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:c,fa:u(),fas:u(),far:u(),fad:u(),fab:u(),fal:u(),"fa-solid":u(),"fa-regular":u(),"fa-light":u(),"fa-thin":u(),"fa-duotone":u(),"fa-brands":u()}[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||n}},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,a){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=t.defineComponent({name:"BSlotComponent",props:{component:{type:Object,required:!0},name:{type:String,default:"default"},scoped:{type:Boolean},props:{type:Object},tag:{type:[String,Object],default:"div"}},methods:{refresh(){this.$forceUpdate()}},render(){return t.h(this.tag,{},this.component.$slots?this.scoped?this.component.$slots[this.name](this.props):this.component.$slots[this.name]():void 0)}}),p=Object.defineProperty,f=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,g=(e,t,i)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var y,I=(e,t)=>{const i={provide(){return{["b"+e]:this}}};return l(t,1)&&(i.data=function(){return((e,t)=>{for(var i in t||(t={}))v.call(t,i)&&g(e,i,t[i]);if(f)for(var i of f(t))b.call(t,i)&&g(e,i,t[i]);return e})({childItems:[]},l(t,3)?{nextIndex:0}:{})},i.methods={_registerItem(e){l(t,3)&&(e.dynamicIndex=this.nextIndex,++this.nextIndex),this.childItems.push(e)},_unregisterItem(e){this.childItems=this.childItems.filter((t=>t.uniqueValue!==e.uniqueValue))}},l(t,3)&&(i.computed={sortedItems(){return this.childItems.slice().sort(((e,t)=>e.index-t.index))}})),i},x=t.defineComponent({name:"BTabs",components:{BIcon:h,BSlotComponent:m},mixins:[(y="tab",t.defineComponent({components:{BIcon:h,BSlotComponent:m},mixins:[I(y,3)],props:{modelValue:{type:[String,Number,null],default:void 0},size:String,animated:{type:Boolean,default:!0},animation:String,animateInitially:Boolean,vertical:{type:Boolean,default:!1},position:String,destroyOnHide:{type:Boolean,default:!1}},emits:{"update:modelValue":e=>!0},data(){return{activeId:this.modelValue,defaultSlots:[],contentHeight:0,isTransitioning:!1}},computed:{activeItem(){const e=this.childItems;return void 0===this.activeId?this.items[0]:null===this.activeId?null:e.find((e=>e.uniqueValue===this.activeId))},items(){return this.sortedItems}},watch:{modelValue(e){"number"==typeof e?(e=r(e,0,this.items.length-1),this.activeId=this.items[e].uniqueValue):this.activeId=e},activeId(e,t){const i=null!=t?this.childItems.find((e=>e.uniqueValue===t)):null;i&&this.activeItem&&(i.deactivate(this.activeItem.index),this.activeItem.activate(i.index)),(e=this.activeItem?"number"==typeof this.modelValue?this.items.indexOf(this.activeItem):this.activeItem.uniqueValue:void 0)!==this.modelValue&&this.$emit("update:modelValue",e)}},methods:{childClick(e){this.activeId=e.uniqueValue},getNextItemIdx(e,t=!1){let i=null;for(let n=0;n<this.items.length;n++){const s=this.items[n];if(e<s.index&&s.visible&&(!t||t&&!s.disabled)){i=s.index;break}}return i},getPrevItemIdx(e,t=!1){let i=null;for(let n=this.items.length-1;n>=0;n--){const s=this.items[n];if(s.index<e&&s.visible&&(!t||t&&!s.disabled)){i=s.index;break}}return i}},mounted(){if("number"==typeof this.modelValue){const e=r(this.modelValue,0,this.items.length-1);this.activeId=this.items[e].uniqueValue}else this.activeId=this.modelValue}}))],props:{expanded:{type:Boolean,default:()=>s},type:{type:[String,Object],default:()=>a},animated:{type:Boolean,default:()=>o},multiline:Boolean},data:()=>({currentFocus:null}),computed:{mainClasses(){return{"is-fullwidth":this.expanded,"is-vertical":this.vertical,"is-multiline":this.multiline,[this.position]:this.position&&this.vertical}},navClasses(){return[this.type,this.size,{[this.position]:this.position&&!this.vertical,"is-fullwidth":this.expanded,"is-toggle":"is-toggle-rounded"===this.type}]}},methods:{giveFocusToTab(e){Array.isArray(e)&&null==(e=e[0])||(e.$el&&e.$el.focus?e.$el.focus():e.focus&&e.focus())},manageTablistKeydown(e){const{key:t}=e;switch(t){case this.vertical?"ArrowUp":"ArrowLeft":case this.vertical?"Up":"Left":{let t=this.getPrevItemIdx(this.currentFocus,!0);null===t&&(t=this.getPrevItemIdx(1/0,!0));const i=this.items.find((e=>e.index===t));i&&this.$refs[`tabLink${t}`]&&!i.disabled&&this.giveFocusToTab(this.$refs[`tabLink${t}`]),e.preventDefault();break}case this.vertical?"ArrowDown":"ArrowRight":case this.vertical?"Down":"Right":{let t=this.getNextItemIdx(this.currentFocus,!0);null===t&&(t=this.getNextItemIdx(-1,!0));const i=this.items.find((e=>e.index===t));i&&this.$refs[`tabLink${t}`]&&!i.disabled&&this.giveFocusToTab(this.$refs[`tabLink${t}`]),e.preventDefault();break}}},manageTabKeydown(e,t){const{key:i}=e;switch(i){case" ":case"Space":case"Spacebar":case"Enter":this.childClick(t),e.preventDefault()}}}});const C=["aria-orientation"],k=["aria-controls","aria-selected"],w=["id","tabindex","onFocus","onClick","onKeydown"];var B=d(x,[["render",function(e,i,n,s,o,a){const l=t.resolveComponent("b-slot-component"),r=t.resolveComponent("b-icon");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["b-tabs",e.mainClasses])},[t.createElementVNode("nav",{class:t.normalizeClass(["tabs",e.navClasses]),onKeydown:i[0]||(i[0]=(...t)=>e.manageTablistKeydown&&e.manageTablistKeydown(...t))},[t.renderSlot(e.$slots,"start"),t.createElementVNode("ul",{"aria-orientation":e.vertical?"vertical":"horizontal",role:"tablist"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.items,(i=>t.withDirectives((t.openBlock(),t.createElementBlock("li",{key:i.uniqueValue,class:t.normalizeClass([i.headerClass,{"is-active":i.isActive,"is-disabled":i.disabled}]),role:"tab","aria-controls":`${i.uniqueValue}-content`,"aria-selected":`${i.isActive}`},[i.$slots.header?(t.openBlock(),t.createBlock(l,{key:0,ref_for:!0,ref:`tabLink${i.index}`,component:i,name:"header",tag:"a",id:`${i.uniqueValue}-label`,tabindex:i.isActive?0:-1,onFocus:t=>e.currentFocus=i.index,onClick:t=>e.childClick(i),onKeydown:t=>e.manageTabKeydown(t,i)},null,8,["component","id","tabindex","onFocus","onClick","onKeydown"])):(t.openBlock(),t.createElementBlock("a",{key:1,ref_for:!0,ref:`tabLink${i.index}`,id:`${i.uniqueValue}-label`,tabindex:i.isActive?0:-1,onFocus:t=>e.currentFocus=i.index,onClick:t=>e.childClick(i),onKeydown:t=>e.manageTabKeydown(t,i)},[i.icon?(t.openBlock(),t.createBlock(r,{key:0,icon:i.icon,pack:i.iconPack,size:e.size},null,8,["icon","pack","size"])):t.createCommentVNode("v-if",!0),t.createElementVNode("span",null,t.toDisplayString(i.label),1)],40,w))],10,k)),[[t.vShow,i.visible]]))),128))],8,C),t.renderSlot(e.$slots,"end")],34),t.createElementVNode("section",{class:t.normalizeClass(["tab-content",{"is-transitioning":e.isTransitioning}])},[t.renderSlot(e.$slots,"default")],2)],2)}]]),S=Object.defineProperty,z=Object.defineProperties,$=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,T=(e,t,i)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,q=(e,t)=>{for(var i in t||(t={}))O.call(t,i)&&T(e,i,t[i]);if(V)for(var i of V(t))P.call(t,i)&&T(e,i,t[i]);return e},j=(e,t)=>z(e,$(t));var E,A=(e,t)=>{const i={inject:{parent:{from:"b"+e,default:""}},props:{value:{type:String,default:null}},computed:{uniqueValue(){return null!=this.value?this.value:this.$.uid}},created(){if(this.parent)this.parent._registerItem&&this.parent._registerItem(this);else if(!l(t,2))throw new Error("You should wrap "+this.$options.name+" in a "+e)},beforeUnmount(){this.parent&&this.parent._unregisterItem&&this.parent._unregisterItem(this)}};return l(t,1)&&(i.props=j(q({},i.props),{order:{type:Number,required:!1}}),i.data=()=>({dynamicIndex:void 0}),i.computed=j(q({},i.computed),{index(){return null!=this.order?this.order:this.dynamicIndex}})),i},N=t.defineComponent({name:"BTabItem",mixins:[(E="tab",t.defineComponent({mixins:[A(E,1)],props:{label:String,icon:String,iconPack:String,visible:{type:Boolean,default:!0},headerClass:{type:[String,Array,Object],default:null}},data:()=>({transitionName:null,elementClass:"item",elementRole:null}),computed:{isActive(){return this.parent.activeItem===this}},methods:{activate(e){this.transitionName=this.index<e?this.parent.vertical?"slide-down":"slide-next":this.parent.vertical?"slide-up":"slide-prev"},deactivate(e){this.transitionName=e<this.index?this.parent.vertical?"slide-down":"slide-next":this.parent.vertical?"slide-up":"slide-prev"}},render(){var e;if(this.parent.destroyOnHide&&(!this.isActive||!this.visible))return;const i=t.withDirectives(t.h("div",{class:this.elementClass,role:this.elementRole,id:`${this.uniqueValue}-content`,"aria-labelledby":this.elementRole?`${this.uniqueValue}-label`:null,tabindex:this.isActive?0:-1},this.$slots),[[t.vShow,this.isActive&&this.visible]]);return this.parent.animated?t.h(t.Transition,{name:null!=(e=this.parent.animation||this.transitionName)?e:void 0,appear:!0===this.parent.animateInitially||void 0,onBeforeEnter:()=>{this.parent.isTransitioning=!0},onAfterEnter:()=>{this.parent.isTransitioning=!1}},{default:()=>i}):i}}))],props:{disabled:Boolean},data:()=>({elementClass:"tab-item",elementRole:"tabpanel"})});const F=(e,t,i)=>{const n=t.name;if(null==n)throw new Error("Buefy.registerComponent: missing component name");e.component(n,t)},_={install(e){F(e,B),F(e,N)}};e.BTabItem=N,e.BTabs=B,e.default=_,Object.defineProperty(e,"__esModule",{value:!0})}));