flow-item.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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, Host } from "@stencil/core";
  7. import { getElementDir } from "../../utils/dom";
  8. import { CSS, ICONS, TEXT, SLOTS } from "./resources";
  9. import { SLOTS as PANEL_SLOTS } from "../panel/resources";
  10. import { updateHostInteraction } from "../../utils/interactive";
  11. /**
  12. * @slot - A slot for adding custom content.
  13. * @slot header-actions-start - A slot for adding actions or content to the start side of the header.
  14. * @slot header-actions-end - A slot for adding actions or content to the end side of the header.
  15. * @slot header-content - A slot for adding custom content to the header.
  16. * @slot header-menu-actions - A slot for adding an overflow menu with actions inside a `calcite-dropdown`.
  17. * @slot fab - A slot for adding a `calcite-fab` (floating action button) to perform an action.
  18. * @slot footer-actions - A slot for adding buttons to the footer.
  19. * @slot footer - A slot for adding custom content to the footer.
  20. */
  21. export class FlowItem {
  22. constructor() {
  23. // --------------------------------------------------------------------------
  24. //
  25. // Properties
  26. //
  27. // --------------------------------------------------------------------------
  28. /** When true, displays a close button in the trailing side of the header */
  29. this.closable = false;
  30. /** When true, flow-item will be hidden */
  31. this.closed = false;
  32. /**
  33. * When true, interaction is prevented and the component is displayed with lower opacity.
  34. */
  35. this.disabled = false;
  36. /**
  37. * When true, a busy indicator is displayed.
  38. */
  39. this.loading = false;
  40. /**
  41. * When true, the action menu items in the `header-menu-actions` slot are open.
  42. */
  43. this.menuOpen = false;
  44. /**
  45. * When true, displays a back button in the header.
  46. */
  47. this.showBackButton = false;
  48. // --------------------------------------------------------------------------
  49. //
  50. // Private Methods
  51. //
  52. // --------------------------------------------------------------------------
  53. this.handlePanelScroll = (event) => {
  54. event.stopPropagation();
  55. this.calciteFlowItemScroll.emit();
  56. };
  57. this.handlePanelClose = (event) => {
  58. event.stopPropagation();
  59. this.calciteFlowItemClose.emit();
  60. };
  61. this.backButtonClick = () => {
  62. this.calciteFlowItemBackClick.emit();
  63. this.calciteFlowItemBack.emit();
  64. };
  65. this.setBackRef = (node) => {
  66. this.backButtonEl = node;
  67. };
  68. this.setContainerRef = (node) => {
  69. this.containerEl = node;
  70. };
  71. this.getBackLabel = () => {
  72. return this.intlBack || TEXT.back;
  73. };
  74. }
  75. //--------------------------------------------------------------------------
  76. //
  77. // Lifecycle
  78. //
  79. //--------------------------------------------------------------------------
  80. componentDidRender() {
  81. updateHostInteraction(this);
  82. }
  83. // --------------------------------------------------------------------------
  84. //
  85. // Methods
  86. //
  87. // --------------------------------------------------------------------------
  88. /**
  89. * Sets focus on the component.
  90. */
  91. async setFocus() {
  92. const { backButtonEl, containerEl } = this;
  93. if (backButtonEl) {
  94. backButtonEl.setFocus();
  95. return;
  96. }
  97. containerEl === null || containerEl === void 0 ? void 0 : containerEl.setFocus();
  98. }
  99. /**
  100. * Scrolls the component's content to a specified set of coordinates.
  101. *
  102. * @example
  103. * myCalciteFlowItem.scrollContentTo({
  104. * left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.
  105. * top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element
  106. * behavior: "auto" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).
  107. * });
  108. * @param options
  109. */
  110. async scrollContentTo(options) {
  111. var _a;
  112. await ((_a = this.containerEl) === null || _a === void 0 ? void 0 : _a.scrollContentTo(options));
  113. }
  114. // --------------------------------------------------------------------------
  115. //
  116. // Render Methods
  117. //
  118. // --------------------------------------------------------------------------
  119. renderBackButton() {
  120. const { el } = this;
  121. const rtl = getElementDir(el) === "rtl";
  122. const { showBackButton, backButtonClick } = this;
  123. const label = this.getBackLabel();
  124. const icon = rtl ? ICONS.backRight : ICONS.backLeft;
  125. return showBackButton ? (h("calcite-action", { "aria-label": label, class: CSS.backButton, icon: icon, key: "flow-back-button", onClick: backButtonClick, ref: this.setBackRef, scale: "s", slot: "header-actions-start", text: label })) : null;
  126. }
  127. render() {
  128. const { closable, closed, description, disabled, heading, headingLevel, heightScale, intlBack, intlClose, intlOptions, loading, menuOpen, widthScale, backButtonEl } = this;
  129. const label = this.getBackLabel();
  130. return (h(Host, null, h("calcite-panel", { closable: closable, closed: closed, description: description, disabled: disabled, heading: heading, headingLevel: headingLevel, heightScale: heightScale, intlBack: intlBack, intlClose: intlClose, intlOptions: intlOptions, loading: loading, menuOpen: menuOpen, onCalcitePanelClose: this.handlePanelClose, onCalcitePanelScroll: this.handlePanelScroll, ref: this.setContainerRef, widthScale: widthScale }, this.renderBackButton(), h("slot", { name: SLOTS.headerActionsStart, slot: PANEL_SLOTS.headerActionsStart }), h("slot", { name: SLOTS.headerActionsEnd, slot: PANEL_SLOTS.headerActionsEnd }), h("slot", { name: SLOTS.headerContent, slot: PANEL_SLOTS.headerContent }), h("slot", { name: SLOTS.headerMenuActions, slot: PANEL_SLOTS.headerMenuActions }), h("slot", { name: SLOTS.fab, slot: PANEL_SLOTS.fab }), h("slot", { name: SLOTS.footerActions, slot: PANEL_SLOTS.footerActions }), h("slot", { name: SLOTS.footer, slot: PANEL_SLOTS.footer }), h("slot", null)), backButtonEl ? (h("calcite-tooltip", { label: label, placement: "auto", referenceElement: backButtonEl }, label)) : null));
  131. }
  132. static get is() { return "calcite-flow-item"; }
  133. static get encapsulation() { return "shadow"; }
  134. static get originalStyleUrls() {
  135. return {
  136. "$": ["flow-item.scss"]
  137. };
  138. }
  139. static get styleUrls() {
  140. return {
  141. "$": ["flow-item.css"]
  142. };
  143. }
  144. static get properties() {
  145. return {
  146. "closable": {
  147. "type": "boolean",
  148. "mutable": true,
  149. "complexType": {
  150. "original": "boolean",
  151. "resolved": "boolean",
  152. "references": {}
  153. },
  154. "required": false,
  155. "optional": false,
  156. "docs": {
  157. "tags": [],
  158. "text": "When true, displays a close button in the trailing side of the header"
  159. },
  160. "attribute": "closable",
  161. "reflect": true,
  162. "defaultValue": "false"
  163. },
  164. "closed": {
  165. "type": "boolean",
  166. "mutable": true,
  167. "complexType": {
  168. "original": "boolean",
  169. "resolved": "boolean",
  170. "references": {}
  171. },
  172. "required": false,
  173. "optional": false,
  174. "docs": {
  175. "tags": [],
  176. "text": "When true, flow-item will be hidden"
  177. },
  178. "attribute": "closed",
  179. "reflect": true,
  180. "defaultValue": "false"
  181. },
  182. "beforeBack": {
  183. "type": "unknown",
  184. "mutable": false,
  185. "complexType": {
  186. "original": "() => Promise<void>",
  187. "resolved": "() => Promise<void>",
  188. "references": {
  189. "Promise": {
  190. "location": "global"
  191. }
  192. }
  193. },
  194. "required": false,
  195. "optional": true,
  196. "docs": {
  197. "tags": [],
  198. "text": "When provided, this method will be called before it is removed from the parent flow."
  199. }
  200. },
  201. "description": {
  202. "type": "string",
  203. "mutable": false,
  204. "complexType": {
  205. "original": "string",
  206. "resolved": "string",
  207. "references": {}
  208. },
  209. "required": false,
  210. "optional": false,
  211. "docs": {
  212. "tags": [],
  213. "text": "A description for the component."
  214. },
  215. "attribute": "description",
  216. "reflect": false
  217. },
  218. "disabled": {
  219. "type": "boolean",
  220. "mutable": false,
  221. "complexType": {
  222. "original": "boolean",
  223. "resolved": "boolean",
  224. "references": {}
  225. },
  226. "required": false,
  227. "optional": false,
  228. "docs": {
  229. "tags": [],
  230. "text": "When true, interaction is prevented and the component is displayed with lower opacity."
  231. },
  232. "attribute": "disabled",
  233. "reflect": true,
  234. "defaultValue": "false"
  235. },
  236. "heading": {
  237. "type": "string",
  238. "mutable": false,
  239. "complexType": {
  240. "original": "string",
  241. "resolved": "string",
  242. "references": {}
  243. },
  244. "required": false,
  245. "optional": true,
  246. "docs": {
  247. "tags": [],
  248. "text": "The component header text."
  249. },
  250. "attribute": "heading",
  251. "reflect": false
  252. },
  253. "headingLevel": {
  254. "type": "number",
  255. "mutable": false,
  256. "complexType": {
  257. "original": "HeadingLevel",
  258. "resolved": "1 | 2 | 3 | 4 | 5 | 6",
  259. "references": {
  260. "HeadingLevel": {
  261. "location": "import",
  262. "path": "../functional/Heading"
  263. }
  264. }
  265. },
  266. "required": false,
  267. "optional": false,
  268. "docs": {
  269. "tags": [],
  270. "text": "Specifies the number at which section headings should start."
  271. },
  272. "attribute": "heading-level",
  273. "reflect": true
  274. },
  275. "heightScale": {
  276. "type": "string",
  277. "mutable": false,
  278. "complexType": {
  279. "original": "Scale",
  280. "resolved": "\"l\" | \"m\" | \"s\"",
  281. "references": {
  282. "Scale": {
  283. "location": "import",
  284. "path": "../interfaces"
  285. }
  286. }
  287. },
  288. "required": false,
  289. "optional": true,
  290. "docs": {
  291. "tags": [],
  292. "text": "Specifies the maximum height of the component."
  293. },
  294. "attribute": "height-scale",
  295. "reflect": true
  296. },
  297. "intlBack": {
  298. "type": "string",
  299. "mutable": false,
  300. "complexType": {
  301. "original": "string",
  302. "resolved": "string",
  303. "references": {}
  304. },
  305. "required": false,
  306. "optional": true,
  307. "docs": {
  308. "tags": [],
  309. "text": "Accessible name for the component's back button. The back button will only be shown when 'showBackButton' is true."
  310. },
  311. "attribute": "intl-back",
  312. "reflect": false
  313. },
  314. "intlClose": {
  315. "type": "string",
  316. "mutable": false,
  317. "complexType": {
  318. "original": "string",
  319. "resolved": "string",
  320. "references": {}
  321. },
  322. "required": false,
  323. "optional": true,
  324. "docs": {
  325. "tags": [],
  326. "text": "Accessible name for the component's close button. The close button will only be shown when 'dismissible' is true."
  327. },
  328. "attribute": "intl-close",
  329. "reflect": false
  330. },
  331. "intlOptions": {
  332. "type": "string",
  333. "mutable": false,
  334. "complexType": {
  335. "original": "string",
  336. "resolved": "string",
  337. "references": {}
  338. },
  339. "required": false,
  340. "optional": true,
  341. "docs": {
  342. "tags": [],
  343. "text": "Accessible name for the component's actions menu."
  344. },
  345. "attribute": "intl-options",
  346. "reflect": false
  347. },
  348. "loading": {
  349. "type": "boolean",
  350. "mutable": false,
  351. "complexType": {
  352. "original": "boolean",
  353. "resolved": "boolean",
  354. "references": {}
  355. },
  356. "required": false,
  357. "optional": false,
  358. "docs": {
  359. "tags": [],
  360. "text": "When true, a busy indicator is displayed."
  361. },
  362. "attribute": "loading",
  363. "reflect": true,
  364. "defaultValue": "false"
  365. },
  366. "menuOpen": {
  367. "type": "boolean",
  368. "mutable": false,
  369. "complexType": {
  370. "original": "boolean",
  371. "resolved": "boolean",
  372. "references": {}
  373. },
  374. "required": false,
  375. "optional": false,
  376. "docs": {
  377. "tags": [],
  378. "text": "When true, the action menu items in the `header-menu-actions` slot are open."
  379. },
  380. "attribute": "menu-open",
  381. "reflect": true,
  382. "defaultValue": "false"
  383. },
  384. "showBackButton": {
  385. "type": "boolean",
  386. "mutable": false,
  387. "complexType": {
  388. "original": "boolean",
  389. "resolved": "boolean",
  390. "references": {}
  391. },
  392. "required": false,
  393. "optional": false,
  394. "docs": {
  395. "tags": [],
  396. "text": "When true, displays a back button in the header."
  397. },
  398. "attribute": "show-back-button",
  399. "reflect": true,
  400. "defaultValue": "false"
  401. },
  402. "widthScale": {
  403. "type": "string",
  404. "mutable": false,
  405. "complexType": {
  406. "original": "Scale",
  407. "resolved": "\"l\" | \"m\" | \"s\"",
  408. "references": {
  409. "Scale": {
  410. "location": "import",
  411. "path": "../interfaces"
  412. }
  413. }
  414. },
  415. "required": false,
  416. "optional": true,
  417. "docs": {
  418. "tags": [],
  419. "text": "Specifies the width of the component."
  420. },
  421. "attribute": "width-scale",
  422. "reflect": true
  423. }
  424. };
  425. }
  426. static get states() {
  427. return {
  428. "backButtonEl": {}
  429. };
  430. }
  431. static get events() {
  432. return [{
  433. "method": "calciteFlowItemBack",
  434. "name": "calciteFlowItemBack",
  435. "bubbles": true,
  436. "cancelable": false,
  437. "composed": true,
  438. "docs": {
  439. "tags": [],
  440. "text": "Fires when the back button is clicked."
  441. },
  442. "complexType": {
  443. "original": "void",
  444. "resolved": "void",
  445. "references": {}
  446. }
  447. }, {
  448. "method": "calciteFlowItemBackClick",
  449. "name": "calciteFlowItemBackClick",
  450. "bubbles": true,
  451. "cancelable": false,
  452. "composed": true,
  453. "docs": {
  454. "tags": [{
  455. "name": "deprecated",
  456. "text": "use calciteFlowItemBack instead."
  457. }],
  458. "text": "Fires when the back button is clicked."
  459. },
  460. "complexType": {
  461. "original": "void",
  462. "resolved": "void",
  463. "references": {}
  464. }
  465. }, {
  466. "method": "calciteFlowItemScroll",
  467. "name": "calciteFlowItemScroll",
  468. "bubbles": true,
  469. "cancelable": false,
  470. "composed": true,
  471. "docs": {
  472. "tags": [],
  473. "text": "Fires when the content is scrolled."
  474. },
  475. "complexType": {
  476. "original": "void",
  477. "resolved": "void",
  478. "references": {}
  479. }
  480. }, {
  481. "method": "calciteFlowItemClose",
  482. "name": "calciteFlowItemClose",
  483. "bubbles": true,
  484. "cancelable": false,
  485. "composed": true,
  486. "docs": {
  487. "tags": [],
  488. "text": "Fires when the close button is clicked."
  489. },
  490. "complexType": {
  491. "original": "void",
  492. "resolved": "void",
  493. "references": {}
  494. }
  495. }];
  496. }
  497. static get methods() {
  498. return {
  499. "setFocus": {
  500. "complexType": {
  501. "signature": "() => Promise<void>",
  502. "parameters": [],
  503. "references": {
  504. "Promise": {
  505. "location": "global"
  506. }
  507. },
  508. "return": "Promise<void>"
  509. },
  510. "docs": {
  511. "text": "Sets focus on the component.",
  512. "tags": []
  513. }
  514. },
  515. "scrollContentTo": {
  516. "complexType": {
  517. "signature": "(options?: ScrollToOptions) => Promise<void>",
  518. "parameters": [{
  519. "tags": [{
  520. "name": "param",
  521. "text": "options"
  522. }],
  523. "text": ""
  524. }],
  525. "references": {
  526. "Promise": {
  527. "location": "global"
  528. },
  529. "ScrollToOptions": {
  530. "location": "global"
  531. }
  532. },
  533. "return": "Promise<void>"
  534. },
  535. "docs": {
  536. "text": "Scrolls the component's content to a specified set of coordinates.",
  537. "tags": [{
  538. "name": "example",
  539. "text": "myCalciteFlowItem.scrollContentTo({\n left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.\n top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element\n behavior: \"auto\" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).\n});"
  540. }, {
  541. "name": "param",
  542. "text": "options"
  543. }]
  544. }
  545. }
  546. };
  547. }
  548. static get elementRef() { return "el"; }
  549. }