calcite-stepper_2.entry.js 27 KB

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