-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathModals.svelte
51 lines (47 loc) · 1.21 KB
/
Modals.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
<script>
import { modals, exitBeforeEnter, transitioning } from './store'
function isLazyModal(component) {
return typeof component.prototype === 'undefined'
}
async function getComponent(component) {
return component().then((res) => res.default)
}
</script>
{#if $modals.length > 0}
<slot name="backdrop" />
{/if}
<slot>
{#each $modals as modal, i (i)}
<!-- lazy modal -->
{#if isLazyModal(modal.component)}
{#await getComponent(modal.component)}
<slot name="loading" />
{:then component}
<svelte:component
this={component}
isOpen={i === $modals.length - 1 && !$transitioning}
{...modal.props}
on:introstart={() => {
$exitBeforeEnter = true
}}
on:outroend={() => {
$transitioning = false
}}
/>
{/await}
{:else}
<!-- normal modal -->
<svelte:component
this={modal.component}
isOpen={i === $modals.length - 1 && !$transitioning}
{...modal.props}
on:introstart={() => {
$exitBeforeEnter = true
}}
on:outroend={() => {
$transitioning = false
}}
/>
{/if}
{/each}
</slot>