-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathLoading.astro
67 lines (56 loc) · 1.48 KB
/
Loading.astro
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
---
import Icon from "./Icon.astro";
---
<div class="loading-container loading">
<Icon name="circle-notch" group="solid" class="spinner"/>
<div class="content">
<slot/>
</div>
</div>
<script>
const loadingElements = document.querySelectorAll("div.loading-container");
for (const element of loadingElements) {
const spinner = element.querySelector("i.spinner");
const contentContainer = element.querySelector("div.content");
if (!spinner) {
console.error("Failed to find spinner");
continue;
}
if (!contentContainer) {
console.error("Failed to find content container");
continue;
}
element.addEventListener("content_loaded", (e) => {
e.stopPropagation();
element.classList.remove("loading");
})
}
</script>
<style lang="scss">
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.loading-container {
:global(i.spinner) {
display: none;
font-size: 2em;
animation: spin 1s linear infinite both;
}
&.loading {
display: flex;
justify-content: center;
align-items: center;
:global(i.spinner) {
display: block;
}
.content {
display: none;
}
}
}
</style>