calcite-stepper-item.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
  7. import { g as getElementProp, t as toAriaBoolean } from './dom.js';
  8. import { u as updateHostInteraction } from './interactive.js';
  9. import { d as defineCustomElement$2 } from './icon.js';
  10. 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)}";
  11. const StepperItem = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  12. constructor() {
  13. super();
  14. this.__registerHost();
  15. this.__attachShadow();
  16. this.calciteStepperItemKeyEvent = createEvent(this, "calciteStepperItemKeyEvent", 7);
  17. this.calciteStepperItemSelect = createEvent(this, "calciteStepperItemSelect", 7);
  18. this.calciteStepperItemRegister = createEvent(this, "calciteStepperItemRegister", 7);
  19. //--------------------------------------------------------------------------
  20. //
  21. // Public Properties
  22. //
  23. //--------------------------------------------------------------------------
  24. /** is the step active */
  25. this.active = false;
  26. /** has the step been completed */
  27. this.complete = false;
  28. /** does the step contain an error that needs to be resolved by the user */
  29. this.error = false;
  30. /** is the step disabled and not navigable to by a user */
  31. this.disabled = false;
  32. /** should the items display an icon based on status */
  33. /** @internal */
  34. this.icon = false;
  35. /** optionally display the step number next to the title and subtitle */
  36. /** @internal */
  37. this.numbered = false;
  38. /** the scale of the item */
  39. /** @internal */
  40. this.scale = "m";
  41. //--------------------------------------------------------------------------
  42. //
  43. // Private Methods
  44. //
  45. //--------------------------------------------------------------------------
  46. this.keyDownHandler = (e) => {
  47. if (!this.disabled && e.target === this.el) {
  48. switch (e.key) {
  49. case " ":
  50. case "Enter":
  51. this.emitRequestedItem();
  52. e.preventDefault();
  53. break;
  54. case "ArrowUp":
  55. case "ArrowDown":
  56. case "ArrowLeft":
  57. case "ArrowRight":
  58. case "Home":
  59. case "End":
  60. this.calciteStepperItemKeyEvent.emit({ item: e });
  61. e.preventDefault();
  62. break;
  63. }
  64. }
  65. };
  66. this.emitRequestedItem = () => {
  67. if (!this.disabled) {
  68. this.calciteStepperItemSelect.emit({
  69. position: this.itemPosition,
  70. content: this.itemContent
  71. });
  72. }
  73. };
  74. this.setItemContent = (event) => {
  75. this.itemPosition = this.getItemPosition();
  76. const itemContent = event.target.assignedNodes({ flatten: true });
  77. if (itemContent.length) {
  78. this.itemContent = itemContent;
  79. }
  80. this.registerStepperItem();
  81. if (this.active) {
  82. this.emitRequestedItem();
  83. }
  84. };
  85. }
  86. // watch for removal of disabled to register step
  87. disabledWatcher() {
  88. this.registerStepperItem();
  89. }
  90. //--------------------------------------------------------------------------
  91. //
  92. // Lifecycle
  93. //
  94. //--------------------------------------------------------------------------
  95. componentWillLoad() {
  96. this.icon = getElementProp(this.el, "icon", false);
  97. this.numbered = getElementProp(this.el, "numbered", false);
  98. this.layout = getElementProp(this.el, "layout", false);
  99. this.scale = getElementProp(this.el, "scale", "m");
  100. this.parentStepperEl = this.el.parentElement;
  101. }
  102. componentDidRender() {
  103. updateHostInteraction(this, true);
  104. }
  105. render() {
  106. 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 })))));
  107. }
  108. //--------------------------------------------------------------------------
  109. //
  110. // Event Listeners
  111. //
  112. //--------------------------------------------------------------------------
  113. updateActiveItemOnChange(event) {
  114. if (event.target === this.parentStepperEl ||
  115. event.composedPath().includes(this.parentStepperEl)) {
  116. this.activePosition = event.detail.position;
  117. this.determineActiveItem();
  118. }
  119. }
  120. renderIcon() {
  121. const path = this.active
  122. ? "circleF"
  123. : this.error
  124. ? "exclamationMarkCircleF"
  125. : this.complete
  126. ? "checkCircleF"
  127. : "circle";
  128. return h("calcite-icon", { class: "stepper-item-icon", icon: path, scale: "s" });
  129. }
  130. determineActiveItem() {
  131. this.active = !this.disabled && this.itemPosition === this.activePosition;
  132. }
  133. registerStepperItem() {
  134. this.calciteStepperItemRegister.emit({
  135. position: this.itemPosition,
  136. content: this.itemContent
  137. });
  138. }
  139. getItemPosition() {
  140. return Array.prototype.indexOf.call(this.parentStepperEl.querySelectorAll("calcite-stepper-item"), this.el);
  141. }
  142. get el() { return this; }
  143. static get watchers() { return {
  144. "disabled": ["disabledWatcher"]
  145. }; }
  146. static get style() { return stepperItemCss; }
  147. }, [1, "calcite-stepper-item", {
  148. "active": [1540],
  149. "complete": [516],
  150. "error": [4],
  151. "disabled": [516],
  152. "itemTitle": [1, "item-title"],
  153. "itemSubtitle": [1, "item-subtitle"],
  154. "layout": [1537],
  155. "icon": [1028],
  156. "numbered": [1028],
  157. "scale": [1537]
  158. }, [[16, "calciteStepperItemChange", "updateActiveItemOnChange"]]]);
  159. function defineCustomElement$1() {
  160. if (typeof customElements === "undefined") {
  161. return;
  162. }
  163. const components = ["calcite-stepper-item", "calcite-icon"];
  164. components.forEach(tagName => { switch (tagName) {
  165. case "calcite-stepper-item":
  166. if (!customElements.get(tagName)) {
  167. customElements.define(tagName, StepperItem);
  168. }
  169. break;
  170. case "calcite-icon":
  171. if (!customElements.get(tagName)) {
  172. defineCustomElement$2();
  173. }
  174. break;
  175. } });
  176. }
  177. defineCustomElement$1();
  178. const CalciteStepperItem = StepperItem;
  179. const defineCustomElement = defineCustomElement$1;
  180. export { CalciteStepperItem, defineCustomElement };