@cbpds/web-components
Version:
Web components for the CBP Design System.
5 lines • 2.49 kB
JavaScript
/*!
* CPB Design System web components - built with Stencil
*/
import{p as t,H as s,h as i,c as e}from"./p-e7f1ba21.js";import{s as n}from"./p-9c1b2f31.js";import{s as c}from"./p-0ebcb99a.js";const a="cbp-subnav{display:block}";const o=a;const h=t(class t extends s{constructor(){super();this.__registerHost();this.subnavItems=[];this.activeItem=null;this.accessibilityText="Sub-Navigation";this.flat=undefined;this.store=undefined;this.context=undefined;this.sx={}}updateActiveItem(t){const s=this.host.querySelector(`cbp-subnav-item[name="${t}"]`);this.activeItem=s;this.subnavItems.forEach((t=>{t.open=false}));if(s)s.open=true;setTimeout((()=>{s===null||s===void 0?void 0:s.querySelector("a").focus()}),101)}updateCurrent(t){const s=this.host.querySelector(`cbp-subnav-item[name="${t}"]`);this.currentItem=s;this.subnavItems.forEach((t=>{if(t==s)t.current=true;else t.current=false}))}handleSubnavItemClick({detail:{host:t}}){this.subnavItems.forEach((s=>{if(t==s){if(this.store){const i=this.findParent(s);c.currentPage=t.name;c.currentParent=i.name}}else{s.current=false}}))}findParent(t){const s=t.parentElement.closest("cbp-subnav-item");if(!s)return t;else return this.findParent(s)}componentWillLoad(){this.subnavItems=Array.from(this.host.querySelectorAll("cbp-subnav-item"));this.currentItem=this.host.querySelector("cbp-subnav-item[current]");this.subnavItems.forEach((t=>{t.addEventListener("subnavItemClick",(t=>{this.handleSubnavItemClick(t)}))}));if(typeof this.sx=="string"){this.sx=JSON.parse(this.sx)||{}}n(this.host,Object.assign({},this.sx))}render(){var t,s;if(this.store){if(((t=this.currentItem)===null||t===void 0?void 0:t.name)!=c.currentPage){this.updateCurrent(c.currentPage)}if(((s=this.activeItem)===null||s===void 0?void 0:s.name)!=c.activeItemName){this.updateActiveItem(c.activeItemName)}}return i(e,{key:"d8ca51f29c562f48785b0fddcc6cf8be74959e8c"},i("nav",{key:"3e8ddc4953099861c9f1986d81310658cb179556","aria-label":this.accessibilityText},i("slot",{key:"13b66d3390cba32db0139c462e1c4007b6c9f283"})))}get host(){return this}static get style(){return o}},[4,"cbp-subnav",{accessibilityText:[1,"accessibility-text"],flat:[516],store:[4],context:[513],sx:[8]}]);function u(){if(typeof customElements==="undefined"){return}const t=["cbp-subnav"];t.forEach((t=>{switch(t){case"cbp-subnav":if(!customElements.get(t)){customElements.define(t,h)}break}}))}const b=h;const r=u;export{b as CbpSubnav,r as defineCustomElement};
//# sourceMappingURL=cbp-subnav.js.map