-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathservo-element.stories.ts
54 lines (50 loc) · 1.22 KB
/
servo-element.stories.ts
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
52
53
54
import { number, withKnobs } from '@storybook/addon-knobs';
import { storiesOf, forceReRender } from '@storybook/web-components';
import { html } from 'lit';
import './servo-element';
class SweepAnimation {
angle = 0;
goingUp = true;
step() {
if (this.goingUp) {
this.angle++;
} else {
this.angle--;
}
if (this.angle === 180) {
this.goingUp = false;
}
if (this.angle === 0) {
this.goingUp = true;
}
}
}
const sweepAnimation = new SweepAnimation();
setInterval(() => {
sweepAnimation.step();
forceReRender();
}, 20);
storiesOf('Servo', module)
.addParameters({ component: 'wokwi-servo' })
.addDecorator(withKnobs)
.add(
'Default',
() => html` <wokwi-servo angle=${number('angle', 45, { min: 0, max: 180 })}></wokwi-servo> `
)
.add('Animated: sweep', () => {
return html` <wokwi-servo angle=${sweepAnimation.angle}></wokwi-servo> `;
})
.add(
'Horn: double',
() =>
html`
<wokwi-servo horn="double" angle=${number('angle', 45, { min: 0, max: 180 })}></wokwi-servo>
`
)
.add(
'Horn: cross',
() =>
html`
<wokwi-servo horn="cross" angle=${number('angle', 45, { min: 0, max: 180 })}></wokwi-servo>
`
);