action-group.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 { h } from "@stencil/core";
  7. import { ICONS, SLOTS, TEXT } from "./resources";
  8. import { Fragment } from "@stencil/core/internal";
  9. import { getSlotted } from "../../utils/dom";
  10. import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources";
  11. import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
  12. /**
  13. * @slot - A slot for adding a group of `calcite-action`s.
  14. * @slot menu-actions - A slot for adding an overflow menu with `calcite-action`s inside a `calcite-dropdown`.
  15. * @slot menu-tooltip - A slot for adding a `calcite-tooltip` for the menu.
  16. */
  17. export class ActionGroup {
  18. constructor() {
  19. // --------------------------------------------------------------------------
  20. //
  21. // Properties
  22. //
  23. // --------------------------------------------------------------------------
  24. /**
  25. * When `true`, the component is expanded.
  26. */
  27. this.expanded = false;
  28. /**
  29. * Indicates the layout of the component.
  30. */
  31. this.layout = "vertical";
  32. /**
  33. * When `true`, the `calcite-action-menu` is open.
  34. */
  35. this.menuOpen = false;
  36. // --------------------------------------------------------------------------
  37. //
  38. // Private Methods
  39. //
  40. // --------------------------------------------------------------------------
  41. this.setMenuOpen = (event) => {
  42. this.menuOpen = !!event.detail;
  43. };
  44. }
  45. expandedHandler() {
  46. this.menuOpen = false;
  47. }
  48. // --------------------------------------------------------------------------
  49. //
  50. // Lifecycle
  51. //
  52. // --------------------------------------------------------------------------
  53. connectedCallback() {
  54. connectConditionalSlotComponent(this);
  55. }
  56. disconnectedCallback() {
  57. disconnectConditionalSlotComponent(this);
  58. }
  59. // --------------------------------------------------------------------------
  60. //
  61. // Component Methods
  62. //
  63. // --------------------------------------------------------------------------
  64. renderTooltip() {
  65. const { el } = this;
  66. const hasTooltip = getSlotted(el, SLOTS.menuTooltip);
  67. return hasTooltip ? h("slot", { name: SLOTS.menuTooltip, slot: ACTION_MENU_SLOTS.tooltip }) : null;
  68. }
  69. renderMenu() {
  70. const { el, expanded, intlMore, menuOpen, scale, layout } = this;
  71. const hasMenuItems = getSlotted(el, SLOTS.menuActions);
  72. 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: ACTION_MENU_SLOTS.trigger, text: intlMore || TEXT.more, textEnabled: expanded }), h("slot", { name: SLOTS.menuActions }), this.renderTooltip())) : null;
  73. }
  74. render() {
  75. return (h(Fragment, null, h("slot", null), this.renderMenu()));
  76. }
  77. static get is() { return "calcite-action-group"; }
  78. static get encapsulation() { return "shadow"; }
  79. static get originalStyleUrls() {
  80. return {
  81. "$": ["action-group.scss"]
  82. };
  83. }
  84. static get styleUrls() {
  85. return {
  86. "$": ["action-group.css"]
  87. };
  88. }
  89. static get properties() {
  90. return {
  91. "expanded": {
  92. "type": "boolean",
  93. "mutable": false,
  94. "complexType": {
  95. "original": "boolean",
  96. "resolved": "boolean",
  97. "references": {}
  98. },
  99. "required": false,
  100. "optional": false,
  101. "docs": {
  102. "tags": [],
  103. "text": "When `true`, the component is expanded."
  104. },
  105. "attribute": "expanded",
  106. "reflect": true,
  107. "defaultValue": "false"
  108. },
  109. "layout": {
  110. "type": "string",
  111. "mutable": false,
  112. "complexType": {
  113. "original": "Layout",
  114. "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
  115. "references": {
  116. "Layout": {
  117. "location": "import",
  118. "path": "../interfaces"
  119. }
  120. }
  121. },
  122. "required": false,
  123. "optional": false,
  124. "docs": {
  125. "tags": [],
  126. "text": "Indicates the layout of the component."
  127. },
  128. "attribute": "layout",
  129. "reflect": true,
  130. "defaultValue": "\"vertical\""
  131. },
  132. "columns": {
  133. "type": "number",
  134. "mutable": false,
  135. "complexType": {
  136. "original": "Columns",
  137. "resolved": "1 | 2 | 3 | 4 | 5 | 6",
  138. "references": {
  139. "Columns": {
  140. "location": "import",
  141. "path": "../interfaces"
  142. }
  143. }
  144. },
  145. "required": false,
  146. "optional": true,
  147. "docs": {
  148. "tags": [],
  149. "text": "Indicates number of columns."
  150. },
  151. "attribute": "columns",
  152. "reflect": true
  153. },
  154. "intlMore": {
  155. "type": "string",
  156. "mutable": false,
  157. "complexType": {
  158. "original": "string",
  159. "resolved": "string",
  160. "references": {}
  161. },
  162. "required": false,
  163. "optional": true,
  164. "docs": {
  165. "tags": [],
  166. "text": "Specifies a text string for the `calcite-action-menu`."
  167. },
  168. "attribute": "intl-more",
  169. "reflect": false
  170. },
  171. "menuOpen": {
  172. "type": "boolean",
  173. "mutable": true,
  174. "complexType": {
  175. "original": "boolean",
  176. "resolved": "boolean",
  177. "references": {}
  178. },
  179. "required": false,
  180. "optional": false,
  181. "docs": {
  182. "tags": [],
  183. "text": "When `true`, the `calcite-action-menu` is open."
  184. },
  185. "attribute": "menu-open",
  186. "reflect": true,
  187. "defaultValue": "false"
  188. },
  189. "scale": {
  190. "type": "string",
  191. "mutable": false,
  192. "complexType": {
  193. "original": "Scale",
  194. "resolved": "\"l\" | \"m\" | \"s\"",
  195. "references": {
  196. "Scale": {
  197. "location": "import",
  198. "path": "../interfaces"
  199. }
  200. }
  201. },
  202. "required": false,
  203. "optional": false,
  204. "docs": {
  205. "tags": [],
  206. "text": "Specifies the size of the `calcite-action-menu`."
  207. },
  208. "attribute": "scale",
  209. "reflect": true
  210. }
  211. };
  212. }
  213. static get elementRef() { return "el"; }
  214. static get watchers() {
  215. return [{
  216. "propName": "expanded",
  217. "methodName": "expandedHandler"
  218. }];
  219. }
  220. }