/** * Copyright Aquera Inc 2023 * * This source code is licensed under the BSD-3-Clause license found in the * LICENSE file in the root directory of this source tree. */ import { LitElement, nothing, html, CSSResultArray, TemplateResult, PropertyValues } from 'lit'; import { customElement, property, state, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { styles } from './nile-stepper-item.css'; import NileElement from '../internal/nile-element'; /** * Nile stepper-item component. * * @tag nile-stepper-item * */ @customElement('nile-stepper-item') export class NileStepperItem extends NileElement { @query('.stepper__item__content--above .stepper__content__title') absoluteTitle:HTMLDivElement; @query('.stepper__item__content--above .stepper__content__subtitle') absoluteSubtitle:HTMLDivElement; /* Properties passed directly */ @property({attribute: true, reflect: true}) title: string = ''; @property({attribute: true, reflect: true}) subtitle: string = ''; @property({attribute: true, reflect: true}) completed: boolean = false; @property({attribute: true, reflect: true}) current: boolean = false; /* Properties passed to parent component: NileStepper */ @state() private contentBelow = false; @state() private size : 'sm' | 'lg' = 'lg'; @state() private icon = 'tick'; /* Properties Computed at parent level component NileStepper */ @state() private isFirst = false; @state() private isLast = false; @state() private isComplete = false; @state() private isCurrent = false; @state() private isManualMode = false; @state() private currentStepValue :Number; @state() private completedStepValue :Number; @state() private calculatedCompletedStepValue :Number; @state() private value :Number; @state() private haveFlex :Boolean=true; /** * The styles for nile-stepper-item * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]` */ public static get styles(): CSSResultArray { return [styles]; } protected updated(_changedProperties: PropertyValues): void { if(_changedProperties.has('subtitle') && this.isLast && !this.contentBelow && this.subtitle){ const subtitleWidth=this.absoluteSubtitle?.scrollWidth as number ?? '0'; this.absoluteTitle.style.minWidth=subtitleWidth+"px" } } /* #endregion */ /* #region Methods */ /** * Render method * @slot This is a slot test */ public render(): TemplateResult { if (!this.haveFlex) this.style.setProperty('--stepper-flex-val', `0`); const isCurrent = this.isManualMode ? this.current : this.isCurrent; const isComplete = this.isManualMode ? this.completed : this.isComplete; let showCompletedIcon = false; if (isComplete && !isCurrent || this.completedStepValue == this.value) showCompletedIcon = true; let suffixStepperLineActive = false; if (isComplete) { suffixStepperLineActive = true; if (this.calculatedCompletedStepValue == this.value) suffixStepperLineActive = false; } return html`
${this.isFirst ? nothing : html`
`}
${showCompletedIcon ? html`
${this.getSvg()}
` : html`
` }
${this.contentBelow || !this.title ? nothing:html`
${this.title}
${this.subtitle}
`} ${this.isLast ? nothing : html`
`}
${this.contentBelow? html`
${this.title}
${this.subtitle}
`:nothing}
`; } getSvg():TemplateResult{ let iconSize = this.size == 'sm' ? 20 : this.size == 'lg' ? 24 : 28; return html` ` } /* #endregion */ } export default NileStepperItem; declare global { interface HTMLElementTagNameMap { 'nile-stepper-item': NileStepperItem; } }