UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

481 lines (480 loc) • 14.9 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 { h } from "@stencil/core"; import { connectInteractive, disconnectInteractive, updateHostInteraction } from "../../utils/interactive"; import { componentLoaded, setComponentLoaded, setUpLoadableComponent } from "../../utils/loadable"; import { CSS } from "./resources"; /** * @slot - A slot for adding `calcite-dropdown` content. */ export class SplitButton { constructor() { this.calciteSplitButtonPrimaryClickHandler = () => this.calciteSplitButtonPrimaryClick.emit(); this.calciteSplitButtonSecondaryClickHandler = () => this.calciteSplitButtonSecondaryClick.emit(); this.appearance = "solid"; this.kind = "brand"; this.disabled = false; this.active = false; this.dropdownIconType = "chevron"; this.dropdownLabel = undefined; this.loading = false; this.overlayPositioning = "absolute"; this.primaryIconEnd = undefined; this.primaryIconFlipRtl = undefined; this.primaryIconStart = undefined; this.primaryLabel = undefined; this.primaryText = undefined; this.scale = "m"; this.width = "auto"; } handleDisabledChange(value) { if (!value) { this.active = false; } } activeHandler() { if (this.disabled) { this.active = false; } } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component's first focusable element. */ async setFocus() { await componentLoaded(this); this.el.focus(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { connectInteractive(this); } componentWillLoad() { setUpLoadableComponent(this); } componentDidLoad() { setComponentLoaded(this); } componentDidRender() { updateHostInteraction(this); } disconnectedCallback() { disconnectInteractive(this); } render() { const widthClasses = { [CSS.container]: true, [CSS.widthAuto]: this.width === "auto", [CSS.widthHalf]: this.width === "half", [CSS.widthFull]: this.width === "full" }; const buttonWidth = this.width === "auto" ? "auto" : "full"; return (h("div", { class: widthClasses }, h("calcite-button", { appearance: this.appearance, disabled: this.disabled, "icon-end": this.primaryIconEnd ? this.primaryIconEnd : null, "icon-start": this.primaryIconStart ? this.primaryIconStart : null, iconFlipRtl: this.primaryIconFlipRtl ? this.primaryIconFlipRtl : null, kind: this.kind, label: this.primaryLabel, loading: this.loading, onClick: this.calciteSplitButtonPrimaryClickHandler, scale: this.scale, splitChild: "primary", type: "button", width: buttonWidth }, this.primaryText), h("div", { class: CSS.dividerContainer }, h("div", { class: CSS.divider })), h("calcite-dropdown", { disabled: this.disabled, onClick: this.calciteSplitButtonSecondaryClickHandler, open: this.active, overlayPositioning: this.overlayPositioning, placement: "bottom-end", scale: this.scale, width: this.scale }, h("calcite-button", { appearance: this.appearance, disabled: this.disabled, "icon-start": this.dropdownIcon, kind: this.kind, label: this.dropdownLabel, scale: this.scale, slot: "trigger", splitChild: "secondary", type: "button" }), h("slot", null)))); } get dropdownIcon() { return this.dropdownIconType === "chevron" ? "chevronDown" : this.dropdownIconType === "caret" ? "caretDown" : this.dropdownIconType === "ellipsis" ? "ellipsis" : "handle-vertical"; } static get is() { return "calcite-split-button"; } static get encapsulation() { return "shadow"; } static get delegatesFocus() { return true; } static get originalStyleUrls() { return { "$": ["split-button.scss"] }; } static get styleUrls() { return { "$": ["split-button.css"] }; } static get properties() { return { "appearance": { "type": "string", "mutable": false, "complexType": { "original": "Extract<\n \"outline\" | \"outline-fill\" | \"solid\" | \"transparent\",\n Appearance\n >", "resolved": "\"outline\" | \"outline-fill\" | \"solid\" | \"transparent\"", "references": { "Extract": { "location": "global" }, "Appearance": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the appearance style of the component." }, "attribute": "appearance", "reflect": true, "defaultValue": "\"solid\"" }, "kind": { "type": "string", "mutable": false, "complexType": { "original": "Extract<\"brand\" | \"danger\" | \"inverse\" | \"neutral\", Kind>", "resolved": "\"brand\" | \"danger\" | \"inverse\" | \"neutral\"", "references": { "Extract": { "location": "global" }, "Kind": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the kind of the component (will apply to border and background if applicable)." }, "attribute": "kind", "reflect": true, "defaultValue": "\"brand\"" }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, interaction is prevented and the component is displayed with lower opacity." }, "attribute": "disabled", "reflect": true, "defaultValue": "false" }, "active": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "internal", "text": undefined }], "text": "When `true`, the component is active." }, "attribute": "active", "reflect": true, "defaultValue": "false" }, "dropdownIconType": { "type": "string", "mutable": false, "complexType": { "original": "DropdownIconType", "resolved": "\"caret\" | \"chevron\" | \"ellipsis\" | \"overflow\"", "references": { "DropdownIconType": { "location": "import", "path": "../button/interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the icon used for the dropdown menu." }, "attribute": "dropdown-icon-type", "reflect": true, "defaultValue": "\"chevron\"" }, "dropdownLabel": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Accessible name for the dropdown menu." }, "attribute": "dropdown-label", "reflect": true }, "loading": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, a busy indicator is displayed on the primary button." }, "attribute": "loading", "reflect": true, "defaultValue": "false" }, "overlayPositioning": { "type": "string", "mutable": false, "complexType": { "original": "OverlayPositioning", "resolved": "\"absolute\" | \"fixed\"", "references": { "OverlayPositioning": { "location": "import", "path": "../../utils/floating-ui" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Determines the type of positioning to use for the overlaid content.\n\nUsing `\"absolute\"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.\n\n`\"fixed\"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `\"fixed\"`." }, "attribute": "overlay-positioning", "reflect": true, "defaultValue": "\"absolute\"" }, "primaryIconEnd": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies an icon to display at the end of the primary button." }, "attribute": "primary-icon-end", "reflect": true }, "primaryIconFlipRtl": { "type": "string", "mutable": false, "complexType": { "original": "FlipContext", "resolved": "\"both\" | \"end\" | \"start\"", "references": { "FlipContext": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Displays the `primaryIconStart` and/or `primaryIconEnd` as flipped when the element direction is right-to-left (`\"rtl\"`)." }, "attribute": "primary-icon-flip-rtl", "reflect": true }, "primaryIconStart": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies an icon to display at the start of the primary button." }, "attribute": "primary-icon-start", "reflect": true }, "primaryLabel": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Accessible name for the primary button." }, "attribute": "primary-label", "reflect": true }, "primaryText": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Text displayed in the primary button." }, "attribute": "primary-text", "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 component." }, "attribute": "scale", "reflect": true, "defaultValue": "\"m\"" }, "width": { "type": "string", "mutable": false, "complexType": { "original": "Width", "resolved": "\"auto\" | \"full\" | \"half\"", "references": { "Width": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the width of the component." }, "attribute": "width", "reflect": true, "defaultValue": "\"auto\"" } }; } static get events() { return [{ "method": "calciteSplitButtonPrimaryClick", "name": "calciteSplitButtonPrimaryClick", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [], "text": "Fires when the primary button is clicked." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }, { "method": "calciteSplitButtonSecondaryClick", "name": "calciteSplitButtonSecondaryClick", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [], "text": "Fires when the dropdown menu is clicked." }, "complexType": { "original": "void", "resolved": "void", "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's first focusable element.", "tags": [] } } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "disabled", "methodName": "handleDisabledChange" }, { "propName": "active", "methodName": "activeHandler" }]; } }