/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.97 */ import { Host, h } from "@stencil/core"; import { ExpandToggle, toggleChildActionText } from "../functional/ExpandToggle"; import { focusElement, getSlotted } from "../../utils/dom"; import { CSS, TEXT, SLOTS } from "./resources"; import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot"; /** * @slot - A slot for adding `calcite-action`s to the component. * @slot expand-tooltip - Used to set the `calcite-tooltip` for the expand toggle. */ export class ActionPad { constructor() { // -------------------------------------------------------------------------- // // Properties // // -------------------------------------------------------------------------- /** * When `true`, the expand-toggling behavior is disabled. */ this.expandDisabled = false; /** * When `true`, the component is expanded. */ this.expanded = false; /** * Indicates the layout of the component. */ this.layout = "vertical"; // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.actionMenuOpenChangeHandler = (event) => { if (event.detail) { const composedPath = event.composedPath(); Array.from(this.el.querySelectorAll("calcite-action-group")).forEach((group) => { if (!composedPath.includes(group)) { group.menuOpen = false; } }); } }; this.toggleExpand = () => { this.expanded = !this.expanded; this.calciteActionPadToggle.emit(); }; this.setExpandToggleRef = (el) => { this.expandToggleEl = el; }; } expandedHandler(expanded) { toggleChildActionText({ parent: this.el, expanded }); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { connectConditionalSlotComponent(this); } disconnectedCallback() { disconnectConditionalSlotComponent(this); } componentWillLoad() { const { el, expanded } = this; toggleChildActionText({ parent: el, expanded }); } // -------------------------------------------------------------------------- // // Methods // // -------------------------------------------------------------------------- /** * Sets focus on the component. * * @param focusId */ async setFocus(focusId) { var _a; if (focusId === "expand-toggle") { await focusElement(this.expandToggleEl); return; } (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus(); } // -------------------------------------------------------------------------- // // Component Methods // // -------------------------------------------------------------------------- renderBottomActionGroup() { const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale, layout } = this; const tooltip = getSlotted(el, SLOTS.expandTooltip); const expandLabel = intlExpand || TEXT.expand; const collapseLabel = intlCollapse || TEXT.collapse; const expandToggleNode = !expandDisabled ? (h(ExpandToggle, { el: el, expanded: expanded, intlCollapse: collapseLabel, intlExpand: expandLabel, position: position, ref: this.setExpandToggleRef, scale: scale, toggle: toggleExpand, tooltip: tooltip })) : null; return expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom, layout: layout, scale: scale }, h("slot", { name: SLOTS.expandTooltip }), expandToggleNode)) : null; } render() { return (h(Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler }, h("div", { class: CSS.container }, h("slot", null), this.renderBottomActionGroup()))); } static get is() { return "calcite-action-pad"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["action-pad.scss"] }; } static get styleUrls() { return { "$": ["action-pad.css"] }; } static get properties() { return { "expandDisabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the expand-toggling behavior is disabled." }, "attribute": "expand-disabled", "reflect": true, "defaultValue": "false" }, "expanded": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the component is expanded." }, "attribute": "expanded", "reflect": true, "defaultValue": "false" }, "layout": { "type": "string", "mutable": false, "complexType": { "original": "Layout", "resolved": "\"grid\" | \"horizontal\" | \"vertical\"", "references": { "Layout": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Indicates the layout of the component." }, "attribute": "layout", "reflect": true, "defaultValue": "\"vertical\"" }, "intlExpand": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Specifies the label of the expand icon when the component is collapsed." }, "attribute": "intl-expand", "reflect": false }, "intlCollapse": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Specifies 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 element's `dir` property." }, "attribute": "position", "reflect": true }, "scale": { "type": "string", "mutable": false, "complexType": { "original": "Scale", "resolved": "\"l\" | \"m\" | \"s\"", "references": { "Scale": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the size of the expand `calcite-action`." }, "attribute": "scale", "reflect": true } }; } static get events() { return [{ "method": "calciteActionPadToggle", "name": "calciteActionPadToggle", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [], "text": "Emits when the `expanded` property is toggled." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }]; } static get methods() { return { "setFocus": { "complexType": { "signature": "(focusId?: \"expand-toggle\") => Promise", "parameters": [{ "tags": [{ "name": "param", "text": "focusId" }], "text": "" }], "references": { "Promise": { "location": "global" } }, "return": "Promise" }, "docs": { "text": "Sets focus on the component.", "tags": [{ "name": "param", "text": "focusId" }] } } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "expanded", "methodName": "expandedHandler" }]; } }