calcite-stepper_2.cjs.entry.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const dom = require('./dom-9ac0341c.js');
  10. const interactive = require('./interactive-e294111f.js');
  11. require('./guid-8b6d6cb4.js');
  12. const stepperCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:-ms-flexbox;display:flex;width:100%;min-width:100%;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:justify;justify-content:space-between}:host([layout=vertical]){-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column}:host ::slotted(.calcite-stepper-content){display:-ms-flexbox;display:flex;width:100%;min-width:100%;-ms-flex-direction:column;flex-direction:column;-ms-flex-wrap:wrap;flex-wrap:wrap}";
  13. const Stepper = class {
  14. constructor(hostRef) {
  15. index.registerInstance(this, hostRef);
  16. this.calciteStepperItemChange = index.createEvent(this, "calciteStepperItemChange", 7);
  17. //--------------------------------------------------------------------------
  18. //
  19. // Public Properties
  20. //
  21. //--------------------------------------------------------------------------
  22. /** optionally display a status icon next to the step title */
  23. this.icon = false;
  24. /** specify the layout of stepper, defaults to horizontal */
  25. this.layout = "horizontal";
  26. /** optionally display the number next to the step title */
  27. this.numbered = false;
  28. /** specify the scale of stepper, defaults to m */
  29. this.scale = "m";
  30. //--------------------------------------------------------------------------
  31. //
  32. // Private State/Props
  33. //
  34. //--------------------------------------------------------------------------
  35. this.itemMap = new Map();
  36. /** list of sorted Stepper items */
  37. this.items = [];
  38. /** list of enabled Stepper items */
  39. this.enabledItems = [];
  40. }
  41. // watch for removal of disabled to register step
  42. contentWatcher() {
  43. if (this.layout === "horizontal") {
  44. if (!this.stepperContentContainer && this.requestedContent) {
  45. this.addHorizontalContentContainer();
  46. }
  47. this.updateContent(this.requestedContent);
  48. }
  49. }
  50. //--------------------------------------------------------------------------
  51. //
  52. // Lifecycle
  53. //
  54. //--------------------------------------------------------------------------
  55. componentDidLoad() {
  56. // if no stepper items are set as active, default to the first one
  57. if (!this.currentPosition) {
  58. this.calciteStepperItemChange.emit({
  59. position: 0
  60. });
  61. }
  62. }
  63. componentWillLoad() {
  64. if (this.layout === "horizontal" && !this.stepperContentContainer) {
  65. this.addHorizontalContentContainer();
  66. }
  67. }
  68. render() {
  69. return index.h("slot", null);
  70. }
  71. //--------------------------------------------------------------------------
  72. //
  73. // Event Listeners
  74. //
  75. //--------------------------------------------------------------------------
  76. calciteStepperItemKeyEvent(e) {
  77. const item = e.detail.item;
  78. const itemToFocus = e.target;
  79. const isFirstItem = this.itemIndex(itemToFocus) === 0;
  80. const isLastItem = this.itemIndex(itemToFocus) === this.enabledItems.length - 1;
  81. switch (item.key) {
  82. case "ArrowDown":
  83. case "ArrowRight":
  84. if (isLastItem) {
  85. this.focusFirstItem();
  86. }
  87. else {
  88. this.focusNextItem(itemToFocus);
  89. }
  90. break;
  91. case "ArrowUp":
  92. case "ArrowLeft":
  93. if (isFirstItem) {
  94. this.focusLastItem();
  95. }
  96. else {
  97. this.focusPrevItem(itemToFocus);
  98. }
  99. break;
  100. case "Home":
  101. this.focusFirstItem();
  102. break;
  103. case "End":
  104. this.focusLastItem();
  105. break;
  106. }
  107. }
  108. registerItem(event) {
  109. const item = event.target;
  110. const { content, position } = event.detail;
  111. if (content && item.active) {
  112. this.requestedContent = content;
  113. }
  114. this.itemMap.set(item, position);
  115. this.items = this.sortItems();
  116. this.enabledItems = this.filterItems();
  117. }
  118. updateItem(event) {
  119. if (event.detail.content) {
  120. this.requestedContent = event.detail.content;
  121. }
  122. this.currentPosition = event.detail.position;
  123. this.calciteStepperItemChange.emit({
  124. position: this.currentPosition
  125. });
  126. }
  127. //--------------------------------------------------------------------------
  128. //
  129. // Public Methods
  130. //
  131. //--------------------------------------------------------------------------
  132. /** set the next step as active */
  133. async nextStep() {
  134. const enabledStepIndex = this.getEnabledStepIndex(this.currentPosition + 1, "next");
  135. if (typeof enabledStepIndex !== "number") {
  136. return;
  137. }
  138. this.emitChangedItem(enabledStepIndex);
  139. }
  140. /** set the previous step as active */
  141. async prevStep() {
  142. const enabledStepIndex = this.getEnabledStepIndex(this.currentPosition - 1, "previous");
  143. if (typeof enabledStepIndex !== "number") {
  144. return;
  145. }
  146. this.emitChangedItem(enabledStepIndex);
  147. }
  148. /** set the requested step as active */
  149. async goToStep(step) {
  150. const position = step - 1;
  151. if (this.currentPosition !== position) {
  152. this.emitChangedItem(position);
  153. }
  154. }
  155. /** set the first step as active */
  156. async startStep() {
  157. const enabledStepIndex = this.getEnabledStepIndex(0, "next");
  158. if (typeof enabledStepIndex !== "number") {
  159. return;
  160. }
  161. this.emitChangedItem(enabledStepIndex);
  162. }
  163. /** set the last step as active */
  164. async endStep() {
  165. const enabledStepIndex = this.getEnabledStepIndex(this.items.length - 1, "previous");
  166. if (typeof enabledStepIndex !== "number") {
  167. return;
  168. }
  169. this.emitChangedItem(enabledStepIndex);
  170. }
  171. //--------------------------------------------------------------------------
  172. //
  173. // Private Methods
  174. //
  175. //--------------------------------------------------------------------------
  176. getEnabledStepIndex(startIndex, direction = "next") {
  177. var _a;
  178. const { items, currentPosition } = this;
  179. let newIndex = startIndex;
  180. while ((_a = items[newIndex]) === null || _a === void 0 ? void 0 : _a.disabled) {
  181. newIndex = newIndex + (direction === "previous" ? -1 : 1);
  182. }
  183. return newIndex !== currentPosition && newIndex < items.length && newIndex >= 0
  184. ? newIndex
  185. : null;
  186. }
  187. addHorizontalContentContainer() {
  188. this.stepperContentContainer = document.createElement("div");
  189. this.stepperContentContainer.classList.add("calcite-stepper-content");
  190. this.el.insertAdjacentElement("beforeend", this.stepperContentContainer);
  191. }
  192. emitChangedItem(position) {
  193. this.currentPosition = position;
  194. this.calciteStepperItemChange.emit({
  195. position
  196. });
  197. }
  198. focusFirstItem() {
  199. const firstItem = this.enabledItems[0];
  200. this.focusElement(firstItem);
  201. }
  202. focusLastItem() {
  203. const lastItem = this.enabledItems[this.enabledItems.length - 1];
  204. this.focusElement(lastItem);
  205. }
  206. focusNextItem(e) {
  207. const index = this.itemIndex(e);
  208. const nextItem = this.enabledItems[index + 1] || this.enabledItems[0];
  209. this.focusElement(nextItem);
  210. }
  211. focusPrevItem(e) {
  212. const index = this.itemIndex(e);
  213. const prevItem = this.enabledItems[index - 1] || this.enabledItems[this.enabledItems.length - 1];
  214. this.focusElement(prevItem);
  215. }
  216. itemIndex(e) {
  217. return this.enabledItems.indexOf(e);
  218. }
  219. focusElement(item) {
  220. item.focus();
  221. }
  222. sortItems() {
  223. const { itemMap } = this;
  224. return Array.from(itemMap.keys()).sort((a, b) => itemMap.get(a) - itemMap.get(b));
  225. }
  226. filterItems() {
  227. return this.items.filter((item) => !item.disabled);
  228. }
  229. updateContent(content) {
  230. this.stepperContentContainer.innerHTML = "";
  231. this.stepperContentContainer.append(...content);
  232. }
  233. get el() { return index.getElement(this); }
  234. static get watchers() { return {
  235. "requestedContent": ["contentWatcher"]
  236. }; }
  237. };
  238. Stepper.style = stepperCss;
  239. const stepperItemCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([scale=s]){--calcite-stepper-item-spacing-unit-s:0.25rem;--calcite-stepper-item-spacing-unit-m:0.75rem;--calcite-stepper-item-spacing-unit-l:1rem;font-size:var(--calcite-font-size--1);line-height:1rem;-webkit-margin-end:0.25rem;margin-inline-end:0.25rem}:host([scale=s]) .stepper-item-subtitle{font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]){--calcite-stepper-item-spacing-unit-s:0.5rem;--calcite-stepper-item-spacing-unit-m:1rem;--calcite-stepper-item-spacing-unit-l:1.25rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;-webkit-margin-end:0.5rem;margin-inline-end:0.5rem}:host([scale=m]) .stepper-item-subtitle{font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]){--calcite-stepper-item-spacing-unit-s:0.75rem;--calcite-stepper-item-spacing-unit-m:1.25rem;--calcite-stepper-item-spacing-unit-l:1.5rem;font-size:var(--calcite-font-size-1);line-height:1.5rem;-webkit-margin-end:0.75rem;margin-inline-end:0.75rem}:host([scale=l]) .stepper-item-subtitle{font-size:var(--calcite-font-size-0);line-height:1.25rem}:host{position:relative;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;-ms-flex-direction:column;flex-direction:column;margin-bottom:var(--calcite-stepper-item-spacing-unit-s)}:host .container{position:relative;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;cursor:pointer;-ms-flex-direction:column;flex-direction:column;border-width:0px;border-top-width:2px;border-style:solid;border-color:var(--calcite-ui-border-3);color:var(--calcite-ui-text-3);-webkit-text-decoration-line:none;text-decoration-line:none;outline:2px solid transparent;outline-offset:2px;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host{outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}:host(:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:2px}:host .stepper-item-header{display:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-align:start;align-items:flex-start}:host .stepper-item-content,:host .stepper-item-header{-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);padding-block:var(--calcite-stepper-item-spacing-unit-l);-webkit-padding-end:var(--calcite-stepper-item-spacing-unit-m);padding-inline-end:var(--calcite-stepper-item-spacing-unit-m);text-align:start}:host .stepper-item-header *{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-align:center;align-items:center;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host .stepper-item-content{display:none;width:100%;-ms-flex-direction:column;flex-direction:column;font-size:var(--calcite-font-size--2);line-height:1.375}:host .stepper-item-icon{-webkit-margin-end:var(--calcite-stepper-item-spacing-unit-m);margin-inline-end:var(--calcite-stepper-item-spacing-unit-m);margin-top:1px;display:-ms-inline-flexbox;display:inline-flex;height:0.75rem;-ms-flex-negative:0;flex-shrink:0;-ms-flex-item-align:start;align-self:flex-start;color:var(--calcite-ui-text-3);opacity:var(--calcite-ui-opacity-disabled);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host .stepper-item-header-text{-ms-flex-direction:column;flex-direction:column;text-align:initial;-webkit-margin-end:auto;margin-inline-end:auto}:host .stepper-item-title,:host .stepper-item-subtitle{display:-ms-flexbox;display:flex;width:100%}:host .stepper-item-title{margin-bottom:0.25rem;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2)}:host .stepper-item-subtitle{color:var(--calcite-ui-text-3)}:host .stepper-item-number{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-3);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-margin-end:var(--calcite-stepper-item-spacing-unit-m);margin-inline-end:var(--calcite-stepper-item-spacing-unit-m)}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([complete]) .container{border-color:rgba(0, 122, 194, 0.5)}:host([complete]) .container .stepper-item-icon{color:var(--calcite-ui-brand)}:host([error]) .container{border-top-color:var(--calcite-ui-danger)}:host([error]) .container .stepper-item-number{color:var(--calcite-ui-danger)}:host([error]) .container .stepper-item-icon{opacity:1;color:var(--calcite-ui-danger)}:host(:hover:not([disabled]):not([active])) .container,:host(:focus:not([disabled]):not([active])) .container{border-top-color:var(--calcite-ui-brand)}:host(:hover:not([disabled]):not([active])) .container .stepper-item-title,:host(:focus:not([disabled]):not([active])) .container .stepper-item-title{color:var(--calcite-ui-text-1)}:host(:hover:not([disabled]):not([active])) .container .stepper-item-subtitle,:host(:focus:not([disabled]):not([active])) .container .stepper-item-subtitle{color:var(--calcite-ui-text-2)}:host([error]:hover:not([disabled]):not([active])) .container,:host([error]:focus:not([disabled]):not([active])) .container{border-top-color:var(--calcite-ui-danger-hover)}:host([active]) .container{border-top-color:var(--calcite-ui-brand)}:host([active]) .container .stepper-item-title{color:var(--calcite-ui-text-1)}:host([active]) .container .stepper-item-subtitle{color:var(--calcite-ui-text-2)}:host([active]) .container .stepper-item-number{color:var(--calcite-ui-brand)}:host([active]) .container .stepper-item-icon{color:var(--calcite-ui-brand);opacity:1}:host([layout=vertical]) .container{margin-left:0px;margin-right:0px;margin-top:0px;-ms-flex:1 1 auto;flex:1 1 auto;border-top-width:0px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-top:0px;padding-bottom:0px;border-inline-start-width:2px;-webkit-padding-start:var(--calcite-stepper-item-spacing-unit-l);padding-inline-start:var(--calcite-stepper-item-spacing-unit-l)}:host([layout=vertical]) .container .stepper-item-icon{-ms-flex-order:3;order:3;margin-top:1px;margin-bottom:0px;-webkit-padding-start:var(--calcite-stepper-item-spacing-unit-s);padding-inline-start:var(--calcite-stepper-item-spacing-unit-s);-webkit-margin-start:auto;margin-inline-start:auto}:host([layout=vertical]) .container .stepper-item-header{-webkit-padding-end:0px;padding-inline-end:0px}:host([layout=vertical]) .container .stepper-item-content{padding:0px}:host([layout=vertical][active]) .container .stepper-item-content{display:-ms-flexbox;display:flex}:host([layout=vertical][active]) .container .stepper-item-content ::slotted(:last-child){margin-bottom:var(--calcite-stepper-item-spacing-unit-l)}:host([layout=vertical][complete]) .container{border-color:rgba(0, 122, 194, 0.5)}:host([layout=vertical][complete]:hover:not([disabled]):not([active])) .container,:host([layout=vertical][complete]:focus:not([disabled]):not([active])) .container{border-color:var(--calcite-ui-brand)}:host([layout=vertical][error]) .container{border-color:var(--calcite-ui-danger)}:host([layout=vertical][active]) .container{border-color:var(--calcite-ui-brand)}:host([layout=vertical]:hover:not([disabled]):not([active])) .container,:host([layout=vertical]:focus:not([disabled]):not([active])) .container{border-color:rgba(0, 122, 194, 0.5)}:host([layout=vertical][error]:hover:not([disabled]):not([active])) .container,:host([layout=vertical][error]:focus:not([disabled]):not([active])) .container{border-color:var(--calcite-ui-danger-hover)}";
  240. const StepperItem = class {
  241. constructor(hostRef) {
  242. index.registerInstance(this, hostRef);
  243. this.calciteStepperItemKeyEvent = index.createEvent(this, "calciteStepperItemKeyEvent", 7);
  244. this.calciteStepperItemSelect = index.createEvent(this, "calciteStepperItemSelect", 7);
  245. this.calciteStepperItemRegister = index.createEvent(this, "calciteStepperItemRegister", 7);
  246. //--------------------------------------------------------------------------
  247. //
  248. // Public Properties
  249. //
  250. //--------------------------------------------------------------------------
  251. /** is the step active */
  252. this.active = false;
  253. /** has the step been completed */
  254. this.complete = false;
  255. /** does the step contain an error that needs to be resolved by the user */
  256. this.error = false;
  257. /** is the step disabled and not navigable to by a user */
  258. this.disabled = false;
  259. /** should the items display an icon based on status */
  260. /** @internal */
  261. this.icon = false;
  262. /** optionally display the step number next to the title and subtitle */
  263. /** @internal */
  264. this.numbered = false;
  265. /** the scale of the item */
  266. /** @internal */
  267. this.scale = "m";
  268. //--------------------------------------------------------------------------
  269. //
  270. // Private Methods
  271. //
  272. //--------------------------------------------------------------------------
  273. this.keyDownHandler = (e) => {
  274. if (!this.disabled && e.target === this.el) {
  275. switch (e.key) {
  276. case " ":
  277. case "Enter":
  278. this.emitRequestedItem();
  279. e.preventDefault();
  280. break;
  281. case "ArrowUp":
  282. case "ArrowDown":
  283. case "ArrowLeft":
  284. case "ArrowRight":
  285. case "Home":
  286. case "End":
  287. this.calciteStepperItemKeyEvent.emit({ item: e });
  288. e.preventDefault();
  289. break;
  290. }
  291. }
  292. };
  293. this.emitRequestedItem = () => {
  294. if (!this.disabled) {
  295. this.calciteStepperItemSelect.emit({
  296. position: this.itemPosition,
  297. content: this.itemContent
  298. });
  299. }
  300. };
  301. this.setItemContent = (event) => {
  302. this.itemPosition = this.getItemPosition();
  303. const itemContent = event.target.assignedNodes({ flatten: true });
  304. if (itemContent.length) {
  305. this.itemContent = itemContent;
  306. }
  307. this.registerStepperItem();
  308. if (this.active) {
  309. this.emitRequestedItem();
  310. }
  311. };
  312. }
  313. // watch for removal of disabled to register step
  314. disabledWatcher() {
  315. this.registerStepperItem();
  316. }
  317. //--------------------------------------------------------------------------
  318. //
  319. // Lifecycle
  320. //
  321. //--------------------------------------------------------------------------
  322. componentWillLoad() {
  323. this.icon = dom.getElementProp(this.el, "icon", false);
  324. this.numbered = dom.getElementProp(this.el, "numbered", false);
  325. this.layout = dom.getElementProp(this.el, "layout", false);
  326. this.scale = dom.getElementProp(this.el, "scale", "m");
  327. this.parentStepperEl = this.el.parentElement;
  328. }
  329. componentDidRender() {
  330. interactive.updateHostInteraction(this, true);
  331. }
  332. render() {
  333. return (index.h(index.Host, { "aria-expanded": dom.toAriaBoolean(this.active), onClick: this.emitRequestedItem, onKeyDown: this.keyDownHandler }, index.h("div", { class: "container" }, index.h("div", { class: "stepper-item-header" }, this.icon ? this.renderIcon() : null, this.numbered ? (index.h("div", { class: "stepper-item-number" }, this.getItemPosition() + 1, ".")) : null, index.h("div", { class: "stepper-item-header-text" }, index.h("span", { class: "stepper-item-title" }, this.itemTitle), index.h("span", { class: "stepper-item-subtitle" }, this.itemSubtitle))), index.h("div", { class: "stepper-item-content" }, index.h("slot", { onSlotchange: this.setItemContent })))));
  334. }
  335. //--------------------------------------------------------------------------
  336. //
  337. // Event Listeners
  338. //
  339. //--------------------------------------------------------------------------
  340. updateActiveItemOnChange(event) {
  341. if (event.target === this.parentStepperEl ||
  342. event.composedPath().includes(this.parentStepperEl)) {
  343. this.activePosition = event.detail.position;
  344. this.determineActiveItem();
  345. }
  346. }
  347. renderIcon() {
  348. const path = this.active
  349. ? "circleF"
  350. : this.error
  351. ? "exclamationMarkCircleF"
  352. : this.complete
  353. ? "checkCircleF"
  354. : "circle";
  355. return index.h("calcite-icon", { class: "stepper-item-icon", icon: path, scale: "s" });
  356. }
  357. determineActiveItem() {
  358. this.active = !this.disabled && this.itemPosition === this.activePosition;
  359. }
  360. registerStepperItem() {
  361. this.calciteStepperItemRegister.emit({
  362. position: this.itemPosition,
  363. content: this.itemContent
  364. });
  365. }
  366. getItemPosition() {
  367. return Array.prototype.indexOf.call(this.parentStepperEl.querySelectorAll("calcite-stepper-item"), this.el);
  368. }
  369. get el() { return index.getElement(this); }
  370. static get watchers() { return {
  371. "disabled": ["disabledWatcher"]
  372. }; }
  373. };
  374. StepperItem.style = stepperItemCss;
  375. exports.calcite_stepper = Stepper;
  376. exports.calcite_stepper_item = StepperItem;