UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

308 lines (307 loc) • 9.39 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ import { Fragment, h } from "@stencil/core"; import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot"; import { getSlotted } from "../../utils/dom"; import { componentLoaded, setComponentLoaded, setUpLoadableComponent } from "../../utils/loadable"; import { connectLocalized, disconnectLocalized } from "../../utils/locale"; import { connectMessages, disconnectMessages, setUpMessages, updateMessages } from "../../utils/t9n"; import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources"; import { ICONS, SLOTS } from "./resources"; /** * @slot - A slot for adding a group of `calcite-action`s. * @slot menu-actions - A slot for adding an overflow menu with `calcite-action`s inside a `calcite-dropdown`. * @slot menu-tooltip - A slot for adding a `calcite-tooltip` for the menu. */ export class ActionGroup { constructor() { // -------------------------------------------------------------------------- // // Private Methods // // -------------------------------------------------------------------------- this.setMenuOpen = (event) => { this.menuOpen = !!event.target.open; }; this.expanded = false; this.layout = "vertical"; this.columns = undefined; this.menuOpen = false; this.scale = undefined; this.messages = undefined; this.messageOverrides = undefined; this.effectiveLocale = ""; this.defaultMessages = undefined; } expandedHandler() { this.menuOpen = false; } onMessagesChange() { /* wired up by t9n util */ } effectiveLocaleChange() { updateMessages(this, this.effectiveLocale); } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component's first focusable element. */ async setFocus() { await componentLoaded(this); this.el.focus(); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { connectLocalized(this); connectMessages(this); connectConditionalSlotComponent(this); } disconnectedCallback() { disconnectLocalized(this); disconnectMessages(this); disconnectConditionalSlotComponent(this); } async componentWillLoad() { setUpLoadableComponent(this); await setUpMessages(this); } componentDidLoad() { setComponentLoaded(this); } // -------------------------------------------------------------------------- // // Component Methods // // -------------------------------------------------------------------------- renderTooltip() { const { el } = this; const hasTooltip = getSlotted(el, SLOTS.menuTooltip); return hasTooltip ? h("slot", { name: SLOTS.menuTooltip, slot: ACTION_MENU_SLOTS.tooltip }) : null; } renderMenu() { const { el, expanded, menuOpen, scale, layout, messages } = this; const hasMenuItems = getSlotted(el, SLOTS.menuActions); return hasMenuItems ? (h("calcite-action-menu", { expanded: expanded, flipPlacements: ["left", "right"], label: messages.more, onCalciteActionMenuOpen: this.setMenuOpen, open: menuOpen, placement: layout === "horizontal" ? "bottom-start" : "leading-start", scale: scale }, h("calcite-action", { icon: ICONS.menu, scale: scale, slot: ACTION_MENU_SLOTS.trigger, text: messages.more, textEnabled: expanded }), h("slot", { name: SLOTS.menuActions }), this.renderTooltip())) : null; } render() { return (h(Fragment, null, h("slot", null), this.renderMenu())); } static get is() { return "calcite-action-group"; } static get encapsulation() { return "shadow"; } static get delegatesFocus() { return true; } static get originalStyleUrls() { return { "$": ["action-group.scss"] }; } static get styleUrls() { return { "$": ["action-group.css"] }; } static get assetsDirs() { return ["assets"]; } static get properties() { return { "expanded": { "type": "boolean", "mutable": false, "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": [{ "name": "deprecated", "text": "Use the `layout` property on the component's parent instead." }], "text": "Indicates the layout of the component." }, "attribute": "layout", "reflect": true, "defaultValue": "\"vertical\"" }, "columns": { "type": "number", "mutable": false, "complexType": { "original": "Columns", "resolved": "1 | 2 | 3 | 4 | 5 | 6", "references": { "Columns": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Indicates number of columns." }, "attribute": "columns", "reflect": true }, "menuOpen": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the `calcite-action-menu` is open." }, "attribute": "menu-open", "reflect": true, "defaultValue": "false" }, "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 `calcite-action-menu`." }, "attribute": "scale", "reflect": true }, "messages": { "type": "unknown", "mutable": true, "complexType": { "original": "ActionGroupMessages", "resolved": "{ more: string; }", "references": { "ActionGroupMessages": { "location": "import", "path": "./assets/action-group/t9n" } } }, "required": false, "optional": false, "docs": { "tags": [{ "name": "internal", "text": undefined }], "text": "Made into a prop for testing purposes only" } }, "messageOverrides": { "type": "unknown", "mutable": true, "complexType": { "original": "Partial<ActionGroupMessages>", "resolved": "{ more?: string; }", "references": { "Partial": { "location": "global" }, "ActionGroupMessages": { "location": "import", "path": "./assets/action-group/t9n" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Use this property to override individual strings used by the component." } } }; } static get states() { return { "effectiveLocale": {}, "defaultMessages": {} }; } static get methods() { return { "setFocus": { "complexType": { "signature": "() => Promise<void>", "parameters": [], "references": { "Promise": { "location": "global" } }, "return": "Promise<void>" }, "docs": { "text": "Sets focus on the component's first focusable element.", "tags": [] } } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "expanded", "methodName": "expandedHandler" }, { "propName": "messageOverrides", "methodName": "onMessagesChange" }, { "propName": "effectiveLocale", "methodName": "effectiveLocaleChange" }]; } }