All files / src/components/indicator indicator.ts

0% Statements 0/26
0% Branches 0/4
0% Functions 0/6
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
import { html, property, TemplateResult } from 'lit-element';
import { RootElement, htmlElement } from '../../core';
 
import './style.scss';
 
@htmlElement(`indicator`)
export class Indicator extends RootElement {
  @property({
    converter: (value, type) => {
      const items: number[] = [];
      const num = Number(value);
      for (let i = 0; i < num; i++) {
        items.push(i);
      }
      return items;
    },
  })
  public length: number[] = [];
  @property({ type: Number }) public active = 0;
 
  public constructor() {
    super();
    this.theme = 'dark';
  }
 
  public render(): TemplateResult {
    return html`
      ${this.length.map(index => {
        const classes = `bg-${this.theme} ${index === this.active ? 'active' : ''}`.trim();
        return html`
          <span class="${classes}" @click=${(e: any) => this.itemClick(index, e)}></span>
        `;
      })}
    `;
  }
 
  private itemClick(index: number, event: any): any {
    if (index !== this.active) {
      this.active = index;
      const event = new CustomEvent<any>('index-changed', {
        detail: {
          index: this.active,
        },
        bubbles: true,
        composed: true,
      });
      this.dispatchEvent(event);
    }
  }
}