123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /*!
- * 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<void>",
- "parameters": [{
- "tags": [{
- "name": "param",
- "text": "focusId"
- }],
- "text": ""
- }],
- "references": {
- "Promise": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "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"
- }];
- }
- }
|