|
| 1 | +import { withKnobs } from '@storybook/addon-knobs'; |
| 2 | +import { storiesOf } from '@storybook/polymer'; |
| 3 | +import { html } from 'lit-html'; |
| 4 | +import './7segment-element'; |
| 5 | +import { LitElement, customElement, property } from 'lit-element'; |
| 6 | + |
| 7 | +storiesOf('7 Segment', module) |
| 8 | + .addDecorator(withKnobs) |
| 9 | + .add( |
| 10 | + 'Red 4.', |
| 11 | + () => html` |
| 12 | + <wokwi-7segment color="red" values="[0,1,1,0,0,1,1,1]"></wokwi-7segment> |
| 13 | + ` |
| 14 | + ) |
| 15 | + .add( |
| 16 | + 'Green 5', |
| 17 | + () => html` |
| 18 | + <wokwi-7segment color="green" values="[1,0,1,1,0,1,1,0]"></wokwi-7segment> |
| 19 | + ` |
| 20 | + ) |
| 21 | + .add( |
| 22 | + 'Blue spinner', |
| 23 | + () => html` |
| 24 | + <wokwi-blue-spinner></wokwi-blue-spinner> |
| 25 | + ` |
| 26 | + ); |
| 27 | + |
| 28 | +@customElement('wokwi-blue-spinner') |
| 29 | +export class BlueSpinnerElement extends LitElement { |
| 30 | + @property({ type: Array }) values: number[] = []; |
| 31 | + |
| 32 | + private interval: number | null = null; |
| 33 | + |
| 34 | + connectedCallback() { |
| 35 | + super.connectedCallback(); |
| 36 | + let i = 0; |
| 37 | + this.interval = setInterval(() => { |
| 38 | + this.values = [0, 0, 0, 0, 0, 0, 0, 0]; |
| 39 | + this.values[i++ % 6] = 1; |
| 40 | + }, 100); |
| 41 | + } |
| 42 | + |
| 43 | + disconnectedCallback() { |
| 44 | + if (this.interval) { |
| 45 | + clearInterval(this.interval); |
| 46 | + this.interval = null; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + render() { |
| 51 | + return html` |
| 52 | + <wokwi-7segment color="blue" .values="${this.values}"></wokwi-7segment> |
| 53 | + `; |
| 54 | + } |
| 55 | +} |
0 commit comments