UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

286 lines (285 loc) • 8.4 kB
import { Component, Element, Event, Host, Prop, Watch, h, Method } from "@stencil/core"; import { CalciteExpandToggle, toggleChildActionText } from "../functional/CalciteExpandToggle"; import { CSS, SLOTS, TEXT } from "./resources"; import { getSlotted, focusElement } from "../../utils/dom"; /** * @slot bottom-actions - A slot for adding `calcite-action`s that will appear at the bottom of the action bar, above the collapse/expand button. * @slot - A slot for adding `calcite-action`s that will appear at the top of the action bar. */ export class CalciteActionBar { constructor() { // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * When set to true, the expand-toggling behavior will be disabled. */ this.expandDisabled = false; /** * Indicates whether widget is expanded. */ this.expanded = false; this.observer = new MutationObserver(() => { const { el, expanded } = this; toggleChildActionText({ parent: el, expanded }); }); // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.toggleExpand = () => { this.expanded = !this.expanded; }; this.setExpandToggleRef = (el) => { this.expandToggleEl = el; }; } expandHandler(expandDisabled) { if (!expandDisabled) { toggleChildActionText({ parent: this.el, expanded: this.expanded }); } } expandedHandler(expanded) { if (!this.expandDisabled) { toggleChildActionText({ parent: this.el, expanded }); } this.calciteActionBarToggle.emit(); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- componentWillLoad() { const { el, expandDisabled, expanded } = this; if (!expandDisabled) { toggleChildActionText({ parent: el, expanded }); } this.observer.observe(el, { childList: true }); } disconnectedCallback() { this.observer.disconnect(); } // -------------------------------------------------------------------------- // // Methods // // -------------------------------------------------------------------------- async setFocus(focusId) { if (focusId === "expand-toggle") { await focusElement(this.expandToggleEl); return; } this.el.focus(); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- renderBottomActionGroup() { const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, tooltipExpand } = this; const expandLabel = intlExpand || TEXT.expand; const collapseLabel = intlCollapse || TEXT.collapse; const expandToggleNode = !expandDisabled ? (h(CalciteExpandToggle, { el: el, expanded: expanded, intlCollapse: collapseLabel, intlExpand: expandLabel, position: position, ref: this.setExpandToggleRef, toggle: toggleExpand, tooltip: tooltipExpand })) : null; return getSlotted(el, SLOTS.bottomActions) || expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom }, h("slot", { name: SLOTS.bottomActions }), expandToggleNode)) : null; } render() { return (h(Host, null, h("slot", null), this.renderBottomActionGroup())); } static get is() { return "calcite-action-bar"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["calcite-action-bar.scss"] }; } static get styleUrls() { return { "$": ["calcite-action-bar.css"] }; } static get properties() { return { "expandDisabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When set to true, the expand-toggling behavior will be disabled." }, "attribute": "expand-disabled", "reflect": true, "defaultValue": "false" }, "expanded": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Indicates whether widget is expanded." }, "attribute": "expanded", "reflect": true, "defaultValue": "false" }, "tooltipExpand": { "type": "unknown", "mutable": false, "complexType": { "original": "HTMLCalciteTooltipElement", "resolved": "HTMLCalciteTooltipElement", "references": { "HTMLCalciteTooltipElement": { "location": "global" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Used to set the tooltip for the expand toggle." } }, "intlExpand": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Updates the label of the expand icon when the component is not expanded." }, "attribute": "intl-expand", "reflect": false }, "intlCollapse": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Updates the label of the collapse icon when the component is expanded." }, "attribute": "intl-collapse", "reflect": false }, "position": { "type": "string", "mutable": false, "complexType": { "original": "Position", "resolved": "\"end\" | \"start\"", "references": { "Position": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Arranges the component depending on the elements 'dir' property." }, "attribute": "position", "reflect": true }, "theme": { "type": "string", "mutable": false, "complexType": { "original": "Theme", "resolved": "\"dark\" | \"light\"", "references": { "Theme": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Used to set the component's color scheme." }, "attribute": "theme", "reflect": true } }; } static get events() { return [{ "method": "calciteActionBarToggle", "name": "calciteActionBarToggle", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Emitted when expanded has been toggled." }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get methods() { return { "setFocus": { "complexType": { "signature": "(focusId?: \"expand-toggle\") => Promise<void>", "parameters": [{ "tags": [], "text": "" }], "references": { "Promise": { "location": "global" } }, "return": "Promise<void>" }, "docs": { "text": "", "tags": [] } } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "expandDisabled", "methodName": "expandHandler" }, { "propName": "expanded", "methodName": "expandedHandler" }]; } }