calcite-stepper_2.entry.js 26 KB

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