-
Notifications
You must be signed in to change notification settings - Fork 2
/
+page.svelte
149 lines (130 loc) · 3.9 KB
/
+page.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script lang="ts">
import '$lib/style.css';
import './app.css';
import dedent from 'dedent';
import ModalContainer from '$lib/ModalContainer.svelte';
import { openModal } from '$lib/service';
import type { ModalOptions } from '$lib/types';
import crossedFingers from './assets/Crossedfingers.svg';
import heartFace from './assets/Heartface.svg';
import mainmatter from './assets/Mainmatter.svg';
import redHeart from './assets/Redheart.svg';
import yellowHeart from './assets/Yellowheart.svg';
import FooComponent from './FooComponent.svelte';
import SyntaxHighlight from './SyntaxHighlight.svelte';
async function openFooModal(data?: unknown, options?: ModalOptions) {
let result = await openModal(FooComponent, data ?? null, options);
console.log(`Modal result: ${JSON.stringify(result)}`);
}
</script>
<svelte:head>
<title>Svelte Promise Modals</title>
<script
defer
data-domain="svelte-promise-modals.com"
src="https://plausible.io/js/script.js"
></script>
</svelte:head>
<header>
<div>
<img
src={crossedFingers}
alt="An emoji showing crossed fingers"
role="presentation"
id="crossedfingers"
/>
<span class="visually-hidden">svelte-promise-modals</span>
</div>
<h1>
<span class="svelte">Svelte</span><span class="translateNeg">Promise</span><span
class="translatePos">Modals</span
>
</h1>
</header>
<main>
<div class="note">
<p>Modals in Svelte made easy. <span class="whitespace-nowrap">Promised.🤞</span></p>
</div>
<div class="preview">
<h2>Example for <strong>the modal</strong></h2>
<button
type="button"
on:click={() => openFooModal({ data: 'something' })}
data-testid="open-foo"
>
A simple modal with a button to close it
</button>
</div>
<!-- eslint-disable -->
<SyntaxHighlight
code={dedent`
<script>
import { openModal } from 'svelte-promise-modals';
async function openFooModal() {
let result = await openModal(FooComponent);
console.log(result); // Whatever the modal returned when it was closed
}
</script>
<button type="button" on:click={() => openFooModal()}>
A simple modal with a button to close it
</button>
`}
/>
<!-- eslint-enable -->
<div class="preview">
<h2>Example for <strong>custom animations</strong></h2>
<button type="button" on:click={() => openFooModal(null, { className: 'from-top' })}>
From and to the top of the window
</button>
<button type="button" on:click={() => openFooModal(null, { className: 'from-bottom' })}>
From and to the bottom of the window
</button>
</div>
<div class="note">
<p>
Code for the demonstrations shown here can be found in the <a
href="https://github.com/mainmatter/svelte-promise-modals/tree/master/src/routes"
>demo application</a
> of the addon.
</p>
<p>
See the <a
href="https://github.com/mainmatter/svelte-promise-modals#readme"
target="_blank"
rel="noopener noreferrer">README</a
> on GitHub for setup & further instructions.
</p>
</div>
<div>
<img src={redHeart} alt="A red heart" role="presentation" id="redheart" />
</div>
<div class="note">
<p>
svelte-promise-modals is <br />made & sponsored with ❤️ by
<a href="https://mainmatter.com/svelte-consulting/" target="_blank" rel="noopener noreferrer">
<div>
<img src={mainmatter} alt="Mainmatter" role="presentation" id="mainmatter" />
</div></a
>
</p>
</div>
<div>
<img
src={yellowHeart}
alt="yellow heart"
role="presentation"
id="yellowheart"
class="floating"
/>
</div>
<div>
<img
src={heartFace}
alt="smiley face surrounded by hearts"
role="presentation"
id="heartface"
class="floating"
/>
</div>
</main>
<ModalContainer />