calcite-split-button.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.97
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client/index.js';
  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 = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:inline-block}:host .split-button__container{display:flex;align-items:stretch}:host .split-button__container>calcite-dropdown>calcite-button{block-size:100%;vertical-align:top}:host:host([color=blue]){--calcite-split-button-background:var(--calcite-ui-brand);--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host:host([color=red]){--calcite-split-button-background:var(--calcite-ui-danger);--calcite-split-button-divider:var(--calcite-ui-foreground-1)}:host:host([color=neutral]){--calcite-split-button-background:var(--calcite-ui-foreground-3);--calcite-split-button-divider:var(--calcite-ui-text-1)}:host: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{inline-size:auto}.width-half{inline-size:50%}.width-full{inline-size:100%}.split-button__divider-container{display:flex;inline-size:1px;align-items:stretch;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;background-color:var(--calcite-split-button-background)}.split-button__divider{margin-block:0.25rem;display:inline-block;inline-size:1px;background-color:var(--calcite-split-button-divider)}:host([appearance=outline]) .split-button__divider-container,:host([appearance=clear]) .split-button__divider-container,:host([appearance=minimal]) .split-button__divider-container{border-block:1px solid var(--calcite-split-button-divider)}:host([appearance=outline]):hover .split-button__divider-container,:host([appearance=clear]):hover .split-button__divider-container,:host([appearance=minimal]):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,:host([appearance=minimal]):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]),:host([appearance=minimal]: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]),:host([appearance=minimal]: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,:host([appearance=minimal]:focus-within) .split-button__divider-container{background-color:var(--calcite-split-button-divider)}: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", 6);
  27. this.calciteSplitButtonSecondaryClick = createEvent(this, "calciteSplitButtonSecondaryClick", 6);
  28. /** Specifies the appearance style of the component. */
  29. this.appearance = "solid";
  30. /** Specifies the color of the component. */
  31. this.color = "blue";
  32. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  33. this.disabled = false;
  34. /**
  35. * When `true`, the component is active.
  36. *
  37. * @internal
  38. */
  39. this.active = false;
  40. /** Specifies the icon used for the dropdown menu. */
  41. this.dropdownIconType = "chevron";
  42. /**
  43. When `true`, a busy indicator is displayed on the primary button.
  44. */
  45. this.loading = false;
  46. /**
  47. * Determines the type of positioning to use for the overlaid content.
  48. *
  49. * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
  50. *
  51. * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
  52. *
  53. */
  54. this.overlayPositioning = "absolute";
  55. /** Specifies the size of the component. */
  56. this.scale = "m";
  57. /** Specifies the width of the component. */
  58. this.width = "auto";
  59. this.calciteSplitButtonPrimaryClickHandler = (event) => this.calciteSplitButtonPrimaryClick.emit(event);
  60. this.calciteSplitButtonSecondaryClickHandler = (event) => this.calciteSplitButtonSecondaryClick.emit(event);
  61. }
  62. handleDisabledChange(value) {
  63. if (!value) {
  64. this.active = false;
  65. }
  66. }
  67. activeHandler() {
  68. if (this.disabled) {
  69. this.active = false;
  70. }
  71. }
  72. //--------------------------------------------------------------------------
  73. //
  74. // Lifecycle
  75. //
  76. //--------------------------------------------------------------------------
  77. componentDidRender() {
  78. updateHostInteraction(this);
  79. }
  80. render() {
  81. const widthClasses = {
  82. [CSS.container]: true,
  83. [CSS.widthAuto]: this.width === "auto",
  84. [CSS.widthHalf]: this.width === "half",
  85. [CSS.widthFull]: this.width === "full"
  86. };
  87. const buttonWidth = this.width === "auto" ? "auto" : "full";
  88. 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-end", 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))));
  89. }
  90. get dropdownIcon() {
  91. return this.dropdownIconType === "chevron"
  92. ? "chevronDown"
  93. : this.dropdownIconType === "caret"
  94. ? "caretDown"
  95. : this.dropdownIconType === "ellipsis"
  96. ? "ellipsis"
  97. : "handle-vertical";
  98. }
  99. get el() { return this; }
  100. static get watchers() { return {
  101. "disabled": ["handleDisabledChange"],
  102. "active": ["activeHandler"]
  103. }; }
  104. static get style() { return splitButtonCss; }
  105. }, [1, "calcite-split-button", {
  106. "appearance": [513],
  107. "color": [513],
  108. "disabled": [516],
  109. "active": [1540],
  110. "dropdownIconType": [513, "dropdown-icon-type"],
  111. "dropdownLabel": [513, "dropdown-label"],
  112. "loading": [516],
  113. "overlayPositioning": [513, "overlay-positioning"],
  114. "primaryIconEnd": [513, "primary-icon-end"],
  115. "primaryIconFlipRtl": [513, "primary-icon-flip-rtl"],
  116. "primaryIconStart": [513, "primary-icon-start"],
  117. "primaryLabel": [513, "primary-label"],
  118. "primaryText": [513, "primary-text"],
  119. "scale": [513],
  120. "width": [513]
  121. }]);
  122. function defineCustomElement$1() {
  123. if (typeof customElements === "undefined") {
  124. return;
  125. }
  126. const components = ["calcite-split-button", "calcite-button", "calcite-dropdown", "calcite-icon", "calcite-loader"];
  127. components.forEach(tagName => { switch (tagName) {
  128. case "calcite-split-button":
  129. if (!customElements.get(tagName)) {
  130. customElements.define(tagName, SplitButton);
  131. }
  132. break;
  133. case "calcite-button":
  134. if (!customElements.get(tagName)) {
  135. defineCustomElement$5();
  136. }
  137. break;
  138. case "calcite-dropdown":
  139. if (!customElements.get(tagName)) {
  140. defineCustomElement$4();
  141. }
  142. break;
  143. case "calcite-icon":
  144. if (!customElements.get(tagName)) {
  145. defineCustomElement$3();
  146. }
  147. break;
  148. case "calcite-loader":
  149. if (!customElements.get(tagName)) {
  150. defineCustomElement$2();
  151. }
  152. break;
  153. } });
  154. }
  155. defineCustomElement$1();
  156. const CalciteSplitButton = SplitButton;
  157. const defineCustomElement = defineCustomElement$1;
  158. export { CalciteSplitButton, defineCustomElement };