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-436f46fe.js";import{s as n}from"./p-93ade441.js";import{s as a}from"./p-43bc425a.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);a.currentPage=t.name;a.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,e;if(this.store){if(((t=this.currentItem)===null||t===void 0?void 0:t.name)!=a.currentPage){this.updateCurrent(a.currentPage)}if(((e=this.activeItem)===null||e===void 0?void 0:e.name)!=a.activeItemName){this.updateActiveItem(a.activeItemName)}}return s(i,{key:"d8ca51f29c562f48785b0fddcc6cf8be74959e8c"},s("nav",{key:"3e8ddc4953099861c9f1986d81310658cb179556","aria-label":this.accessibilityText},s("slot",{key:"13b66d3390cba32db0139c462e1c4007b6c9f283"})))}get host(){return e(this)}};o.style=c;export{o as cbp_subnav}; //# sourceMappingURL=p-dddb43d5.entry.js.map