import { ZuiBaseElement } from '@zywave/zui-base'; import { html } from 'lit'; import { property } from 'lit/decorators.js'; import { style } from './zui-step-flow-indicator-css.js'; import type { PropertyValues } from 'lit'; import type { ZuiStepFlowIndicatorItem } from './zui-step-flow-indicator-item'; /** * @element zui-step-flow-indicator * * @deprecated */ export class ZuiStepFlowIndicator extends ZuiBaseElement { @property({ type: Number }) step = 0; @property({ type: Boolean }) hide = false; @property({ type: String }) orientation = 'horizontal'; #indicatorItems: NodeListOf | undefined[] = undefined; protected firstUpdated() { this._setupChildren(); } static get styles() { return [super.styles, style]; } render() { if (this.hide) { this.classList.add('hide'); } else { this.classList.remove('hide'); } return html` `; } updated(changedProps: PropertyValues) { super.update(changedProps); const indicatorItems = this._getIndicatorItems(); //Add/remove active on step change for (let i = 0; i < indicatorItems.length; i++) { const indicatorItem = indicatorItems[i]; if (i === this.step) { indicatorItem.setAttribute('active', ''); } else { indicatorItem.removeAttribute('active'); } } if (changedProps.has('orientation')) { for (let i = 0; i < indicatorItems.length; i++) { const indicatorItem = indicatorItems[i]; if (this.orientation && this.orientation === 'vertical') { indicatorItem.setAttribute('orientation', 'vertical'); } else { indicatorItem.removeAttribute('orientation'); } } } } private _setupChildren() { const indicatorItems = this._getIndicatorItems(); for (let i = 0; i < indicatorItems.length; i++) { const indicatorItem: ZuiStepFlowIndicatorItem = indicatorItems[i]; indicatorItem.index = i; indicatorItem.addEventListener('click', this._onItemClick.bind(this)); } } private _onItemClick(event: Event) { const item = event.target as ZuiStepFlowIndicatorItem; this.dispatchEvent(new CustomEvent('setstep', { bubbles: true, composed: true, detail: item.index })); } private _getIndicatorItems(): undefined[] | NodeListOf { const indicatorItemElements: NodeListOf = this.querySelectorAll('zui-step-flow-indicator-item'); if (indicatorItemElements) { this.#indicatorItems = indicatorItemElements; } else { this.#indicatorItems = []; } return this.#indicatorItems; } } window.customElements.define('zui-step-flow-indicator', ZuiStepFlowIndicator); declare global { interface HTMLElementTagNameMap { 'zui-step-flow-indicator': ZuiStepFlowIndicator; } }