aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Loading/Grid.svelte
blob: 73a6d284939301afe1460dcbe32e750c7baebf85 (plain) (blame)
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
<script lang="ts">
  export let colour = 'var(--fg)';
</script>

<div class="grid" style={`--loader-colour: ${colour};`}>
  {#each Array.from({ length: 9 }) as _}
    <div></div>
  {/each}
</div>

<style lang="scss">
  .grid {
    display: inline-block;
    position: relative;
    width: 64px;
    height: 64px;

    div {
      position: absolute;
      width: 13px;
      height: 13px;
      border-radius: 50%;
      background: var(--loader-colour);
      animation: grid 1.2s linear infinite;
    }
  }

  @function column($i) {
    @if $i % 3 == 0 {
      @return 3;
    } @else {
      @return $i % 3;
    }
  }

  @for $i from 1 through 9 {
    .grid div:nth-child(#{$i}) {
      $row: ceil(calc($i / 3));
      $column: column($i);

      top: 6px + ($row - 1) * 20px;
      left: 6px + ($column - 1) * 20px;
      animation-delay: -0.4s * ($i - 1);
    }
  }

  @keyframes grid {
    0%,
    100% {
      opacity: 1;
    }

    50% {
      opacity: 0.5;
    }
  }
</style>