primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 8.74 kB
JavaScript
import e from"primevue/icons/chevrondown";import t from"primevue/icons/chevronright";import n from"primevue/ripple";import{UniqueComponentId as i,DomHandler as a}from"primevue/utils";import{mergeProps as r,openBlock as o,createElementBlock as c,Fragment as d,renderList as s,createElementVNode as l,createBlock as p,resolveDynamicComponent as b,toDisplayString as u,createCommentVNode as h,createVNode as f,Transition as v,withCtx as g,withDirectives as T,vShow as m}from"vue";import y from"primevue/accordion/style";import x from"primevue/basecomponent";var A={name:"Accordion",extends:{name:"BaseAccordion",extends:x,props:{multiple:{type:Boolean,default:!1},activeIndex:{type:[Number,Array],default:null},lazy:{type:Boolean,default:!1},expandIcon:{type:String,default:void 0},collapseIcon:{type:String,default:void 0},tabindex:{type:Number,default:0},selectOnFocus:{type:Boolean,default:!1}},style:y,provide:function(){return{$parentInstance:this}}},emits:["update:activeIndex","tab-open","tab-close","tab-click"],data:function(){return{id:this.$attrs.id,d_activeIndex:this.activeIndex}},watch:{"$attrs.id":function(e){this.id=e||i()},activeIndex:function(e){this.d_activeIndex=e}},mounted:function(){this.id=this.id||i()},methods:{isAccordionTab:function(e){return"AccordionTab"===e.type.name},isTabActive:function(e){return this.multiple?this.d_activeIndex&&this.d_activeIndex.includes(e):this.d_activeIndex===e},getTabProp:function(e,t){return e.props?e.props[t]:void 0},getKey:function(e,t){return this.getTabProp(e,"header")||t},getTabHeaderActionId:function(e){return"".concat(this.id,"_").concat(e,"_header_action")},getTabContentId:function(e){return"".concat(this.id,"_").concat(e,"_content")},getTabPT:function(e,t,n){var i=this.tabs.length,a={props:e.props||{},parent:{instance:this,props:this.$props,state:this.$data},context:{index:n,count:i,first:0===n,last:n===i-1,active:this.isTabActive(n)}};return r(this.ptm("tab.".concat(t),{tab:a}),this.ptm("accordiontab.".concat(t),{accordiontab:a}),this.ptm("accordiontab.".concat(t),a),this.ptmo(this.getTabProp(e,"pt"),t,a))},onTabClick:function(e,t,n){this.changeActiveIndex(e,t,n),this.$emit("tab-click",{originalEvent:e,index:n})},onTabKeyDown:function(e,t,n){switch(e.code){case"ArrowDown":this.onTabArrowDownKey(e);break;case"ArrowUp":this.onTabArrowUpKey(e);break;case"Home":this.onTabHomeKey(e);break;case"End":this.onTabEndKey(e);break;case"Enter":case"NumpadEnter":case"Space":this.onTabEnterKey(e,t,n)}},onTabArrowDownKey:function(e){var t=this.findNextHeaderAction(e.target.parentElement.parentElement);t?this.changeFocusedTab(e,t):this.onTabHomeKey(e),e.preventDefault()},onTabArrowUpKey:function(e){var t=this.findPrevHeaderAction(e.target.parentElement.parentElement);t?this.changeFocusedTab(e,t):this.onTabEndKey(e),e.preventDefault()},onTabHomeKey:function(e){var t=this.findFirstHeaderAction();this.changeFocusedTab(e,t),e.preventDefault()},onTabEndKey:function(e){var t=this.findLastHeaderAction();this.changeFocusedTab(e,t),e.preventDefault()},onTabEnterKey:function(e,t,n){this.changeActiveIndex(e,t,n),e.preventDefault()},findNextHeaderAction:function(e){var t=a.findSingle(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?e:e.nextElementSibling,'[data-pc-section="header"]');return t?a.getAttribute(t,"data-p-disabled")?this.findNextHeaderAction(t.parentElement):a.findSingle(t,'[data-pc-section="headeraction"]'):null},findPrevHeaderAction:function(e){var t=a.findSingle(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?e:e.previousElementSibling,'[data-pc-section="header"]');return t?a.getAttribute(t,"data-p-disabled")?this.findPrevHeaderAction(t.parentElement):a.findSingle(t,'[data-pc-section="headeraction"]'):null},findFirstHeaderAction:function(){return this.findNextHeaderAction(this.$el.firstElementChild,!0)},findLastHeaderAction:function(){return this.findPrevHeaderAction(this.$el.lastElementChild,!0)},changeActiveIndex:function(e,t,n){if(!this.getTabProp(t,"disabled")){var i=this.isTabActive(n),a=i?"tab-close":"tab-open";this.multiple?i?this.d_activeIndex=this.d_activeIndex.filter((function(e){return e!==n})):this.d_activeIndex?this.d_activeIndex.push(n):this.d_activeIndex=[n]:this.d_activeIndex=this.d_activeIndex===n?null:n,this.$emit("update:activeIndex",this.d_activeIndex),this.$emit(a,{originalEvent:e,index:n})}},changeFocusedTab:function(e,t){if(t&&(a.focus(t),this.selectOnFocus)){var n=parseInt(t.parentElement.parentElement.dataset.pcIndex,10);this.changeActiveIndex(e,this.tabs[n],n)}}},computed:{tabs:function(){var e=this;return this.$slots.default().reduce((function(t,n){return e.isAccordionTab(n)?t.push(n):n.children&&n.children instanceof Array&&n.children.forEach((function(n){e.isAccordionTab(n)&&t.push(n)})),t}),[])}},components:{ChevronDownIcon:e,ChevronRightIcon:t},directives:{ripple:n}};function I(e){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},I(e)}function P(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?P(Object(n),!0).forEach((function(t){E(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):P(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function E(e,t,n){var i;return(t="symbol"==I(i=S(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e,t){if("object"!=I(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=I(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var O=["data-pc-index","data-p-active"],H=["data-p-highlight","data-p-disabled"],_=["id","tabindex","aria-disabled","aria-expanded","aria-controls","onClick","onKeydown"],k=["id","aria-labelledby"];A.render=function(e,t,n,i,a,y){return o(),c("div",r({class:e.cx("root")},e.ptm("root")),[(o(!0),c(d,null,s(y.tabs,(function(t,n){return o(),c("div",r({key:y.getKey(t,n),class:e.cx("tab.root",{tab:t,index:n})},y.getTabPT(t,"root",n),{"data-pc-name":"accordiontab","data-pc-index":n,"data-p-active":y.isTabActive(n)}),[l("div",r({style:y.getTabProp(t,"headerStyle"),class:[e.cx("tab.header",{tab:t,index:n}),y.getTabProp(t,"headerClass")]},w(w({},y.getTabProp(t,"headerProps")),y.getTabPT(t,"header",n)),{"data-p-highlight":y.isTabActive(n),"data-p-disabled":y.getTabProp(t,"disabled")}),[l("a",r({id:y.getTabHeaderActionId(n),class:e.cx("tab.headerAction"),tabindex:y.getTabProp(t,"disabled")?-1:e.tabindex,role:"button","aria-disabled":y.getTabProp(t,"disabled"),"aria-expanded":y.isTabActive(n),"aria-controls":y.getTabContentId(n),onClick:function(e){return y.onTabClick(e,t,n)},onKeydown:function(e){return y.onTabKeyDown(e,t,n)}},w(w({},y.getTabProp(t,"headeractionprops")),y.getTabPT(t,"headeraction",n))),[t.children&&t.children.headericon?(o(),p(b(t.children.headericon),{key:0,isTabActive:y.isTabActive(n),active:y.isTabActive(n),index:n},null,8,["isTabActive","active","index"])):y.isTabActive(n)?(o(),p(b(e.$slots.collapseicon?e.$slots.collapseicon:e.collapseIcon?"span":"ChevronDownIcon"),r({key:1,class:[e.cx("tab.headerIcon"),e.collapseIcon],"aria-hidden":"true"},y.getTabPT(t,"headericon",n)),null,16,["class"])):(o(),p(b(e.$slots.expandicon?e.$slots.expandicon:e.expandIcon?"span":"ChevronRightIcon"),r({key:2,class:[e.cx("tab.headerIcon"),e.expandIcon],"aria-hidden":"true"},y.getTabPT(t,"headericon",n)),null,16,["class"])),t.props&&t.props.header?(o(),c("span",r({key:3,class:e.cx("tab.headerTitle")},y.getTabPT(t,"headertitle",n)),u(t.props.header),17)):h("",!0),t.children&&t.children.header?(o(),p(b(t.children.header),{key:4})):h("",!0)],16,_)],16,H),f(v,r({name:"p-toggleable-content"},y.getTabPT(t,"transition",n)),{default:g((function(){return[!e.lazy||y.isTabActive(n)?T((o(),c("div",r({key:0,id:y.getTabContentId(n),style:y.getTabProp(t,"contentStyle"),class:[e.cx("tab.toggleableContent"),y.getTabProp(t,"contentClass")],role:"region","aria-labelledby":y.getTabHeaderActionId(n)},w(w({},y.getTabProp(t,"contentProps")),y.getTabPT(t,"toggleablecontent",n))),[l("div",r({class:e.cx("tab.content")},y.getTabPT(t,"content",n)),[(o(),p(b(t)))],16)],16,k)),[[m,!!e.lazy||y.isTabActive(n)]]):h("",!0)]})),_:2},1040)],16,O)})),128))],16)};export{A as default};