calcite-split-button.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
  7. import { u as updateHostInteraction } from './interactive.js';
  8. import { d as defineCustomElement$5 } from './button.js';
  9. import { d as defineCustomElement$4 } from './dropdown.js';
  10. import { d as defineCustomElement$3 } from './icon.js';
  11. import { d as defineCustomElement$2 } from './loader.js';
  12. const CSS = {
  13. container: "split-button__container",
  14. dividerContainer: "split-button__divider-container",
  15. divider: "split-button__divider",
  16. widthAuto: "width-auto",
  17. widthHalf: "width-half",
  18. widthFull: "width-full"
  19. };
  20. const splitButtonCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:inline-block}:host .split-button__container{display:-ms-flexbox;display:flex;-ms-flex-align:stretch;align-items:stretch}:host .split-button__container>calcite-dropdown>calcite-button{height:100%;vertical-align:top}:host([appearance=solid]):host([color=blue]){--calcite-split-button-background:var(--calcite-ui-brand);--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host([appearance=solid]):host([color=red]){--calcite-split-button-background:var(--calcite-ui-danger);--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host([appearance=solid]):host([color=neutral]){--calcite-split-button-background:var(--calcite-ui-foreground-3);--calcite-split-button-divider:var(--calcite-ui-text-1)}:host([appearance=solid]):host([color=inverse]){--calcite-split-button-background:var(--calcite-ui-inverse);--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host([appearance=transparent]):host([color=blue]){--calcite-split-button-divider:var(--calcite-ui-brand)}:host([appearance=transparent]):host([color=red]){--calcite-split-button-divider:var(--calcite-ui-danger)}:host([appearance=transparent]):host([color=neutral]){--calcite-split-button-divider:var(--calcite-ui-text-1)}:host([appearance=transparent]):host([color=inverse]){--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host([appearance=clear]),:host([appearance=transparent]){--calcite-split-button-background:transparent}:host([appearance=outline]){--calcite-split-button-background:var(--calcite-ui-foreground-1)}:host([appearance=clear]):host([color=blue]),:host([appearance=outline]):host([color=blue]){--calcite-split-button-divider:var(--calcite-ui-brand)}:host([appearance=clear]):host([color=red]),:host([appearance=outline]):host([color=red]){--calcite-split-button-divider:var(--calcite-ui-danger)}:host([appearance=clear]):host([color=neutral]),:host([appearance=outline]):host([color=neutral]){--calcite-split-button-divider:var(--calcite-ui-foreground-3)}:host([appearance=clear]):host([color=inverse]),:host([appearance=outline]):host([color=inverse]){--calcite-split-button-divider:var(--calcite-ui-inverse)}.width-auto{width:auto}.width-half{width:50%}.width-full{width:100%}.split-button__divider-container{display:-ms-flexbox;display:flex;width:1px;-ms-flex-align:stretch;align-items:stretch;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s;background-color:var(--calcite-split-button-background)}.split-button__divider{margin-top:0.25rem;margin-bottom:0.25rem;display:inline-block;width:1px;background-color:var(--calcite-split-button-divider)}:host([appearance=outline]) .split-button__divider-container,:host([appearance=clear]) .split-button__divider-container{border-top:1px solid var(--calcite-split-button-divider);border-bottom:1px solid var(--calcite-split-button-divider)}:host([appearance=outline]):hover .split-button__divider-container,:host([appearance=clear]):hover .split-button__divider-container{background-color:var(--calcite-split-button-divider)}:host([appearance=outline]:hover) .split-button__divider-container,:host([appearance=clear]:hover) .split-button__divider-container{background-color:var(--calcite-split-button-divider)}:host([appearance=outline]:focus-within):host([color=blue]),:host([appearance=clear]:focus-within):host([color=blue]){--calcite-split-button-divider:var(--calcite-ui-brand-press)}:host([appearance=outline]:focus-within):host([color=red]),:host([appearance=clear]:focus-within):host([color=red]){--calcite-split-button-divider:var(--calcite-ui-danger-press)}:host([appearance=outline]:focus-within) .split-button__divider-container,:host([appearance=clear]:focus-within) .split-button__divider-container{background-color:var(--calcite-split-button-divider)}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) .split-button__divider-container{opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) calcite-dropdown>calcite-button{pointer-events:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  21. const SplitButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  22. constructor() {
  23. super();
  24. this.__registerHost();
  25. this.__attachShadow();
  26. this.calciteSplitButtonPrimaryClick = createEvent(this, "calciteSplitButtonPrimaryClick", 7);
  27. this.calciteSplitButtonSecondaryClick = createEvent(this, "calciteSplitButtonSecondaryClick", 7);
  28. /** specify the appearance style of the button, defaults to solid. */
  29. this.appearance = "solid";
  30. /** specify the color of the control, defaults to blue */
  31. this.color = "blue";
  32. /** is the control disabled */
  33. this.disabled = false;
  34. /**
  35. * Is the dropdown currently active or not
  36. * @internal
  37. */
  38. this.active = false;
  39. /** specify the icon used for the dropdown menu, defaults to chevron */
  40. this.dropdownIconType = "chevron";
  41. /** optionally add a calcite-loader component to the control,
  42. disabling interaction. with the primary button */
  43. this.loading = false;
  44. /** Describes the type of positioning to use for the dropdown. If your element is in a fixed container, use the 'fixed' value. */
  45. this.overlayPositioning = "absolute";
  46. /** specify the scale of the control, defaults to m */
  47. this.scale = "m";
  48. /** specify the width of the button, defaults to auto */
  49. this.width = "auto";
  50. this.calciteSplitButtonPrimaryClickHandler = (e) => this.calciteSplitButtonPrimaryClick.emit(e);
  51. this.calciteSplitButtonSecondaryClickHandler = (e) => this.calciteSplitButtonSecondaryClick.emit(e);
  52. }
  53. handleDisabledChange(value) {
  54. if (!value) {
  55. this.active = false;
  56. }
  57. }
  58. activeHandler() {
  59. if (this.disabled) {
  60. this.active = false;
  61. }
  62. }
  63. //--------------------------------------------------------------------------
  64. //
  65. // Lifecycle
  66. //
  67. //--------------------------------------------------------------------------
  68. componentDidRender() {
  69. updateHostInteraction(this);
  70. }
  71. render() {
  72. const widthClasses = {
  73. [CSS.container]: true,
  74. [CSS.widthAuto]: this.width === "auto",
  75. [CSS.widthHalf]: this.width === "half",
  76. [CSS.widthFull]: this.width === "full"
  77. };
  78. const buttonWidth = this.width === "auto" ? "auto" : "full";
  79. return (h("div", { class: widthClasses }, h("calcite-button", { appearance: this.appearance, color: this.color, disabled: this.disabled, "icon-end": this.primaryIconEnd ? this.primaryIconEnd : null, "icon-start": this.primaryIconStart ? this.primaryIconStart : null, iconFlipRtl: this.primaryIconFlipRtl ? this.primaryIconFlipRtl : null, 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", { active: this.active, disabled: this.disabled, onClick: this.calciteSplitButtonSecondaryClickHandler, overlayPositioning: this.overlayPositioning, placement: "bottom-trailing", scale: this.scale, width: this.scale }, h("calcite-button", { appearance: this.appearance, color: this.color, disabled: this.disabled, "icon-start": this.dropdownIcon, label: this.dropdownLabel, scale: this.scale, slot: "dropdown-trigger", splitChild: "secondary", type: "button" }), h("slot", null))));
  80. }
  81. get dropdownIcon() {
  82. return this.dropdownIconType === "chevron"
  83. ? "chevronDown"
  84. : this.dropdownIconType === "caret"
  85. ? "caretDown"
  86. : this.dropdownIconType === "ellipsis"
  87. ? "ellipsis"
  88. : "handle-vertical";
  89. }
  90. get el() { return this; }
  91. static get watchers() { return {
  92. "disabled": ["handleDisabledChange"],
  93. "active": ["activeHandler"]
  94. }; }
  95. static get style() { return splitButtonCss; }
  96. }, [1, "calcite-split-button", {
  97. "appearance": [513],
  98. "color": [513],
  99. "disabled": [516],
  100. "active": [1540],
  101. "dropdownIconType": [513, "dropdown-icon-type"],
  102. "dropdownLabel": [513, "dropdown-label"],
  103. "loading": [516],
  104. "overlayPositioning": [1, "overlay-positioning"],
  105. "primaryIconEnd": [513, "primary-icon-end"],
  106. "primaryIconFlipRtl": [513, "primary-icon-flip-rtl"],
  107. "primaryIconStart": [513, "primary-icon-start"],
  108. "primaryLabel": [513, "primary-label"],
  109. "primaryText": [513, "primary-text"],
  110. "scale": [513],
  111. "width": [513]
  112. }]);
  113. function defineCustomElement$1() {
  114. if (typeof customElements === "undefined") {
  115. return;
  116. }
  117. const components = ["calcite-split-button", "calcite-button", "calcite-dropdown", "calcite-icon", "calcite-loader"];
  118. components.forEach(tagName => { switch (tagName) {
  119. case "calcite-split-button":
  120. if (!customElements.get(tagName)) {
  121. customElements.define(tagName, SplitButton);
  122. }
  123. break;
  124. case "calcite-button":
  125. if (!customElements.get(tagName)) {
  126. defineCustomElement$5();
  127. }
  128. break;
  129. case "calcite-dropdown":
  130. if (!customElements.get(tagName)) {
  131. defineCustomElement$4();
  132. }
  133. break;
  134. case "calcite-icon":
  135. if (!customElements.get(tagName)) {
  136. defineCustomElement$3();
  137. }
  138. break;
  139. case "calcite-loader":
  140. if (!customElements.get(tagName)) {
  141. defineCustomElement$2();
  142. }
  143. break;
  144. } });
  145. }
  146. defineCustomElement$1();
  147. const CalciteSplitButton = SplitButton;
  148. const defineCustomElement = defineCustomElement$1;
  149. export { CalciteSplitButton, defineCustomElement };