UNPKG

@cbpds/web-components

Version:
5 lines 2.11 kB
/*! * CPB Design System web components - built with Stencil */ import{r as t,h as s,a as i,g as e}from"./p-654179c2.js";import{s as a}from"./p-93ade441.js";import{s as n}from"./p-83658c86.js";const h="cbp-subnav{display:block}";const c=h;const o=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:"11ec6b59257413cae1709687de7f24fb6ca0522c"},s("nav",{key:"f9d1c7ba630d8938a70b6f594f8c47f4d195525d","aria-label":this.accessibilityText},s("slot",{key:"2627f9f6a71a317ed18c11f73c93139d9d9b6ee1"})))}get host(){return e(this)}};o.style=c;export{o as cbp_subnav}; //# sourceMappingURL=p-dc1dfb05.entry.js.map