calcite-stepper-item.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
  7. import { g as getElementProp, t as toAriaBoolean } from './dom.js';
  8. import { u as updateHostInteraction } from './interactive.js';
  9. import { n as numberStringFormatter, c as connectLocalized, d as disconnectLocalized } from './locale.js';
  10. import { d as defineCustomElement$2 } from './icon.js';
  11. 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}}";
  12. const StepperItem = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  13. constructor() {
  14. super();
  15. this.__registerHost();
  16. this.__attachShadow();
  17. this.calciteInternalStepperItemKeyEvent = createEvent(this, "calciteInternalStepperItemKeyEvent", 6);
  18. this.calciteInternalStepperItemSelect = createEvent(this, "calciteInternalStepperItemSelect", 6);
  19. this.calciteInternalUserRequestedStepperItemSelect = createEvent(this, "calciteInternalUserRequestedStepperItemSelect", 6);
  20. this.calciteInternalStepperItemRegister = createEvent(this, "calciteInternalStepperItemRegister", 6);
  21. //--------------------------------------------------------------------------
  22. //
  23. // Public Properties
  24. //
  25. //--------------------------------------------------------------------------
  26. /**
  27. * When `true`, the component is selected.
  28. *
  29. * @deprecated Use `selected` instead.
  30. */
  31. this.active = false;
  32. /**
  33. * When `true`, the component is selected.
  34. */
  35. this.selected = false;
  36. /** When `true`, the step has been completed. */
  37. this.complete = false;
  38. /** When `true`, the component contains an error that requires resolution from the user. */
  39. this.error = false;
  40. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  41. this.disabled = false;
  42. // internal props inherited from wrapping calcite-stepper
  43. /** Defines the layout of the component. */
  44. /** @internal */
  45. this.layout = "horizontal";
  46. /** When `true`, displays a status icon in the component's heading. */
  47. /** @internal */
  48. this.icon = false;
  49. /** When `true`, displays the step number in the component's heading. */
  50. /** @internal */
  51. this.numbered = false;
  52. /** Specifies the size of the component. */
  53. /** @internal */
  54. this.scale = "m";
  55. //--------------------------------------------------------------------------
  56. //
  57. // Internal State/Props
  58. //
  59. //--------------------------------------------------------------------------
  60. this.effectiveLocale = "";
  61. //--------------------------------------------------------------------------
  62. //
  63. // Private Methods
  64. //
  65. //--------------------------------------------------------------------------
  66. this.keyDownHandler = (event) => {
  67. if (!this.disabled && event.target === this.el) {
  68. switch (event.key) {
  69. case " ":
  70. case "Enter":
  71. this.emitUserRequestedItem();
  72. event.preventDefault();
  73. break;
  74. case "ArrowUp":
  75. case "ArrowDown":
  76. case "ArrowLeft":
  77. case "ArrowRight":
  78. case "Home":
  79. case "End":
  80. this.calciteInternalStepperItemKeyEvent.emit({ item: event });
  81. event.preventDefault();
  82. break;
  83. }
  84. }
  85. };
  86. this.handleItemClick = (event) => {
  87. if (this.layout === "horizontal" &&
  88. event
  89. .composedPath()
  90. .some((el) => { var _a; return (_a = el.classList) === null || _a === void 0 ? void 0 : _a.contains("stepper-item-content"); })) {
  91. return;
  92. }
  93. this.emitUserRequestedItem();
  94. };
  95. this.emitUserRequestedItem = () => {
  96. this.emitRequestedItem();
  97. if (!this.disabled) {
  98. const position = this.itemPosition;
  99. this.calciteInternalUserRequestedStepperItemSelect.emit({
  100. position
  101. });
  102. }
  103. };
  104. this.emitRequestedItem = () => {
  105. if (!this.disabled) {
  106. const position = this.itemPosition;
  107. this.calciteInternalStepperItemSelect.emit({
  108. position
  109. });
  110. }
  111. };
  112. }
  113. activeHandler(value) {
  114. this.selected = value;
  115. }
  116. selectedHandler(value) {
  117. this.active = value;
  118. if (this.selected) {
  119. this.emitRequestedItem();
  120. }
  121. }
  122. // watch for removal of disabled to register step
  123. disabledWatcher() {
  124. this.registerStepperItem();
  125. }
  126. effectiveLocaleWatcher(locale) {
  127. var _a;
  128. numberStringFormatter.numberFormatOptions = {
  129. locale,
  130. numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
  131. useGrouping: false
  132. };
  133. }
  134. //--------------------------------------------------------------------------
  135. //
  136. // Lifecycle
  137. //
  138. //--------------------------------------------------------------------------
  139. connectedCallback() {
  140. connectLocalized(this);
  141. const { selected, active } = this;
  142. if (selected) {
  143. this.active = selected;
  144. }
  145. else if (active) {
  146. this.selected = active;
  147. }
  148. }
  149. componentWillLoad() {
  150. var _a;
  151. this.icon = getElementProp(this.el, "icon", false);
  152. this.numbered = getElementProp(this.el, "numbered", false);
  153. this.layout = getElementProp(this.el, "layout", false);
  154. this.scale = getElementProp(this.el, "scale", "m");
  155. this.parentStepperEl = this.el.parentElement;
  156. this.itemPosition = this.getItemPosition();
  157. this.registerStepperItem();
  158. if (this.selected) {
  159. this.emitRequestedItem();
  160. }
  161. numberStringFormatter.numberFormatOptions = {
  162. locale: this.effectiveLocale,
  163. numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
  164. useGrouping: false
  165. };
  166. }
  167. componentDidRender() {
  168. updateHostInteraction(this, true);
  169. }
  170. disconnectedCallback() {
  171. disconnectLocalized(this);
  172. }
  173. render() {
  174. 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:
  175. /* additional tab index logic needed because of display: contents */
  176. 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)))));
  177. }
  178. //--------------------------------------------------------------------------
  179. //
  180. // Event Listeners
  181. //
  182. //--------------------------------------------------------------------------
  183. updateActiveItemOnChange(event) {
  184. if (event.target === this.parentStepperEl ||
  185. event.composedPath().includes(this.parentStepperEl)) {
  186. this.selectedPosition = event.detail.position;
  187. this.determineSelectedItem();
  188. }
  189. }
  190. //--------------------------------------------------------------------------
  191. //
  192. // Public Methods
  193. //
  194. //--------------------------------------------------------------------------
  195. async setFocus() {
  196. var _a;
  197. (_a = (this.layout === "vertical" ? this.el : this.headerEl)) === null || _a === void 0 ? void 0 : _a.focus();
  198. }
  199. renderIcon() {
  200. const path = this.selected
  201. ? "circleF"
  202. : this.error
  203. ? "exclamationMarkCircleF"
  204. : this.complete
  205. ? "checkCircleF"
  206. : "circle";
  207. return h("calcite-icon", { class: "stepper-item-icon", icon: path, scale: "s" });
  208. }
  209. determineSelectedItem() {
  210. this.selected = !this.disabled && this.itemPosition === this.selectedPosition;
  211. }
  212. registerStepperItem() {
  213. this.calciteInternalStepperItemRegister.emit({
  214. position: this.itemPosition
  215. });
  216. }
  217. getItemPosition() {
  218. var _a;
  219. return Array.from((_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.querySelectorAll("calcite-stepper-item")).indexOf(this.el);
  220. }
  221. get el() { return this; }
  222. static get watchers() { return {
  223. "active": ["activeHandler"],
  224. "selected": ["selectedHandler"],
  225. "disabled": ["disabledWatcher"],
  226. "effectiveLocale": ["effectiveLocaleWatcher"]
  227. }; }
  228. static get style() { return stepperItemCss; }
  229. }, [1, "calcite-stepper-item", {
  230. "active": [1540],
  231. "selected": [1540],
  232. "complete": [516],
  233. "error": [516],
  234. "disabled": [516],
  235. "itemTitle": [1, "item-title"],
  236. "heading": [1],
  237. "itemSubtitle": [1, "item-subtitle"],
  238. "description": [1],
  239. "layout": [1537],
  240. "icon": [1028],
  241. "numbered": [1028],
  242. "scale": [1537],
  243. "effectiveLocale": [32],
  244. "setFocus": [64]
  245. }, [[16, "calciteInternalStepperItemChange", "updateActiveItemOnChange"]]]);
  246. function defineCustomElement$1() {
  247. if (typeof customElements === "undefined") {
  248. return;
  249. }
  250. const components = ["calcite-stepper-item", "calcite-icon"];
  251. components.forEach(tagName => { switch (tagName) {
  252. case "calcite-stepper-item":
  253. if (!customElements.get(tagName)) {
  254. customElements.define(tagName, StepperItem);
  255. }
  256. break;
  257. case "calcite-icon":
  258. if (!customElements.get(tagName)) {
  259. defineCustomElement$2();
  260. }
  261. break;
  262. } });
  263. }
  264. defineCustomElement$1();
  265. const CalciteStepperItem = StepperItem;
  266. const defineCustomElement = defineCustomElement$1;
  267. export { CalciteStepperItem, defineCustomElement };