@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-9caf8482.js";import{s as n}from"./p-9c1b2f31.js";import{s as c}from"./p-c10c2190.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:"11ec6b59257413cae1709687de7f24fb6ca0522c"},i("nav",{key:"f9d1c7ba630d8938a70b6f594f8c47f4d195525d","aria-label":this.accessibilityText},i("slot",{key:"2627f9f6a71a317ed18c11f73c93139d9d9b6ee1"})))}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 r=h;const f=u;export{r as CbpSubnav,f as defineCustomElement};
//# sourceMappingURL=cbp-subnav.js.map