action-pad.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 { Component, Element, Event, Host, Prop, Watch, h, Method } from "@stencil/core";
  7. import { ExpandToggle, toggleChildActionText } from "../functional/ExpandToggle";
  8. import { focusElement, getSlotted } from "../../utils/dom";
  9. import { CSS, TEXT, SLOTS } from "./resources";
  10. import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
  11. /**
  12. * @slot - A slot for adding `calcite-action`s to the action pad.
  13. * @slot expand-tooltip - Used to set the tooltip for the expand toggle.
  14. */
  15. export class ActionPad {
  16. constructor() {
  17. // --------------------------------------------------------------------------
  18. //
  19. // Properties
  20. //
  21. // --------------------------------------------------------------------------
  22. /**
  23. * When set to true, the expand-toggling behavior will be disabled.
  24. */
  25. this.expandDisabled = false;
  26. /**
  27. * Indicates whether widget is expanded.
  28. */
  29. this.expanded = false;
  30. /**
  31. * Indicates the horizontal or vertical layout of the component.
  32. */
  33. this.layout = "vertical";
  34. // --------------------------------------------------------------------------
  35. //
  36. // Private Methods
  37. //
  38. // --------------------------------------------------------------------------
  39. this.actionMenuOpenChangeHandler = (event) => {
  40. if (event.detail) {
  41. const composedPath = event.composedPath();
  42. Array.from(this.el.querySelectorAll("calcite-action-group")).forEach((group) => {
  43. if (!composedPath.includes(group)) {
  44. group.menuOpen = false;
  45. }
  46. });
  47. }
  48. };
  49. this.toggleExpand = () => {
  50. this.expanded = !this.expanded;
  51. this.calciteActionPadToggle.emit();
  52. };
  53. this.setExpandToggleRef = (el) => {
  54. this.expandToggleEl = el;
  55. };
  56. }
  57. expandedHandler(expanded) {
  58. toggleChildActionText({ parent: this.el, expanded });
  59. }
  60. // --------------------------------------------------------------------------
  61. //
  62. // Lifecycle
  63. //
  64. // --------------------------------------------------------------------------
  65. connectedCallback() {
  66. connectConditionalSlotComponent(this);
  67. }
  68. disconnectedCallback() {
  69. disconnectConditionalSlotComponent(this);
  70. }
  71. componentWillLoad() {
  72. const { el, expanded } = this;
  73. toggleChildActionText({ parent: el, expanded });
  74. }
  75. // --------------------------------------------------------------------------
  76. //
  77. // Methods
  78. //
  79. // --------------------------------------------------------------------------
  80. /** Sets focus on the component. */
  81. async setFocus(focusId) {
  82. if (focusId === "expand-toggle") {
  83. await focusElement(this.expandToggleEl);
  84. return;
  85. }
  86. this.el.focus();
  87. }
  88. // --------------------------------------------------------------------------
  89. //
  90. // Component Methods
  91. //
  92. // --------------------------------------------------------------------------
  93. renderBottomActionGroup() {
  94. const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale } = this;
  95. const tooltip = getSlotted(el, SLOTS.expandTooltip);
  96. const expandLabel = intlExpand || TEXT.expand;
  97. const collapseLabel = intlCollapse || TEXT.collapse;
  98. const expandToggleNode = !expandDisabled ? (h(ExpandToggle, { el: el, expanded: expanded, intlCollapse: collapseLabel, intlExpand: expandLabel, position: position, ref: this.setExpandToggleRef, scale: scale, toggle: toggleExpand, tooltip: tooltip })) : null;
  99. return expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom, scale: scale },
  100. h("slot", { name: SLOTS.expandTooltip }),
  101. expandToggleNode)) : null;
  102. }
  103. render() {
  104. return (h(Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler },
  105. h("div", { class: CSS.container },
  106. h("slot", null),
  107. this.renderBottomActionGroup())));
  108. }
  109. static get is() { return "calcite-action-pad"; }
  110. static get encapsulation() { return "shadow"; }
  111. static get originalStyleUrls() { return {
  112. "$": ["action-pad.scss"]
  113. }; }
  114. static get styleUrls() { return {
  115. "$": ["action-pad.css"]
  116. }; }
  117. static get properties() { return {
  118. "expandDisabled": {
  119. "type": "boolean",
  120. "mutable": false,
  121. "complexType": {
  122. "original": "boolean",
  123. "resolved": "boolean",
  124. "references": {}
  125. },
  126. "required": false,
  127. "optional": false,
  128. "docs": {
  129. "tags": [],
  130. "text": "When set to true, the expand-toggling behavior will be disabled."
  131. },
  132. "attribute": "expand-disabled",
  133. "reflect": true,
  134. "defaultValue": "false"
  135. },
  136. "expanded": {
  137. "type": "boolean",
  138. "mutable": true,
  139. "complexType": {
  140. "original": "boolean",
  141. "resolved": "boolean",
  142. "references": {}
  143. },
  144. "required": false,
  145. "optional": false,
  146. "docs": {
  147. "tags": [],
  148. "text": "Indicates whether widget is expanded."
  149. },
  150. "attribute": "expanded",
  151. "reflect": true,
  152. "defaultValue": "false"
  153. },
  154. "layout": {
  155. "type": "string",
  156. "mutable": false,
  157. "complexType": {
  158. "original": "Layout",
  159. "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
  160. "references": {
  161. "Layout": {
  162. "location": "import",
  163. "path": "../interfaces"
  164. }
  165. }
  166. },
  167. "required": false,
  168. "optional": false,
  169. "docs": {
  170. "tags": [],
  171. "text": "Indicates the horizontal or vertical layout of the component."
  172. },
  173. "attribute": "layout",
  174. "reflect": true,
  175. "defaultValue": "\"vertical\""
  176. },
  177. "intlExpand": {
  178. "type": "string",
  179. "mutable": false,
  180. "complexType": {
  181. "original": "string",
  182. "resolved": "string",
  183. "references": {}
  184. },
  185. "required": false,
  186. "optional": true,
  187. "docs": {
  188. "tags": [],
  189. "text": "Updates the label of the expand icon when the component is not expanded."
  190. },
  191. "attribute": "intl-expand",
  192. "reflect": false
  193. },
  194. "intlCollapse": {
  195. "type": "string",
  196. "mutable": false,
  197. "complexType": {
  198. "original": "string",
  199. "resolved": "string",
  200. "references": {}
  201. },
  202. "required": false,
  203. "optional": true,
  204. "docs": {
  205. "tags": [],
  206. "text": "Updates the label of the collapse icon when the component is expanded."
  207. },
  208. "attribute": "intl-collapse",
  209. "reflect": false
  210. },
  211. "position": {
  212. "type": "string",
  213. "mutable": false,
  214. "complexType": {
  215. "original": "Position",
  216. "resolved": "\"end\" | \"start\"",
  217. "references": {
  218. "Position": {
  219. "location": "import",
  220. "path": "../interfaces"
  221. }
  222. }
  223. },
  224. "required": false,
  225. "optional": false,
  226. "docs": {
  227. "tags": [],
  228. "text": "Arranges the component depending on the elements 'dir' property."
  229. },
  230. "attribute": "position",
  231. "reflect": true
  232. },
  233. "scale": {
  234. "type": "string",
  235. "mutable": false,
  236. "complexType": {
  237. "original": "Scale",
  238. "resolved": "\"l\" | \"m\" | \"s\"",
  239. "references": {
  240. "Scale": {
  241. "location": "import",
  242. "path": "../interfaces"
  243. }
  244. }
  245. },
  246. "required": false,
  247. "optional": false,
  248. "docs": {
  249. "tags": [],
  250. "text": "Specifies the size of the expand action."
  251. },
  252. "attribute": "scale",
  253. "reflect": true
  254. }
  255. }; }
  256. static get events() { return [{
  257. "method": "calciteActionPadToggle",
  258. "name": "calciteActionPadToggle",
  259. "bubbles": true,
  260. "cancelable": true,
  261. "composed": true,
  262. "docs": {
  263. "tags": [],
  264. "text": "Emitted when expanded has been toggled."
  265. },
  266. "complexType": {
  267. "original": "any",
  268. "resolved": "any",
  269. "references": {}
  270. }
  271. }]; }
  272. static get methods() { return {
  273. "setFocus": {
  274. "complexType": {
  275. "signature": "(focusId?: \"expand-toggle\") => Promise<void>",
  276. "parameters": [{
  277. "tags": [],
  278. "text": ""
  279. }],
  280. "references": {
  281. "Promise": {
  282. "location": "global"
  283. }
  284. },
  285. "return": "Promise<void>"
  286. },
  287. "docs": {
  288. "text": "Sets focus on the component.",
  289. "tags": []
  290. }
  291. }
  292. }; }
  293. static get elementRef() { return "el"; }
  294. static get watchers() { return [{
  295. "propName": "expanded",
  296. "methodName": "expandedHandler"
  297. }]; }
  298. }