UNPKG

@cbpds/web-components

Version:
234 lines (233 loc) 8.95 kB
/*! * CPB Design System web components - built with Stencil */ import { Host, h } from "@stencil/core"; import { setCSSProps, createNamespaceKey } from "../../utils/utils"; export class CbpSubnavItem { constructor() { this.label = undefined; this.href = undefined; this.uid = createNamespaceKey('cbp-subnav-item'); this.name = undefined; this.current = false; this.open = false; this.context = undefined; this.sx = {}; } handleToggleSubnavItem() { this.open = !this.open; this.toggleSubnavItem.emit({ host: this.host, open: this.open, }); } handleSubnavClick() { this.current = true; this.subnavItemClick.emit({ host: this.host, }); } componentWillLoad() { this.icon = this.host.closest('cbp-subnav-item cbp-subnav-item cbp-subnav-item') ? 'caret-down' : 'chevron-right'; this.parent = !!this.host.querySelector('cbp-subnav-item'); if (typeof this.sx == 'string') { this.sx = JSON.parse(this.sx) || {}; } setCSSProps(this.host, Object.assign({}, this.sx)); } render() { return (h(Host, { key: 'c9275df1c61cce9e57f59690d37191c954cb2089' }, h("div", { key: '569a349085420aee7633fe34b9590fb46b949bd4' }, h("cbp-button", { key: '6ab8cf05bf2be0d069813d1c398476553cff06b3', id: this.uid, tag: "a", fill: "outline", color: "primary", href: this.href, "aria-current": this.current ? "page" : "false", context: this.context, onClick: () => this.handleSubnavClick() }, !this.host.querySelector('[slot=cbp-subnav-item-label]') && this.label, h("slot", { key: 'f2e93736c09d0bc53fbd7ccc89a6548b06577982', name: "cbp-subnav-item-label" })), this.parent && h("cbp-button", { key: '0c5ec2dbca318e0a6120e960fe0c5ae83fd85663', fill: "outline", color: "primary", expanded: `${this.open}`, "aria-labelledby": this.uid, context: this.context, onClick: () => this.handleToggleSubnavItem() }, h("cbp-icon", { key: '7b53fd6e5cce29edd27f8819bafea17a3a8a82ec', name: this.icon }))), this.parent && h("section", { key: '9e579ec51a35c6c96864a0fa05762c3a654eb820' }, h("slot", { key: 'f2bcb356f3ef741653ea504265cb181a57a7683e' })))); } static get is() { return "cbp-subnav-item"; } static get originalStyleUrls() { return { "$": ["cbp-subnav-item.scss"] }; } static get styleUrls() { return { "$": ["cbp-subnav-item.css"] }; } static get properties() { return { "label": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the text label for the subnav item." }, "attribute": "label", "reflect": false }, "href": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the href for the Subnav Item anchor." }, "attribute": "href", "reflect": false }, "uid": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Optionally specifies a unique `ID` for the menu, used to wire up the controls and accessibility features." }, "attribute": "uid", "reflect": false, "defaultValue": "createNamespaceKey('cbp-subnav-item')" }, "name": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies a name used to associated Nav Items with Subnav Items." }, "attribute": "name", "reflect": true }, "current": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the current item within the collection of Subnav Items." }, "attribute": "current", "reflect": true, "defaultValue": "false" }, "open": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies whether a Subnav Item with nested children is expanded or collapsed. \nPrimarily used internally for user interactions." }, "attribute": "open", "reflect": true, "defaultValue": "false" }, "context": { "type": "string", "mutable": false, "complexType": { "original": "\"light-inverts\" | \"light-always\" | \"dark-inverts\" | \"dark-always\"", "resolved": "\"dark-always\" | \"dark-inverts\" | \"light-always\" | \"light-inverts\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the context of the component as it applies to the visual design and whether it inverts when light/dark mode is toggled. Default behavior is \"light-inverts\" and does not have to be specified." }, "attribute": "context", "reflect": true }, "sx": { "type": "any", "mutable": false, "complexType": { "original": "any", "resolved": "any", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Supports adding inline styles as an object" }, "attribute": "sx", "reflect": false, "defaultValue": "{}" } }; } static get events() { return [{ "method": "toggleSubnavItem", "name": "toggleSubnavItem", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }, { "method": "subnavItemClick", "name": "subnavItemClick", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get elementRef() { return "host"; } } //# sourceMappingURL=cbp-subnav-item.js.map