-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgressBar.svelte
More file actions
85 lines (74 loc) · 1.65 KB
/
ProgressBar.svelte
File metadata and controls
85 lines (74 loc) · 1.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<script lang="ts">
import { Events } from "@wailsio/runtime";
let {
currentStep = $bindable(),
percentComplete = $bindable(),
totalSteps,
}: {
currentStep: number;
totalSteps: number;
percentComplete: number;
} = $props();
Events.On("monitor:download-progress", (event) => {
const { status, done } = event.data;
if (done) {
percentComplete = 0;
currentStep += 1;
} else {
percentComplete = status;
}
});
let finalPercents = $derived.by(() => {
let items = [];
for (let i = 0; i < currentStep; i++) {
items.push(100);
}
if (currentStep !== totalSteps) items.push(percentComplete);
for (let i = currentStep + 1; i < totalSteps; i++) {
items.push(0);
}
return items;
});
</script>
{#each finalPercents as finalPercent}
<div id="progress" style="--p:{finalPercent}%;" role="progressbar">
<span class="label">{Math.floor(finalPercent)}%</span>
</div>
{/each}
<style>
#progress {
--p: 0%;
width: 100%;
height: 30px;
position: relative;
margin-top: 5%;
background: linear-gradient(to right, #228B22, #006400);
border: 1px solid #333;
border-radius: 15px;
overflow: hidden;
}
/* Overlay hides the not-yet-filled portion */
#progress::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: var(--p);
right: 0;
background: #1a1a1a;
transition: left 0.1s linear;
z-index: 0;
}
.label {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 1rem;
color: #fff;
text-shadow: 0 0 2px rgba(0,0,0,0.6);
pointer-events: none;
user-select: none;
z-index: 1;
}
</style>