UNPKG

@cbpds/web-components

Version:
179 lines (178 loc) 7.1 kB
/*! * CPB Design System web components - built with Stencil */ import { Host, h } from "@stencil/core"; import { setCSSProps, createNamespaceKey } from "../../utils/utils"; export class CbpAccordionItem { constructor() { this.headingId = createNamespaceKey('cbp-accordion-item'); this.open = false; this.label = undefined; this.headingLevel = 'h3'; this.color = undefined; this.sx = {}; } handleClick(e) { this.open = !this.open; this.accordionItemClick.emit({ host: this.host, button: this.button, open: this.open, nativeEvent: e }); this.button.focus(); } componentWillLoad() { if (typeof this.sx == 'string') { this.sx = JSON.parse(this.sx) || {}; } setCSSProps(this.host, Object.assign({}, this.sx)); } componentDidLoad() { this.button = this.control.querySelector('button'); } render() { return (h(Host, { key: 'b096acb167e5faa340acdc6be01e233cc05d9cff' }, h("div", { key: '42537e04ef0f2df62cb75d6f1de43276b1162b60', class: "cbp-accordion-item--control", onClick: (e) => this.handleClick(e) }, h("cbp-button", { key: '7d5cc484131af94b00c6100afaaf599a789bd9e1', type: "button", class: "cbp-accordion-item--toggle", fill: "ghost", color: "secondary", controls: `${this.headingId}-content`, expanded: `${this.open}`, "aria-labelledby": this.headingId, ref: el => (this.control = el) }, h("cbp-icon", { key: '178c2e3620626f99ad3f6bb74db6b53f844b596d', name: "chevron-right" })), h("div", { key: 'dcd615b44414e3930e6dddec4c44180d9685cdbc', id: this.headingId, class: "cbp-accordion-item--heading" }, h("slot", { key: 'faabb763a16fc31cc3880e3e73b14e9026b6dcda', name: "cbp-accordion-item-label" }), this.label && h("cbp-typography", { key: 'ce781aaf9b0bedb0f47fc1368dc6d79421c76d1a', tag: this.headingLevel, variant: "heading-sm" }, this.label))), h("div", { key: 'ab51dc59fd2d148354a4eecbb41170ccd59999bf', id: `${this.headingId}-content`, class: "cbp-accordion-item--content" }, h("slot", { key: 'cd6c38d9d15fb8afa099a02d3b5bccc820eefb2b' })))); } static get is() { return "cbp-accordion-item"; } static get originalStyleUrls() { return { "$": ["cbp-accordion-item.scss"] }; } static get styleUrls() { return { "$": ["cbp-accordion-item.css"] }; } static get properties() { return { "headingId": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies an optional `id` for the accordion item heading, also used to generate an `id` for \nthe accordion item content wrapper. If this property is not specified, a unique string will \nautomatically be generated." }, "attribute": "heading-id", "reflect": false, "defaultValue": "createNamespaceKey('cbp-accordion-item')" }, "open": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies whether the accordion is open." }, "attribute": "open", "reflect": true, "defaultValue": "false" }, "label": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The accordion control label." }, "attribute": "label", "reflect": false }, "headingLevel": { "type": "string", "mutable": false, "complexType": { "original": "'h2' | 'h3' | 'h4' | 'h5' | 'h6'", "resolved": "\"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The heading level of the accordion item control. Defaults to h3." }, "attribute": "heading-level", "reflect": false, "defaultValue": "'h3'" }, "color": { "type": "string", "mutable": false, "complexType": { "original": "'danger'", "resolved": "\"danger\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies an optional color variant of the accordion item." }, "attribute": "color", "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": "accordionItemClick", "name": "accordionItemClick", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "A custom event emitted when the accordion item control is activated." }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get elementRef() { return "host"; } } //# sourceMappingURL=cbp-accordion-item.js.map