aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Loading/Skeleton.svelte
blob: 5ca3789ad9dc769c43b5494539a39ea2090b326f (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
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
<script lang="ts">
  interface Props {
    count?: number;
    width?: string;
    height?: string;
    card?: boolean;
    grid?: boolean;
    list?: boolean;
    pad?: boolean;
    bigCard?: boolean;
  }

  let {
    count = 3,
    width = '100%',
    height = '100px',
    card = true,
    grid = false,
    list = false,
    pad = false,
    bigCard = false
  }: Props = $props();
</script>

{#if grid}
  <div class="grid" style={pad ? 'padding-top: .75em;' : ''}>
    {#each Array(count) as _, i}
      <div class={card ? `${bigCard ? 'card' : ''} card-small` : ''} style={`width: ${width};`}>
        <div class="skeleton-container" style={`--i: ${i};`}>
          <div class="skeleton" style={`width: ${width}; height: ${height};`}></div>
        </div>
      </div>
    {/each}
  </div>
{:else}
  {#each Array(count) as _, i}
    <div
      class={card ? `${bigCard ? 'card' : ''} card-small` : ''}
      style={`width: ${width}; ${list ? 'padding-top: .75em;' : ''}; --i: ${i};`}
    >
      <div class="skeleton-container">
        <div class="skeleton" style={`width: ${width}; height: ${height};`}></div>
      </div>
    </div>

    {#if !list && i < count - 1}
      <p></p>
    {/if}
  {/each}
{/if}

<style>
  @keyframes progress {
    0% {
      background-position: -200px 0;
    }
    100% {
      background-position: calc(200px + 100%) 0;
    }
  }

  .skeleton-container {
    animation: progress 1.2s ease-in-out infinite;
    background-color: var(--base001);
    background-image: linear-gradient(90deg, var(--base0011), var(--base01), var(--base0011));
    background-size: 200px 100%;
    background-repeat: no-repeat;
    border-radius: 8px;
    animation-delay: calc(var(--i) * 0.025s);
  }

  .skeleton {
    border-radius: 4px;
    display: inline-block;
    line-height: 1;
  }

  .grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1em 0.5em;
  }
</style>