action-pad.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 { Host, h } 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 component.
  13. * @slot expand-tooltip - Used to set the `calcite-tooltip` for the expand toggle.
  14. */
  15. export class ActionPad {
  16. constructor() {
  17. // --------------------------------------------------------------------------
  18. //
  19. // Properties
  20. //
  21. // --------------------------------------------------------------------------
  22. /**
  23. * When `true`, the expand-toggling behavior is disabled.
  24. */
  25. this.expandDisabled = false;
  26. /**
  27. * When `true`, the component is expanded.
  28. */
  29. this.expanded = false;
  30. /**
  31. * Indicates the 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. /**
  81. * Sets focus on the component.
  82. *
  83. * @param focusId
  84. */
  85. async setFocus(focusId) {
  86. var _a;
  87. if (focusId === "expand-toggle") {
  88. await focusElement(this.expandToggleEl);
  89. return;
  90. }
  91. (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus();
  92. }
  93. // --------------------------------------------------------------------------
  94. //
  95. // Component Methods
  96. //
  97. // --------------------------------------------------------------------------
  98. renderBottomActionGroup() {
  99. const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale, layout } = this;
  100. const tooltip = getSlotted(el, SLOTS.expandTooltip);
  101. const expandLabel = intlExpand || TEXT.expand;
  102. const collapseLabel = intlCollapse || TEXT.collapse;
  103. 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;
  104. return expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom, layout: layout, scale: scale }, h("slot", { name: SLOTS.expandTooltip }), expandToggleNode)) : null;
  105. }
  106. render() {
  107. return (h(Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler }, h("div", { class: CSS.container }, h("slot", null), this.renderBottomActionGroup())));
  108. }
  109. static get is() { return "calcite-action-pad"; }
  110. static get encapsulation() { return "shadow"; }
  111. static get originalStyleUrls() {
  112. return {
  113. "$": ["action-pad.scss"]
  114. };
  115. }
  116. static get styleUrls() {
  117. return {
  118. "$": ["action-pad.css"]
  119. };
  120. }
  121. static get properties() {
  122. return {
  123. "expandDisabled": {
  124. "type": "boolean",
  125. "mutable": false,
  126. "complexType": {
  127. "original": "boolean",
  128. "resolved": "boolean",
  129. "references": {}
  130. },
  131. "required": false,
  132. "optional": false,
  133. "docs": {
  134. "tags": [],
  135. "text": "When `true`, the expand-toggling behavior is disabled."
  136. },
  137. "attribute": "expand-disabled",
  138. "reflect": true,
  139. "defaultValue": "false"
  140. },
  141. "expanded": {
  142. "type": "boolean",
  143. "mutable": true,
  144. "complexType": {
  145. "original": "boolean",
  146. "resolved": "boolean",
  147. "references": {}
  148. },
  149. "required": false,
  150. "optional": false,
  151. "docs": {
  152. "tags": [],
  153. "text": "When `true`, the component is expanded."
  154. },
  155. "attribute": "expanded",
  156. "reflect": true,
  157. "defaultValue": "false"
  158. },
  159. "layout": {
  160. "type": "string",
  161. "mutable": false,
  162. "complexType": {
  163. "original": "Layout",
  164. "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
  165. "references": {
  166. "Layout": {
  167. "location": "import",
  168. "path": "../interfaces"
  169. }
  170. }
  171. },
  172. "required": false,
  173. "optional": false,
  174. "docs": {
  175. "tags": [],
  176. "text": "Indicates the layout of the component."
  177. },
  178. "attribute": "layout",
  179. "reflect": true,
  180. "defaultValue": "\"vertical\""
  181. },
  182. "intlExpand": {
  183. "type": "string",
  184. "mutable": false,
  185. "complexType": {
  186. "original": "string",
  187. "resolved": "string",
  188. "references": {}
  189. },
  190. "required": false,
  191. "optional": true,
  192. "docs": {
  193. "tags": [],
  194. "text": "Specifies the label of the expand icon when the component is collapsed."
  195. },
  196. "attribute": "intl-expand",
  197. "reflect": false
  198. },
  199. "intlCollapse": {
  200. "type": "string",
  201. "mutable": false,
  202. "complexType": {
  203. "original": "string",
  204. "resolved": "string",
  205. "references": {}
  206. },
  207. "required": false,
  208. "optional": true,
  209. "docs": {
  210. "tags": [],
  211. "text": "Specifies the label of the collapse icon when the component is expanded."
  212. },
  213. "attribute": "intl-collapse",
  214. "reflect": false
  215. },
  216. "position": {
  217. "type": "string",
  218. "mutable": false,
  219. "complexType": {
  220. "original": "Position",
  221. "resolved": "\"end\" | \"start\"",
  222. "references": {
  223. "Position": {
  224. "location": "import",
  225. "path": "../interfaces"
  226. }
  227. }
  228. },
  229. "required": false,
  230. "optional": false,
  231. "docs": {
  232. "tags": [],
  233. "text": "Arranges the component depending on the element's `dir` property."
  234. },
  235. "attribute": "position",
  236. "reflect": true
  237. },
  238. "scale": {
  239. "type": "string",
  240. "mutable": false,
  241. "complexType": {
  242. "original": "Scale",
  243. "resolved": "\"l\" | \"m\" | \"s\"",
  244. "references": {
  245. "Scale": {
  246. "location": "import",
  247. "path": "../interfaces"
  248. }
  249. }
  250. },
  251. "required": false,
  252. "optional": false,
  253. "docs": {
  254. "tags": [],
  255. "text": "Specifies the size of the expand `calcite-action`."
  256. },
  257. "attribute": "scale",
  258. "reflect": true
  259. }
  260. };
  261. }
  262. static get events() {
  263. return [{
  264. "method": "calciteActionPadToggle",
  265. "name": "calciteActionPadToggle",
  266. "bubbles": true,
  267. "cancelable": false,
  268. "composed": true,
  269. "docs": {
  270. "tags": [],
  271. "text": "Emits when the `expanded` property is toggled."
  272. },
  273. "complexType": {
  274. "original": "void",
  275. "resolved": "void",
  276. "references": {}
  277. }
  278. }];
  279. }
  280. static get methods() {
  281. return {
  282. "setFocus": {
  283. "complexType": {
  284. "signature": "(focusId?: \"expand-toggle\") => Promise<void>",
  285. "parameters": [{
  286. "tags": [{
  287. "name": "param",
  288. "text": "focusId"
  289. }],
  290. "text": ""
  291. }],
  292. "references": {
  293. "Promise": {
  294. "location": "global"
  295. }
  296. },
  297. "return": "Promise<void>"
  298. },
  299. "docs": {
  300. "text": "Sets focus on the component.",
  301. "tags": [{
  302. "name": "param",
  303. "text": "focusId"
  304. }]
  305. }
  306. }
  307. };
  308. }
  309. static get elementRef() { return "el"; }
  310. static get watchers() {
  311. return [{
  312. "propName": "expanded",
  313. "methodName": "expandedHandler"
  314. }];
  315. }
  316. }