123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import { h, Host } from "@stencil/core";
- import { getElementProp, toAriaBoolean } from "../../utils/dom";
- import { updateHostInteraction } from "../../utils/interactive";
- import { numberStringFormatter, disconnectLocalized, connectLocalized } from "../../utils/locale";
- /**
- * @slot - A slot for adding custom content.
- */
- export class StepperItem {
- constructor() {
- //--------------------------------------------------------------------------
- //
- // Public Properties
- //
- //--------------------------------------------------------------------------
- /**
- * When `true`, the component is selected.
- *
- * @deprecated Use `selected` instead.
- */
- this.active = false;
- /**
- * When `true`, the component is selected.
- */
- this.selected = false;
- /** When `true`, the step has been completed. */
- this.complete = false;
- /** When `true`, the component contains an error that requires resolution from the user. */
- this.error = false;
- /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
- this.disabled = false;
- // internal props inherited from wrapping calcite-stepper
- /** Defines the layout of the component. */
- /** @internal */
- this.layout = "horizontal";
- /** When `true`, displays a status icon in the component's heading. */
- /** @internal */
- this.icon = false;
- /** When `true`, displays the step number in the component's heading. */
- /** @internal */
- this.numbered = false;
- /** Specifies the size of the component. */
- /** @internal */
- this.scale = "m";
- //--------------------------------------------------------------------------
- //
- // Internal State/Props
- //
- //--------------------------------------------------------------------------
- this.effectiveLocale = "";
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- this.keyDownHandler = (event) => {
- if (!this.disabled && event.target === this.el) {
- switch (event.key) {
- case " ":
- case "Enter":
- this.emitUserRequestedItem();
- event.preventDefault();
- break;
- case "ArrowUp":
- case "ArrowDown":
- case "ArrowLeft":
- case "ArrowRight":
- case "Home":
- case "End":
- this.calciteInternalStepperItemKeyEvent.emit({ item: event });
- event.preventDefault();
- break;
- }
- }
- };
- this.handleItemClick = (event) => {
- if (this.layout === "horizontal" &&
- event
- .composedPath()
- .some((el) => { var _a; return (_a = el.classList) === null || _a === void 0 ? void 0 : _a.contains("stepper-item-content"); })) {
- return;
- }
- this.emitUserRequestedItem();
- };
- this.emitUserRequestedItem = () => {
- this.emitRequestedItem();
- if (!this.disabled) {
- const position = this.itemPosition;
- this.calciteInternalUserRequestedStepperItemSelect.emit({
- position
- });
- }
- };
- this.emitRequestedItem = () => {
- if (!this.disabled) {
- const position = this.itemPosition;
- this.calciteInternalStepperItemSelect.emit({
- position
- });
- }
- };
- }
- activeHandler(value) {
- this.selected = value;
- }
- selectedHandler(value) {
- this.active = value;
- if (this.selected) {
- this.emitRequestedItem();
- }
- }
- // watch for removal of disabled to register step
- disabledWatcher() {
- this.registerStepperItem();
- }
- effectiveLocaleWatcher(locale) {
- var _a;
- numberStringFormatter.numberFormatOptions = {
- locale,
- numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
- useGrouping: false
- };
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- connectLocalized(this);
- const { selected, active } = this;
- if (selected) {
- this.active = selected;
- }
- else if (active) {
- this.selected = active;
- }
- }
- componentWillLoad() {
- var _a;
- this.icon = getElementProp(this.el, "icon", false);
- this.numbered = getElementProp(this.el, "numbered", false);
- this.layout = getElementProp(this.el, "layout", false);
- this.scale = getElementProp(this.el, "scale", "m");
- this.parentStepperEl = this.el.parentElement;
- this.itemPosition = this.getItemPosition();
- this.registerStepperItem();
- if (this.selected) {
- this.emitRequestedItem();
- }
- numberStringFormatter.numberFormatOptions = {
- locale: this.effectiveLocale,
- numberingSystem: (_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.numberingSystem,
- useGrouping: false
- };
- }
- componentDidRender() {
- updateHostInteraction(this, true);
- }
- disconnectedCallback() {
- disconnectLocalized(this);
- }
- render() {
- 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:
- /* additional tab index logic needed because of display: contents */
- 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)))));
- }
- //--------------------------------------------------------------------------
- //
- // Event Listeners
- //
- //--------------------------------------------------------------------------
- updateActiveItemOnChange(event) {
- if (event.target === this.parentStepperEl ||
- event.composedPath().includes(this.parentStepperEl)) {
- this.selectedPosition = event.detail.position;
- this.determineSelectedItem();
- }
- }
- //--------------------------------------------------------------------------
- //
- // Public Methods
- //
- //--------------------------------------------------------------------------
- async setFocus() {
- var _a;
- (_a = (this.layout === "vertical" ? this.el : this.headerEl)) === null || _a === void 0 ? void 0 : _a.focus();
- }
- renderIcon() {
- const path = this.selected
- ? "circleF"
- : this.error
- ? "exclamationMarkCircleF"
- : this.complete
- ? "checkCircleF"
- : "circle";
- return h("calcite-icon", { class: "stepper-item-icon", icon: path, scale: "s" });
- }
- determineSelectedItem() {
- this.selected = !this.disabled && this.itemPosition === this.selectedPosition;
- }
- registerStepperItem() {
- this.calciteInternalStepperItemRegister.emit({
- position: this.itemPosition
- });
- }
- getItemPosition() {
- var _a;
- return Array.from((_a = this.parentStepperEl) === null || _a === void 0 ? void 0 : _a.querySelectorAll("calcite-stepper-item")).indexOf(this.el);
- }
- static get is() { return "calcite-stepper-item"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() {
- return {
- "$": ["stepper-item.scss"]
- };
- }
- static get styleUrls() {
- return {
- "$": ["stepper-item.css"]
- };
- }
- static get properties() {
- return {
- "active": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "Use `selected` instead."
- }],
- "text": "When `true`, the component is selected."
- },
- "attribute": "active",
- "reflect": true,
- "defaultValue": "false"
- },
- "selected": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component is selected."
- },
- "attribute": "selected",
- "reflect": true,
- "defaultValue": "false"
- },
- "complete": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the step has been completed."
- },
- "attribute": "complete",
- "reflect": true,
- "defaultValue": "false"
- },
- "error": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component contains an error that requires resolution from the user."
- },
- "attribute": "error",
- "reflect": true,
- "defaultValue": "false"
- },
- "disabled": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, interaction is prevented and the component is displayed with lower opacity."
- },
- "attribute": "disabled",
- "reflect": true,
- "defaultValue": "false"
- },
- "itemTitle": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "use `heading` instead."
- }],
- "text": "The component header text."
- },
- "attribute": "item-title",
- "reflect": false
- },
- "heading": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "The component header text."
- },
- "attribute": "heading",
- "reflect": false
- },
- "itemSubtitle": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "use `description` instead."
- }],
- "text": "A description for the component. Displays below the header text."
- },
- "attribute": "item-subtitle",
- "reflect": false
- },
- "description": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "A description for the component. Displays below the header text."
- },
- "attribute": "description",
- "reflect": false
- },
- "layout": {
- "type": "string",
- "mutable": true,
- "complexType": {
- "original": "Extract<\"horizontal\" | \"vertical\", Layout>",
- "resolved": "\"horizontal\" | \"vertical\"",
- "references": {
- "Extract": {
- "location": "global"
- },
- "Layout": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "attribute": "layout",
- "reflect": true,
- "defaultValue": "\"horizontal\""
- },
- "icon": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "attribute": "icon",
- "reflect": false,
- "defaultValue": "false"
- },
- "numbered": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "attribute": "numbered",
- "reflect": false,
- "defaultValue": "false"
- },
- "scale": {
- "type": "string",
- "mutable": true,
- "complexType": {
- "original": "Scale",
- "resolved": "\"l\" | \"m\" | \"s\"",
- "references": {
- "Scale": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "attribute": "scale",
- "reflect": true,
- "defaultValue": "\"m\""
- }
- };
- }
- static get states() {
- return {
- "effectiveLocale": {}
- };
- }
- static get events() {
- return [{
- "method": "calciteInternalStepperItemKeyEvent",
- "name": "calciteInternalStepperItemKeyEvent",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "complexType": {
- "original": "StepperItemKeyEventDetail",
- "resolved": "StepperItemKeyEventDetail",
- "references": {
- "StepperItemKeyEventDetail": {
- "location": "import",
- "path": "../stepper/interfaces"
- }
- }
- }
- }, {
- "method": "calciteInternalStepperItemSelect",
- "name": "calciteInternalStepperItemSelect",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "complexType": {
- "original": "StepperItemEventDetail",
- "resolved": "StepperItemEventDetail",
- "references": {
- "StepperItemEventDetail": {
- "location": "import",
- "path": "../stepper/interfaces"
- }
- }
- }
- }, {
- "method": "calciteInternalUserRequestedStepperItemSelect",
- "name": "calciteInternalUserRequestedStepperItemSelect",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "complexType": {
- "original": "StepperItemChangeEventDetail",
- "resolved": "StepperItemChangeEventDetail",
- "references": {
- "StepperItemChangeEventDetail": {
- "location": "import",
- "path": "../stepper/interfaces"
- }
- }
- }
- }, {
- "method": "calciteInternalStepperItemRegister",
- "name": "calciteInternalStepperItemRegister",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "complexType": {
- "original": "StepperItemEventDetail",
- "resolved": "StepperItemEventDetail",
- "references": {
- "StepperItemEventDetail": {
- "location": "import",
- "path": "../stepper/interfaces"
- }
- }
- }
- }];
- }
- static get methods() {
- return {
- "setFocus": {
- "complexType": {
- "signature": "() => Promise<void>",
- "parameters": [],
- "references": {
- "Promise": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "docs": {
- "text": "",
- "tags": []
- }
- }
- };
- }
- static get elementRef() { return "el"; }
- static get watchers() {
- return [{
- "propName": "active",
- "methodName": "activeHandler"
- }, {
- "propName": "selected",
- "methodName": "selectedHandler"
- }, {
- "propName": "disabled",
- "methodName": "disabledWatcher"
- }, {
- "propName": "effectiveLocale",
- "methodName": "effectiveLocaleWatcher"
- }];
- }
- static get listeners() {
- return [{
- "name": "calciteInternalStepperItemChange",
- "method": "updateActiveItemOnChange",
- "target": "body",
- "capture": false,
- "passive": false
- }];
- }
- }
|