-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathCard.svelte
62 lines (52 loc) · 1.76 KB
/
Card.svelte
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
<script>
import { onMount } from 'svelte';
import { Card as BaseCard } from '@keenmate/svelte-adminlte';
import CardDefaultTools from '../components/common/CardDefaultTools.svelte';
import { getRandomString } from '../helpers/string-helpers';
export let loading;
export let noPadding = false;
export let noTools = false;
export let removeParent = false;
let loadingDiv = null;
let card = null;
const cardClassID = 'crd' + getRandomString(6).toLocaleLowerCase();
onMount(() => {
loadingDiv.parentElement.parentElement.appendChild(loadingDiv);
// Destroy the inner Svelte components as well.
// This will stop the loaded setInterval timers and stop reloading not needed data...
if (!noTools) {
document
.querySelector(`div.card.${cardClassID} button[data-card-widget="remove"]`)
.addEventListener('click', (event) => {
let parent = null;
if (removeParent) {
parent = document.querySelector(`div.card.${cardClassID}`).parentElement;
}
setTimeout(() => {
if (parent !== null) {
parent.remove();
}
card.$destroy();
}, 550);
});
}
if (!$$slots.header) {
document.querySelector(`div.card.${cardClassID} div.card-header`).remove();
}
});
</script>
<BaseCard {noPadding} class="{cardClassID} {$$props.class || ''}" bind:this={card}>
<svelte:fragment slot="header">
<slot name="header" />
</svelte:fragment>
<svelte:fragment slot="tools">
<slot name="tools" />
{#if !noTools}
<CardDefaultTools />
{/if}
</svelte:fragment>
<slot />
<div class="overlay" class:d-none={!loading} bind:this={loadingDiv}>
<i class="fas fa-2x fa-sync-alt fa-spin"></i>
</div>
</BaseCard>