UNPKG

@cbpds/web-components

Version:
180 lines (179 loc) 7.48 kB
/*! * CPB Design System web components - built with Stencil */ import { Host, h } from "@stencil/core"; import { setCSSProps, createNamespaceKey } from "../../utils/utils"; export class CbpExpand { constructor() { this.headingId = createNamespaceKey('cbp-expand'); this.open = false; this.label = undefined; this.headingLevel = 'h4'; this.context = undefined; this.sx = {}; } handleClick() { this.open = !this.open; this.expandClick.emit({ host: this.host, button: this.button, open: this.open, }); 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: 'a5b442b17552e5a4e101880183c8874efc8bf6ed' }, h("cbp-flex", { key: '983320d28cd53cca3e2734ed14daa2a4623c57cb', class: "cbp-expand--control", alignItems: "flex-start", gap: "var(--cbp-space-1x)", onClick: () => this.handleClick() }, h("cbp-flex-item", { key: '5239b88a65bd9a11da906b3a64bac23c206e9907' }, h("cbp-button", { key: 'a436e6b9665287289a1104982703676bf2ff6350', class: "cbp-expand--toggle", fill: "ghost", color: "secondary", width: "var(--cbp-space-6x)", height: "var(--cbp-space-6x)", context: this.context, controls: `${this.headingId}-content`, expanded: `${this.open}`, "aria-labelledby": this.headingId, ref: el => (this.control = el) }, h("cbp-icon", { key: 'cb1b86031c073f020aab679948fdf315e665aa72', name: "caret-down", size: "var(--cbp-space-3x)" }))), h("cbp-flex-item", { key: 'f56a80450522eb275dbbd59c1fee5d5a42946579', id: this.headingId, flexGrow: 1 }, this.host.querySelector('[slot="cbp-expand-label"]') ? h("slot", { name: "cbp-expand-label" }) : h("cbp-typography", { tag: this.headingLevel, variant: "heading-xs", context: this.context, sx: '{"line-height":"var(--cbp-space-6x)"}' }, this.label))), h("div", { key: 'ffca8ea49f62cb6453fafdb4080c86a3cb9b90d2', id: `${this.headingId}-content`, class: "cbp-expand--content" }, h("slot", { key: '03bce5edf0bf10aef26271b07ebbfab1737f454d' })))); } static get is() { return "cbp-expand"; } static get originalStyleUrls() { return { "$": ["cbp-expand.scss"] }; } static get styleUrls() { return { "$": ["cbp-expand.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 component item heading, also used to generate an `id` for \nthe content wrapper. If this property is not specified, a unique string will \nautomatically be generated." }, "attribute": "heading-id", "reflect": false, "defaultValue": "createNamespaceKey('cbp-expand')" }, "open": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies whether the content is expanded and visible." }, "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 component 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": "'h4'" }, "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": "expandClick", "name": "expandClick", "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-expand.js.map