primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 4.24 kB
JavaScript
import{UniqueComponentId as e}from"primevue/utils";import{openBlock as t,createElementBlock as a,Fragment as i,renderList as n,normalizeClass as d,createElementVNode as o,toDisplayString as s,createCommentVNode as c,createBlock as r,resolveDynamicComponent as l,createVNode as p,Transition as h,withCtx as b,withDirectives as u,vShow as v}from"vue";var x={name:"Accordion",emits:["tab-close","tab-open","update:activeIndex"],props:{multiple:{type:Boolean,default:!1},activeIndex:{type:[Number,Array],default:null},lazy:{type:Boolean,default:!1},expandIcon:{type:String,default:"pi-chevron-right"},collapseIcon:{type:String,default:"pi-chevron-down"}},data(){return{d_activeIndex:this.activeIndex}},watch:{activeIndex(e){this.d_activeIndex=e}},methods:{onTabClick(e,t,a){if(!this.isTabDisabled(t)){const t=this.isTabActive(a),i=t?"tab-close":"tab-open";this.multiple?t?this.d_activeIndex=this.d_activeIndex.filter((e=>e!==a)):this.d_activeIndex?this.d_activeIndex.push(a):this.d_activeIndex=[a]:this.d_activeIndex=this.d_activeIndex===a?null:a,this.$emit("update:activeIndex",this.d_activeIndex),this.$emit(i,{originalEvent:e,index:a})}},onTabKeydown(e,t,a){13===e.which&&this.onTabClick(e,t,a)},isTabActive(e){return this.multiple?this.d_activeIndex&&this.d_activeIndex.includes(e):e===this.d_activeIndex},getKey:(e,t)=>e.props&&e.props.header?e.props.header:t,isTabDisabled:e=>e.props&&e.props.disabled,getTabClass(e){return["p-accordion-tab",{"p-accordion-tab-active":this.isTabActive(e)}]},getTabHeaderClass(e,t){return["p-accordion-header",{"p-highlight":this.isTabActive(t),"p-disabled":this.isTabDisabled(e)}]},getTabAriaId(e){return this.ariaId+"_"+e},getHeaderCollapseIcon(){return["p-accordion-toggle-icon pi",this.collapseIcon]},getHeaderExpandIcon(){return["p-accordion-toggle-icon pi",this.expandIcon]},isAccordionTab:e=>"AccordionTab"===e.type.name},computed:{tabs(){const e=[];return this.$slots.default().forEach((t=>{this.isAccordionTab(t)?e.push(t):t.children&&t.children instanceof Array&&t.children.forEach((t=>{this.isAccordionTab(t)&&e.push(t)}))})),e},ariaId:()=>e()}};const g={class:"p-accordion p-component"},I=["onClick","onKeydown","tabindex","aria-expanded","id","aria-controls"],T={key:0,class:"p-accordion-header-text"},y=["id","aria-labelledby"],m={class:"p-accordion-content"};!function(e,t){void 0===t&&(t={});var a=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===a&&i.firstChild?i.insertBefore(n,i.firstChild):i.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}("\n.p-accordion-header-link {\n cursor: pointer;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n position: relative;\n text-decoration: none;\n}\n.p-accordion-header-link:focus {\n z-index: 1;\n}\n.p-accordion-header-text {\n line-height: 1;\n}\n"),x.render=function(e,x,f,A,_,k){return t(),a("div",g,[(t(!0),a(i,null,n(k.tabs,((e,i)=>(t(),a("div",{key:k.getKey(e,i),class:d(k.getTabClass(i))},[o("div",{class:d(k.getTabHeaderClass(e,i))},[o("a",{role:"tab",class:"p-accordion-header-link",onClick:t=>k.onTabClick(t,e,i),onKeydown:t=>k.onTabKeydown(t,e,i),tabindex:k.isTabDisabled(e)?null:"0","aria-expanded":k.isTabActive(i),id:k.getTabAriaId(i)+"_header","aria-controls":k.getTabAriaId(i)+"_content"},[o("span",{class:d(k.isTabActive(i)?k.getHeaderCollapseIcon():k.getHeaderExpandIcon())},null,2),e.props&&e.props.header?(t(),a("span",T,s(e.props.header),1)):c("",!0),e.children&&e.children.header?(t(),r(l(e.children.header),{key:1})):c("",!0)],40,I)],2),p(h,{name:"p-toggleable-content"},{default:b((()=>[!f.lazy||k.isTabActive(i)?u((t(),a("div",{key:0,class:"p-toggleable-content",role:"region",id:k.getTabAriaId(i)+"_content","aria-labelledby":k.getTabAriaId(i)+"_header"},[o("div",m,[(t(),r(l(e)))])],8,y)),[[v,!!f.lazy||k.isTabActive(i)]]):c("",!0)])),_:2},1024)],2)))),128))])};export{x as default};