@cbpds/web-components
Version:
Web components for the CBP Design System.
5 lines • 2.11 kB
JavaScript
/*!
* CPB Design System web components - built with Stencil
*/
import{r as t,h as s,a as i,g as e}from"./p-8d4a80f0.js";import{s as a}from"./p-93ade441.js";import{s as n}from"./p-5563068d.js";const h="cbp-subnav{display:block}";const d=h;const c=class{constructor(s){t(this,s);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);n.currentPage=t.name;n.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)||{}}a(this.host,Object.assign({},this.sx))}render(){var t,e;if(this.store){if(((t=this.currentItem)===null||t===void 0?void 0:t.name)!=n.currentPage){this.updateCurrent(n.currentPage)}if(((e=this.activeItem)===null||e===void 0?void 0:e.name)!=n.activeItemName){this.updateActiveItem(n.activeItemName)}}return s(i,{key:"cdc3dde8ba574bbdb004468b9beaa0cd58e6e315"},s("nav",{key:"bf95dd6da6b1b7a6fa8a5c69092ea17dc6ad5b93","aria-label":this.accessibilityText},s("slot",{key:"6fe5235653c7ee362af3762ca14540095c33b712"})))}get host(){return e(this)}};c.style=d;export{c as cbp_subnav};
//# sourceMappingURL=p-e87e5802.entry.js.map