-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile-sharing-event.stories.ts
More file actions
47 lines (41 loc) · 1.38 KB
/
file-sharing-event.stories.ts
File metadata and controls
47 lines (41 loc) · 1.38 KB
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
import { customElement, FASTElement, html } from '@microsoft/fast-element';
import { html as litHtml } from 'lit';
import '../src/index.js';
export default {
title: 'FileSharingEvent',
component: 'file-sharing-event',
};
export const Wrapped = () => litHtml`
<file-sharing-event-wrapper></file-sharing-event-wrapper>`
const template = html`
<file-sharing-card-event>
</file-sharing-card-event>
`;
@customElement({name: 'file-sharing-event-wrapper', template})
class FileSharingEventWrapper extends FASTElement {
override connectedCallback() {
super.connectedCallback && super.connectedCallback();
this.addEventListener('fileadded', (e) => {
this.simulateFileProgress(e.detail.notifyProgress);
});
}
override disconnectedCallback() {
this.removeEventListener('fileadded', (e) => {
this.simulateFileProgress(e.detail.notifyProgress);
});
super.disconnectedCallback && super.disconnectedCallback();
}
private simulateFileProgress(cb: (progress: number) => void) {
const startTime = Date.now();
const handle = setInterval(() => {
const now = Date.now();
const progress = (now - startTime) / 5000;
if (progress > 1) {
cb(1);
clearInterval(handle);
return;
}
cb(progress);
}, 100);
}
}