-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathapp.component.ts
More file actions
65 lines (58 loc) · 1.79 KB
/
app.component.ts
File metadata and controls
65 lines (58 loc) · 1.79 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
ChangeDetectionStrategy,
Component,
ElementRef,
viewChild,
} from '@angular/core';
import {
BTN_SEND_TRIGGER_INTERVAL,
PROGRESS_INITIAL_VALUE,
PROGRESS_MAX_VALUE,
PROGRESS_UPDATE_COUNT,
} from '../constants/app.constants';
import { HoldableDirective } from './holdable.directive';
@Component({
imports: [HoldableDirective],
selector: 'app-root',
template: `
<main class="flex h-screen items-center justify-center">
<div
class="flex w-full max-w-screen-sm flex-col items-center gap-y-8 p-4">
<button
holdable
[updateInterval]="BTN_SEND_TRIGGER_INTERVAL"
(onInterval)="updateProgress()"
(onRelease)="resetProgress()"
(onComplete)="onSend()"
class="rounded bg-indigo-600 px-4 py-2 font-bold text-white transition-colors ease-in-out hover:bg-indigo-700">
Hold me
</button>
<progress
#progress
[value]="PROGRESS_INITIAL_VALUE"
[max]="PROGRESS_MAX_VALUE"></progress>
</div>
</main>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
progress = viewChild<string, ElementRef<HTMLProgressElement>>('progress', {
read: ElementRef,
});
readonly PROGRESS_INITIAL_VALUE = PROGRESS_INITIAL_VALUE;
readonly PROGRESS_MAX_VALUE = PROGRESS_MAX_VALUE;
readonly BTN_SEND_TRIGGER_INTERVAL = BTN_SEND_TRIGGER_INTERVAL;
onSend(): void {
console.log('Save it!');
}
resetProgress(): void {
this.progress().nativeElement.value = this.PROGRESS_INITIAL_VALUE;
}
updateProgress(): void {
const progressEl = this.progress().nativeElement;
const currentVal = progressEl.value;
const increment = this.PROGRESS_MAX_VALUE / PROGRESS_UPDATE_COUNT;
progressEl.value = currentVal + increment;
}
}