action-group.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, h, Fragment } from '@stencil/core/internal/client/index.js';
  7. import { b as getSlotted } from './dom.js';
  8. import { S as SLOTS$1, d as defineCustomElement$4 } from './action-menu.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  10. import { d as defineCustomElement$5 } from './action.js';
  11. import { d as defineCustomElement$3 } from './icon.js';
  12. import { d as defineCustomElement$2 } from './loader.js';
  13. import { d as defineCustomElement$1 } from './popover.js';
  14. const SLOTS = {
  15. menuActions: "menu-actions",
  16. menuTooltip: "menu-tooltip"
  17. };
  18. const TEXT = {
  19. more: "More"
  20. };
  21. const ICONS = {
  22. menu: "ellipsis"
  23. };
  24. const actionGroupCss = "@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}}:host{box-sizing:border-box;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-2);font-size:var(--calcite-font-size--1)}:host *{box-sizing:border-box}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:flex;flex-direction:column;padding:0px;--calcite-action-group-columns:3}:host([columns=\"1\"]){--calcite-action-group-columns:1}:host([columns=\"2\"]){--calcite-action-group-columns:2}:host([columns=\"3\"]){--calcite-action-group-columns:3}:host([columns=\"4\"]){--calcite-action-group-columns:4}:host([columns=\"5\"]){--calcite-action-group-columns:5}:host([columns=\"6\"]){--calcite-action-group-columns:6}:host(:first-child){padding-block-start:0px}:host([layout=horizontal]){flex-direction:row}:host([layout=grid]){display:grid;place-content:stretch;gap:1px;background-color:var(--calcite-ui-background);padding:1px;grid-template-columns:repeat(var(--calcite-action-group-columns), auto)}";
  25. const ActionGroup = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  26. constructor() {
  27. super();
  28. this.__registerHost();
  29. this.__attachShadow();
  30. // --------------------------------------------------------------------------
  31. //
  32. // Properties
  33. //
  34. // --------------------------------------------------------------------------
  35. /**
  36. * When `true`, the component is expanded.
  37. */
  38. this.expanded = false;
  39. /**
  40. * Indicates the layout of the component.
  41. */
  42. this.layout = "vertical";
  43. /**
  44. * When `true`, the `calcite-action-menu` is open.
  45. */
  46. this.menuOpen = false;
  47. // --------------------------------------------------------------------------
  48. //
  49. // Private Methods
  50. //
  51. // --------------------------------------------------------------------------
  52. this.setMenuOpen = (event) => {
  53. this.menuOpen = !!event.detail;
  54. };
  55. }
  56. expandedHandler() {
  57. this.menuOpen = false;
  58. }
  59. // --------------------------------------------------------------------------
  60. //
  61. // Lifecycle
  62. //
  63. // --------------------------------------------------------------------------
  64. connectedCallback() {
  65. connectConditionalSlotComponent(this);
  66. }
  67. disconnectedCallback() {
  68. disconnectConditionalSlotComponent(this);
  69. }
  70. // --------------------------------------------------------------------------
  71. //
  72. // Component Methods
  73. //
  74. // --------------------------------------------------------------------------
  75. renderTooltip() {
  76. const { el } = this;
  77. const hasTooltip = getSlotted(el, SLOTS.menuTooltip);
  78. return hasTooltip ? h("slot", { name: SLOTS.menuTooltip, slot: SLOTS$1.tooltip }) : null;
  79. }
  80. renderMenu() {
  81. const { el, expanded, intlMore, menuOpen, scale, layout } = this;
  82. const hasMenuItems = getSlotted(el, SLOTS.menuActions);
  83. return hasMenuItems ? (h("calcite-action-menu", { expanded: expanded, flipPlacements: ["left", "right"], label: intlMore || TEXT.more, onCalciteActionMenuOpenChange: this.setMenuOpen, open: menuOpen, placement: layout === "horizontal" ? "bottom-leading" : "leading-start", scale: scale }, h("calcite-action", { icon: ICONS.menu, scale: scale, slot: SLOTS$1.trigger, text: intlMore || TEXT.more, textEnabled: expanded }), h("slot", { name: SLOTS.menuActions }), this.renderTooltip())) : null;
  84. }
  85. render() {
  86. return (h(Fragment, null, h("slot", null), this.renderMenu()));
  87. }
  88. get el() { return this; }
  89. static get watchers() { return {
  90. "expanded": ["expandedHandler"]
  91. }; }
  92. static get style() { return actionGroupCss; }
  93. }, [1, "calcite-action-group", {
  94. "expanded": [516],
  95. "layout": [513],
  96. "columns": [514],
  97. "intlMore": [1, "intl-more"],
  98. "menuOpen": [1540, "menu-open"],
  99. "scale": [513]
  100. }]);
  101. function defineCustomElement() {
  102. if (typeof customElements === "undefined") {
  103. return;
  104. }
  105. const components = ["calcite-action-group", "calcite-action", "calcite-action-menu", "calcite-icon", "calcite-loader", "calcite-popover"];
  106. components.forEach(tagName => { switch (tagName) {
  107. case "calcite-action-group":
  108. if (!customElements.get(tagName)) {
  109. customElements.define(tagName, ActionGroup);
  110. }
  111. break;
  112. case "calcite-action":
  113. if (!customElements.get(tagName)) {
  114. defineCustomElement$5();
  115. }
  116. break;
  117. case "calcite-action-menu":
  118. if (!customElements.get(tagName)) {
  119. defineCustomElement$4();
  120. }
  121. break;
  122. case "calcite-icon":
  123. if (!customElements.get(tagName)) {
  124. defineCustomElement$3();
  125. }
  126. break;
  127. case "calcite-loader":
  128. if (!customElements.get(tagName)) {
  129. defineCustomElement$2();
  130. }
  131. break;
  132. case "calcite-popover":
  133. if (!customElements.get(tagName)) {
  134. defineCustomElement$1();
  135. }
  136. break;
  137. } });
  138. }
  139. defineCustomElement();
  140. export { ActionGroup as A, SLOTS as S, defineCustomElement as d };