calcite-stepper_2.cjs.entry.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const dom = require('./dom-2ec8c9ed.js');
  10. const interactive = require('./interactive-32293bca.js');
  11. const locale = require('./locale-678ce361.js');
  12. require('./resources-b5a5f8a7.js');
  13. require('./guid-f4f03a7a.js');
  14. require('./key-6a462411.js');
  15. require('./observers-5706326b.js');
  16. const stepperCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:flex;inline-size:100%;min-inline-size:-moz-fit-content;min-inline-size:fit-content;flex-direction:row;flex-wrap:wrap;align-items:stretch;justify-content:space-between}:host([layout=vertical]){flex:1 1 auto;flex-direction:column}:host([layout=horizontal]){display:grid;grid-template-areas:\"items\" \"content\"}";
  17. const Stepper = class {
  18. constructor(hostRef) {
  19. index.registerInstance(this, hostRef);
  20. this.calciteStepperItemChange = index.createEvent(this, "calciteStepperItemChange", 6);
  21. this.calciteInternalStepperItemChange = index.createEvent(this, "calciteInternalStepperItemChange", 6);
  22. //--------------------------------------------------------------------------
  23. //
  24. // Public Properties
  25. //
  26. //--------------------------------------------------------------------------
  27. /** When `true`, displays a status icon in the `calcite-stepper-item` heading. */
  28. this.icon = false;
  29. /** Defines the layout of the component. */
  30. this.layout = "horizontal";
  31. /** When `true`, displays the step number in the `calcite-stepper-item` heading. */
  32. this.numbered = false;
  33. /** Specifies the size of the component. */
  34. this.scale = "m";
  35. //--------------------------------------------------------------------------
  36. //
  37. // Private State/Props
  38. //
  39. //--------------------------------------------------------------------------
  40. this.itemMap = new Map();
  41. /** list of sorted Stepper items */
  42. this.items = [];
  43. /** list of enabled Stepper items */
  44. this.enabledItems = [];
  45. }
  46. //--------------------------------------------------------------------------
  47. //
  48. // Lifecycle
  49. //
  50. //--------------------------------------------------------------------------
  51. componentDidLoad() {
  52. // if no stepper items are set as active, default to the first one
  53. if (typeof this.currentPosition !== "number") {
  54. this.calciteInternalStepperItemChange.emit({
  55. position: 0
  56. });
  57. }
  58. }
  59. render() {
  60. return (index.h("slot", { onSlotchange: (event) => {
  61. const items = event.currentTarget
  62. .assignedElements()
  63. .filter((el) => (el === null || el === void 0 ? void 0 : el.tagName) === "CALCITE-STEPPER-ITEM");
  64. const spacing = Array(items.length).fill("1fr").join(" ");
  65. this.el.style.gridTemplateAreas = spacing;
  66. this.el.style.gridTemplateColumns = spacing;
  67. } }));
  68. }
  69. //--------------------------------------------------------------------------
  70. //
  71. // Event Listeners
  72. //
  73. //--------------------------------------------------------------------------
  74. calciteInternalStepperItemKeyEvent(event) {
  75. const item = event.detail.item;
  76. const itemToFocus = event.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. event.stopPropagation();
  106. }
  107. registerItem(event) {
  108. const item = event.target;
  109. const { content, position } = event.detail;
  110. this.itemMap.set(item, { position, content });
  111. this.items = this.sortItems();
  112. this.enabledItems = this.filterItems();
  113. event.stopPropagation();
  114. }
  115. updateItem(event) {
  116. const { position } = event.detail;
  117. if (typeof position === "number") {
  118. this.currentPosition = position;
  119. }
  120. this.calciteInternalStepperItemChange.emit({
  121. position
  122. });
  123. }
  124. handleUserRequestedStepperItemSelect(event) {
  125. const { position } = event.detail;
  126. this.calciteStepperItemChange.emit({
  127. position
  128. });
  129. }
  130. //--------------------------------------------------------------------------
  131. //
  132. // Public Methods
  133. //
  134. //--------------------------------------------------------------------------
  135. /** Set the next `calcite-stepper-item` as active. */
  136. async nextStep() {
  137. const enabledStepIndex = this.getEnabledStepIndex(this.currentPosition + 1, "next");
  138. if (typeof enabledStepIndex !== "number") {
  139. return;
  140. }
  141. this.updateStep(enabledStepIndex);
  142. }
  143. /** Set the previous `calcite-stepper-item` as active. */
  144. async prevStep() {
  145. const enabledStepIndex = this.getEnabledStepIndex(this.currentPosition - 1, "previous");
  146. if (typeof enabledStepIndex !== "number") {
  147. return;
  148. }
  149. this.updateStep(enabledStepIndex);
  150. }
  151. /**
  152. * Set a specified `calcite-stepper-item` as active.
  153. *
  154. * @param step
  155. */
  156. async goToStep(step) {
  157. const position = step - 1;
  158. if (this.currentPosition !== position) {
  159. this.updateStep(position);
  160. }
  161. }
  162. /** Set the first `calcite-stepper-item` as active. */
  163. async startStep() {
  164. const enabledStepIndex = this.getEnabledStepIndex(0, "next");
  165. if (typeof enabledStepIndex !== "number") {
  166. return;
  167. }
  168. this.updateStep(enabledStepIndex);
  169. }
  170. /** Set the last `calcite-stepper-item` as active. */
  171. async endStep() {
  172. const enabledStepIndex = this.getEnabledStepIndex(this.items.length - 1, "previous");
  173. if (typeof enabledStepIndex !== "number") {
  174. return;
  175. }
  176. this.updateStep(enabledStepIndex);
  177. }
  178. //--------------------------------------------------------------------------
  179. //
  180. // Private Methods
  181. //
  182. //--------------------------------------------------------------------------
  183. getEnabledStepIndex(startIndex, direction = "next") {
  184. var _a;
  185. const { items, currentPosition } = this;
  186. let newIndex = startIndex;
  187. while ((_a = items[newIndex]) === null || _a === void 0 ? void 0 : _a.disabled) {
  188. newIndex = newIndex + (direction === "previous" ? -1 : 1);
  189. }
  190. return newIndex !== currentPosition && newIndex < items.length && newIndex >= 0
  191. ? newIndex
  192. : null;
  193. }
  194. updateStep(position) {
  195. this.currentPosition = position;
  196. this.calciteInternalStepperItemChange.emit({
  197. position
  198. });
  199. }
  200. focusFirstItem() {
  201. const firstItem = this.enabledItems[0];
  202. dom.focusElement(firstItem);
  203. }
  204. focusLastItem() {
  205. const lastItem = this.enabledItems[this.enabledItems.length - 1];
  206. dom.focusElement(lastItem);
  207. }
  208. focusNextItem(el) {
  209. const index = this.itemIndex(el);
  210. const nextItem = this.enabledItems[index + 1] || this.enabledItems[0];
  211. dom.focusElement(nextItem);
  212. }
  213. focusPrevItem(el) {
  214. const index = this.itemIndex(el);
  215. const prevItem = this.enabledItems[index - 1] || this.enabledItems[this.enabledItems.length - 1];
  216. dom.focusElement(prevItem);
  217. }
  218. itemIndex(el) {
  219. return this.enabledItems.indexOf(el);
  220. }
  221. sortItems() {
  222. const { itemMap } = this;
  223. return Array.from(itemMap.keys()).sort((a, b) => itemMap.get(a).position - itemMap.get(b).position);
  224. }
  225. filterItems() {
  226. return this.items.filter((item) => !item.disabled);
  227. }
  228. get el() { return index.getElement(this); }
  229. };
  230. Stepper.style = stepperCss;
  231. const stepperItemCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([layout=horizontal][disabled]) .stepper-item-header,:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}: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;margin-inline-end:0.25rem}:host([scale=s]) .stepper-item-description{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;margin-inline-end:0.5rem}:host([scale=m]) .stepper-item-description{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;margin-inline-end:0.75rem}:host([scale=l]) .stepper-item-description{font-size:var(--calcite-font-size-0);line-height:1.25rem}:host{position:relative;display:flex;flex-grow:1;flex-direction:column;align-self:flex-start;margin-block-end:var(--calcite-stepper-item-spacing-unit-s)}:host .container{position:relative;display:flex;flex-grow:1;cursor:pointer;flex-direction:column;border-width:0px;border-block-start-width:2px;border-style:solid;border-color:var(--calcite-ui-border-3);color:var(--calcite-ui-text-3);text-decoration-line:none;outline:2px solid transparent;outline-offset:2px;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host{outline-color:transparent}:host(:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:2px}:host .stepper-item-header{display:flex;cursor:pointer;align-items:flex-start}:host .stepper-item-content,:host .stepper-item-header{transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);padding-block:var(--calcite-stepper-item-spacing-unit-l);padding-inline-end:var(--calcite-stepper-item-spacing-unit-m);text-align:start}:host .stepper-item-header *{display:inline-flex;align-items:center;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host .stepper-item-content{display:none;inline-size:100%;flex-direction:column;font-size:var(--calcite-font-size--2);line-height:1.375}:host .stepper-item-icon{margin-inline-end:var(--calcite-stepper-item-spacing-unit-m);margin-block-start:1px;display:inline-flex;block-size:0.75rem;flex-shrink:0;align-self:flex-start;color:var(--calcite-ui-text-3);opacity:var(--calcite-ui-opacity-disabled);transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host .stepper-item-header-text{flex-direction:column;text-align:initial;margin-inline-end:auto}:host .stepper-item-heading,:host .stepper-item-description{display:flex;inline-size:100%}:host .stepper-item-heading{margin-block-end:0.25rem;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2)}:host .stepper-item-description{color:var(--calcite-ui-text-3)}:host .stepper-item-number{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-3);transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);margin-inline-end:var(--calcite-stepper-item-spacing-unit-m)}: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-block-start-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([selected])) .container,:host(:focus:not([disabled]):not([selected])) .container{border-block-start-color:var(--calcite-ui-brand)}:host(:hover:not([disabled]):not([selected])) .container .stepper-item-heading,:host(:focus:not([disabled]):not([selected])) .container .stepper-item-heading{color:var(--calcite-ui-text-1)}:host(:hover:not([disabled]):not([selected])) .container .stepper-item-description,:host(:focus:not([disabled]):not([selected])) .container .stepper-item-description{color:var(--calcite-ui-text-2)}:host([error]:hover:not([disabled]):not([selected])) .container,:host([error]:focus:not([disabled]):not([selected])) .container{border-block-start-color:var(--calcite-ui-danger-hover)}:host([selected]) .container{border-block-start-color:var(--calcite-ui-brand)}:host([selected]) .container .stepper-item-heading{color:var(--calcite-ui-text-1)}:host([selected]) .container .stepper-item-description{color:var(--calcite-ui-text-2)}:host([selected]) .container .stepper-item-number{color:var(--calcite-ui-brand)}:host([selected]) .container .stepper-item-icon{color:var(--calcite-ui-brand);opacity:1}:host([selected]) .container .stepper-item-content{display:flex}:host([layout=vertical]) .container{margin-inline:0px;margin-block-start:0px;flex:1 1 auto;border-block-start-width:0px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-block:0px;border-inline-start-width:2px;padding-inline-start:var(--calcite-stepper-item-spacing-unit-l)}:host([layout=vertical]) .container .stepper-item-icon{order:3;margin-block:1px 0px;padding-inline-start:var(--calcite-stepper-item-spacing-unit-s);margin-inline-start:auto}:host([layout=vertical]) .container .stepper-item-header{padding-inline-end:0px}:host([layout=vertical]) .container .stepper-item-content{padding:0px}:host([layout=vertical][complete]) .container{border-color:rgba(0, 122, 194, 0.5)}:host([layout=vertical][complete]:hover:not([disabled]):not([selected])) .container,:host([layout=vertical][complete]:focus:not([disabled]):not([selected])) .container{border-color:var(--calcite-ui-brand)}:host([layout=vertical][error]) .container{border-color:var(--calcite-ui-danger)}:host([layout=vertical][selected]) .container{border-color:var(--calcite-ui-brand)}:host([layout=vertical][selected]) .container .stepper-item-content ::slotted(:last-child){margin-block-end:var(--calcite-stepper-item-spacing-unit-l)}:host([layout=vertical]:hover:not([disabled]):not([selected])) .container,:host([layout=vertical]:focus:not([disabled]):not([selected])) .container{border-color:rgba(0, 122, 194, 0.5)}:host([layout=vertical][error]:hover:not([disabled]):not([selected])) .container,:host([layout=vertical][error]:focus:not([disabled]):not([selected])) .container{border-color:var(--calcite-ui-danger-hover)}:host([layout=horizontal]){display:contents}:host([layout=horizontal]) .container{display:contents}:host([layout=horizontal]) .stepper-item-header{border-width:0px;border-block-start-width:2px;border-style:solid;border-color:var(--calcite-ui-border-3);outline-color:transparent;grid-row:items;margin-inline-end:0.5rem;margin-block-end:var(--calcite-stepper-item-spacing-unit-s)}:host([layout=horizontal]) .stepper-item-header:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}:host([layout=horizontal]) .stepper-item-content{cursor:auto;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);padding-block:0;padding-inline-end:var(--calcite-stepper-item-spacing-unit-m);text-align:start}:host([layout=horizontal][selected]) .stepper-item-content{grid-area:2/1/2/-1}:host([layout=horizontal][scale=s]) .stepper-item-header{margin-inline-end:0.25rem;margin-block-end:var(--calcite-stepper-item-spacing-unit-s)}:host([layout=horizontal][scale=l]) .stepper-item-header{margin-inline-end:0.75rem;margin-block-end:var(--calcite-stepper-item-spacing-unit-s)}:host([layout=horizontal][complete]) .stepper-item-header{border-color:rgba(0, 122, 194, 0.5)}:host([layout=horizontal][complete]:hover:not([disabled]):not([selected])) .stepper-item-header,:host([layout=horizontal][complete]:focus:not([disabled]):not([selected])) .stepper-item-header{border-color:var(--calcite-ui-brand)}:host([layout=horizontal][error]) .stepper-item-header{border-color:var(--calcite-ui-danger)}:host([layout=horizontal][selected]) .stepper-item-header{border-color:var(--calcite-ui-brand)}:host([layout=horizontal]:hover:not([disabled]):not([selected])) .stepper-item-header,:host([layout=horizontal]:focus:not([disabled]):not([selected])) .stepper-item-header{border-color:rgba(0, 122, 194, 0.5)}:host([layout=horizontal][error]:hover:not([disabled]):not([selected])) .stepper-item-header,:host([layout=horizontal][error]:focus:not([disabled]):not([selected])) .stepper-item-header{border-color:var(--calcite-ui-danger-hover)}@media (forced-colors: active){:host .container{outline-width:0;outline-offset:0}:host(:focus),:host(:focus-visible){outline-color:canvasText}:host([selected]) .container{border-block-start-color:highlight}:host([selected]) .container .stepper-item-number{color:highlight}:host([selected]) .container .stepper-item-icon{color:highlight}:host([layout=vertical][selected]) .container{border-color:highlight}}";
  232. const StepperItem = class {
  233. constructor(hostRef) {
  234. index.registerInstance(this, hostRef);
  235. this.calciteInternalStepperItemKeyEvent = index.createEvent(this, "calciteInternalStepperItemKeyEvent", 6);
  236. this.calciteInternalStepperItemSelect = index.createEvent(this, "calciteInternalStepperItemSelect", 6);
  237. this.calciteInternalUserRequestedStepperItemSelect = index.createEvent(this, "calciteInternalUserRequestedStepperItemSelect", 6);
  238. this.calciteInternalStepperItemRegister = index.createEvent(this, "calciteInternalStepperItemRegister", 6);
  239. //--------------------------------------------------------------------------
  240. //
  241. // Public Properties
  242. //
  243. //--------------------------------------------------------------------------
  244. /**
  245. * When `true`, the component is selected.
  246. *
  247. * @deprecated Use `selected` instead.
  248. */
  249. this.active = false;
  250. /**
  251. * When `true`, the component is selected.
  252. */
  253. this.selected = false;
  254. /** When `true`, the step has been completed. */
  255. this.complete = false;
  256. /** When `true`, the component contains an error that requires resolution from the user. */
  257. this.error = false;
  258. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  259. this.disabled = false;
  260. // internal props inherited from wrapping calcite-stepper
  261. /** Defines the layout of the component. */
  262. /** @internal */
  263. this.layout = "horizontal";
  264. /** When `true`, displays a status icon in the component's heading. */
  265. /** @internal */
  266. this.icon = false;
  267. /** When `true`, displays the step number in the component's heading. */
  268. /** @internal */
  269. this.numbered = false;
  270. /** Specifies the size of the component. */
  271. /** @internal */
  272. this.scale = "m";
  273. //--------------------------------------------------------------------------
  274. //
  275. // Internal State/Props
  276. //
  277. //--------------------------------------------------------------------------
  278. this.effectiveLocale = "";
  279. //--------------------------------------------------------------------------
  280. //
  281. // Private Methods
  282. //
  283. //--------------------------------------------------------------------------
  284. this.keyDownHandler = (event) => {
  285. if (!this.disabled && event.target === this.el) {
  286. switch (event.key) {
  287. case " ":
  288. case "Enter":
  289. this.emitUserRequestedItem();
  290. event.preventDefault();
  291. break;
  292. case "ArrowUp":
  293. case "ArrowDown":
  294. case "ArrowLeft":
  295. case "ArrowRight":
  296. case "Home":
  297. case "End":
  298. this.calciteInternalStepperItemKeyEvent.emit({ item: event });
  299. event.preventDefault();
  300. break;
  301. }
  302. }
  303. };
  304. this.handleItemClick = (event) => {
  305. if (this.layout === "horizontal" &&
  306. event
  307. .composedPath()
  308. .some((el) => { var _a; return (_a = el.classList) === null || _a === void 0 ? void 0 : _a.contains("stepper-item-content"); })) {
  309. return;
  310. }
  311. this.emitUserRequestedItem();
  312. };
  313. this.emitUserRequestedItem = () => {
  314. this.emitRequestedItem();
  315. if (!this.disabled) {
  316. const position = this.itemPosition;
  317. this.calciteInternalUserRequestedStepperItemSelect.emit({
  318. position
  319. });
  320. }
  321. };
  322. this.emitRequestedItem = () => {
  323. if (!this.disabled) {
  324. const position = this.itemPosition;
  325. this.calciteInternalStepperItemSelect.emit({
  326. position
  327. });
  328. }
  329. };
  330. }
  331. activeHandler(value) {
  332. this.selected = value;
  333. }
  334. selectedHandler(value) {
  335. this.active = value;
  336. if (this.selected) {
  337. this.emitRequestedItem();
  338. }
  339. }
  340. // watch for removal of disabled to register step
  341. disabledWatcher() {
  342. this.registerStepperItem();
  343. }
  344. effectiveLocaleWatcher(locale$1) {
  345. var _a;
  346. locale.numberStringFormatter.numberFormatOptions = {
  347. locale: locale$1,
  348. numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
  349. useGrouping: false
  350. };
  351. }
  352. //--------------------------------------------------------------------------
  353. //
  354. // Lifecycle
  355. //
  356. //--------------------------------------------------------------------------
  357. connectedCallback() {
  358. locale.connectLocalized(this);
  359. const { selected, active } = this;
  360. if (selected) {
  361. this.active = selected;
  362. }
  363. else if (active) {
  364. this.selected = active;
  365. }
  366. }
  367. componentWillLoad() {
  368. var _a;
  369. this.icon = dom.getElementProp(this.el, "icon", false);
  370. this.numbered = dom.getElementProp(this.el, "numbered", false);
  371. this.layout = dom.getElementProp(this.el, "layout", false);
  372. this.scale = dom.getElementProp(this.el, "scale", "m");
  373. this.parentStepperEl = this.el.parentElement;
  374. this.itemPosition = this.getItemPosition();
  375. this.registerStepperItem();
  376. if (this.selected) {
  377. this.emitRequestedItem();
  378. }
  379. locale.numberStringFormatter.numberFormatOptions = {
  380. locale: this.effectiveLocale,
  381. numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
  382. useGrouping: false
  383. };
  384. }
  385. componentDidRender() {
  386. interactive.updateHostInteraction(this, true);
  387. }
  388. disconnectedCallback() {
  389. locale.disconnectLocalized(this);
  390. }
  391. render() {
  392. return (index.h(index.Host, { "aria-expanded": dom.toAriaBoolean(this.active), onClick: this.handleItemClick, onKeyDown: this.keyDownHandler }, index.h("div", { class: "container" }, index.h("div", { class: "stepper-item-header", ref: (el) => (this.headerEl = el), tabIndex:
  393. /* additional tab index logic needed because of display: contents */
  394. this.layout === "horizontal" && !this.disabled ? 0 : null }, this.icon ? this.renderIcon() : null, this.numbered ? (index.h("div", { class: "stepper-item-number" }, locale.numberStringFormatter.numberFormatter.format(this.itemPosition + 1), ".")) : null, index.h("div", { class: "stepper-item-header-text" }, index.h("span", { class: "stepper-item-heading" }, this.heading || this.itemTitle), index.h("span", { class: "stepper-item-description" }, this.description || this.itemSubtitle))), index.h("div", { class: "stepper-item-content" }, index.h("slot", null)))));
  395. }
  396. //--------------------------------------------------------------------------
  397. //
  398. // Event Listeners
  399. //
  400. //--------------------------------------------------------------------------
  401. updateActiveItemOnChange(event) {
  402. if (event.target === this.parentStepperEl ||
  403. event.composedPath().includes(this.parentStepperEl)) {
  404. this.selectedPosition = event.detail.position;
  405. this.determineSelectedItem();
  406. }
  407. }
  408. //--------------------------------------------------------------------------
  409. //
  410. // Public Methods
  411. //
  412. //--------------------------------------------------------------------------
  413. async setFocus() {
  414. var _a;
  415. (_a = (this.layout === "vertical" ? this.el : this.headerEl)) === null || _a === void 0 ? void 0 : _a.focus();
  416. }
  417. renderIcon() {
  418. const path = this.selected
  419. ? "circleF"
  420. : this.error
  421. ? "exclamationMarkCircleF"
  422. : this.complete
  423. ? "checkCircleF"
  424. : "circle";
  425. return index.h("calcite-icon", { class: "stepper-item-icon", icon: path, scale: "s" });
  426. }
  427. determineSelectedItem() {
  428. this.selected = !this.disabled && this.itemPosition === this.selectedPosition;
  429. }
  430. registerStepperItem() {
  431. this.calciteInternalStepperItemRegister.emit({
  432. position: this.itemPosition
  433. });
  434. }
  435. getItemPosition() {
  436. var _a;
  437. return Array.from((_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.querySelectorAll("calcite-stepper-item")).indexOf(this.el);
  438. }
  439. get el() { return index.getElement(this); }
  440. static get watchers() { return {
  441. "active": ["activeHandler"],
  442. "selected": ["selectedHandler"],
  443. "disabled": ["disabledWatcher"],
  444. "effectiveLocale": ["effectiveLocaleWatcher"]
  445. }; }
  446. };
  447. StepperItem.style = stepperItemCss;
  448. exports.calcite_stepper = Stepper;
  449. exports.calcite_stepper_item = StepperItem;