123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /*!
- * 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.82
- */
- import { Component, Element, Event, Host, Method, Prop, h, forceUpdate } from "@stencil/core";
- import { CSS, TEXT } from "./resources";
- import { createObserver } from "../../utils/observers";
- import { updateHostInteraction } from "../../utils/interactive";
- import { toAriaBoolean } from "../../utils/dom";
- /**
- * @slot - A slot for adding a `calcite-icon`.
- */
- export class Action {
- constructor() {
- // --------------------------------------------------------------------------
- //
- // Properties
- //
- // --------------------------------------------------------------------------
- /**
- * Indicates whether the action is highlighted.
- */
- this.active = false;
- /** Specify the appearance style of the action, defaults to solid. */
- this.appearance = "solid";
- /**
- * Compact mode is used internally by components to reduce side padding, e.g. calcite-block-section.
- */
- this.compact = false;
- /**
- * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
- */
- this.disabled = false;
- /**
- * Indicates unread changes.
- */
- this.indicator = false;
- /** string to override English loading text
- * @default "Loading"
- */
- this.intlLoading = TEXT.loading;
- /**
- * When true, content is waiting to be loaded. This state shows a busy indicator.
- */
- this.loading = false;
- /**
- * Specifies the size of the action.
- */
- this.scale = "m";
- /**
- * Indicates whether the text is displayed.
- */
- this.textEnabled = false;
- this.mutationObserver = createObserver("mutation", () => forceUpdate(this));
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- this.calciteActionClickHandler = () => {
- if (!this.disabled) {
- this.calciteActionClick.emit();
- }
- };
- }
- // --------------------------------------------------------------------------
- //
- // Lifecycle
- //
- // --------------------------------------------------------------------------
- connectedCallback() {
- var _a;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
- }
- disconnectedCallback() {
- var _a;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- }
- componentDidRender() {
- updateHostInteraction(this);
- }
- // --------------------------------------------------------------------------
- //
- // Methods
- //
- // --------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- this.buttonEl.focus();
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- renderTextContainer() {
- const { text, textEnabled } = this;
- const textContainerClasses = {
- [CSS.textContainer]: true,
- [CSS.textContainerVisible]: textEnabled
- };
- return text ? (h("div", { class: textContainerClasses, key: "text-container" }, text)) : null;
- }
- renderIconContainer() {
- var _a;
- const { loading, icon, scale, el, intlLoading } = this;
- const iconScale = scale === "l" ? "m" : "s";
- const loaderScale = scale === "l" ? "l" : "m";
- const calciteLoaderNode = loading ? (h("calcite-loader", { active: true, inline: true, label: intlLoading, scale: loaderScale })) : null;
- const calciteIconNode = icon ? h("calcite-icon", { icon: icon, scale: iconScale }) : null;
- const iconNode = calciteLoaderNode || calciteIconNode;
- const hasIconToDisplay = iconNode || ((_a = el.children) === null || _a === void 0 ? void 0 : _a.length);
- const slotContainerNode = (h("div", { class: {
- [CSS.slotContainer]: true,
- [CSS.slotContainerHidden]: loading
- } },
- h("slot", null)));
- return hasIconToDisplay ? (h("div", { "aria-hidden": "true", class: CSS.iconContainer, key: "icon-container" },
- iconNode,
- slotContainerNode)) : null;
- }
- render() {
- const { compact, disabled, loading, textEnabled, label, text } = this;
- const ariaLabel = label || text;
- const buttonClasses = {
- [CSS.button]: true,
- [CSS.buttonTextVisible]: textEnabled,
- [CSS.buttonCompact]: compact
- };
- return (h(Host, { onClick: this.calciteActionClickHandler },
- h("button", { "aria-busy": toAriaBoolean(loading), "aria-disabled": toAriaBoolean(disabled), "aria-label": ariaLabel, class: buttonClasses, disabled: disabled, ref: (buttonEl) => (this.buttonEl = buttonEl) },
- this.renderIconContainer(),
- this.renderTextContainer())));
- }
- static get is() { return "calcite-action"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() { return {
- "$": ["action.scss"]
- }; }
- static get styleUrls() { return {
- "$": ["action.css"]
- }; }
- static get properties() { return {
- "active": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Indicates whether the action is highlighted."
- },
- "attribute": "active",
- "reflect": true,
- "defaultValue": "false"
- },
- "alignment": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Alignment",
- "resolved": "\"center\" | \"end\" | \"start\"",
- "references": {
- "Alignment": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "Optionally specify the horizontal alignment of button elements with text content."
- },
- "attribute": "alignment",
- "reflect": true
- },
- "appearance": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Extract<\"solid\" | \"clear\", Appearance>",
- "resolved": "\"clear\" | \"solid\"",
- "references": {
- "Extract": {
- "location": "global"
- },
- "Appearance": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Specify the appearance style of the action, defaults to solid."
- },
- "attribute": "appearance",
- "reflect": true,
- "defaultValue": "\"solid\""
- },
- "compact": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Compact mode is used internally by components to reduce side padding, e.g. calcite-block-section."
- },
- "attribute": "compact",
- "reflect": true,
- "defaultValue": "false"
- },
- "disabled": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When true, disabled prevents interaction. This state shows items with lower opacity/grayed."
- },
- "attribute": "disabled",
- "reflect": true,
- "defaultValue": "false"
- },
- "icon": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "The name of the icon to display. The value of this property must match the icon name from https://esri.github.io/calcite-ui-icons/."
- },
- "attribute": "icon",
- "reflect": false
- },
- "indicator": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Indicates unread changes."
- },
- "attribute": "indicator",
- "reflect": true,
- "defaultValue": "false"
- },
- "intlLoading": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [{
- "name": "default",
- "text": "\"Loading\""
- }],
- "text": "string to override English loading text"
- },
- "attribute": "intl-loading",
- "reflect": false,
- "defaultValue": "TEXT.loading"
- },
- "label": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "The label of the action. If no label is provided, the label inherits what's provided for the `text` prop."
- },
- "attribute": "label",
- "reflect": false
- },
- "loading": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When true, content is waiting to be loaded. This state shows a busy indicator."
- },
- "attribute": "loading",
- "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 action."
- },
- "attribute": "scale",
- "reflect": true,
- "defaultValue": "\"m\""
- },
- "text": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": true,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Text that accompanies the action icon."
- },
- "attribute": "text",
- "reflect": false
- },
- "textEnabled": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Indicates whether the text is displayed."
- },
- "attribute": "text-enabled",
- "reflect": true,
- "defaultValue": "false"
- }
- }; }
- static get events() { return [{
- "method": "calciteActionClick",
- "name": "calciteActionClick",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "use onClick instead."
- }],
- "text": "Emitted when the action has been clicked."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }]; }
- static get methods() { return {
- "setFocus": {
- "complexType": {
- "signature": "() => Promise<void>",
- "parameters": [],
- "references": {
- "Promise": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "docs": {
- "text": "Sets focus on the component.",
- "tags": []
- }
- }
- }; }
- static get elementRef() { return "el"; }
- }
|