-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
422 lines (410 loc) · 18.2 KB
/
index.html
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Toast Notification Example</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="src/toast-notification.css" />
<!-- <link rel="stylesheet" href="dist/toast-notification.min.css" /> -->
<!-- <link rel="stylesheet" href="https://unpkg.com/toast-notification-js/dist/toast-notification.min.css" /> -->
<script>
tailwind.config = {
darkMode: "class",
theme: {
extend: {
keyframes: {
"shrink-width": {
from: {
width: "100%",
},
to: {
width: "0%",
},
},
},
animation: {
"shrink-width": "linear shrink-width 1s",
"shrink-width-paused":
"linear shrink-width 1s paused",
},
},
},
};
</script>
<style type="text/tailwindcss">
@layer utilities {
input,
select {
@apply border-2 border-slate-500 rounded-md p-2 dark:bg-black;
}
}
</style>
<!-- dark mode function -->
<script>
const theme = ["dark", "light"];
if (!theme.includes(localStorage.theme)) {
localStorage.theme = "dark";
}
const lightMode = () => {
document.documentElement.classList.remove("dark");
};
const darkMode = () => {
document.documentElement.classList = "";
document.documentElement.classList.add("dark");
};
function updateTheme() {
localStorage.theme === "dark" ? darkMode() : lightMode();
}
updateTheme();
</script>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"
></script>
<!-- <script type="module">
import { ToastNotification } from "./src/toast-notification.esm.js";
window.ToastNotification = ToastNotification;
</script> -->
<script src="src/toast-notification.umd.js"></script>
<!-- <script src="dist/toast-notification.min.js"></script> -->
<!-- <script src="https://unpkg.com/toast-notification-js/dist/toast-notification.min.js"></script> -->
<script>
document.addEventListener("DOMContentLoaded", () => {
var toastNotification = ToastNotification();
window.addEventListener("showToastNotification", (event) => {
toastNotification.create({
classList: event.detail.classList,
title: event.detail.title,
message: event.detail.message,
icon: event.detail.icon
? event.detail.icon
: "<svg xmlns='http://www.w3.org/2000/svg' fill='currentColor' class='w-full h-full text-green-500' viewBox='0 0 16 16'> <path d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/> </svg>",
duration: event.detail.duration,
closeButton: event.detail.closeButton,
position: event.detail.position,
marginWidth: event.detail.marginWidth,
redirect: event.detail.redirect,
progressBar: event.detail.progressBar,
// root: document.getElementById("toast-container"),
});
});
window.addEventListener("clearToastNotification", (event) => {
toastNotification.clear();
});
});
</script>
</head>
<body class="p-4 text-slate-700 dark:text-slate-200 dark:bg-slate-950">
<h1 class="mb-4 text-4xl font-bold capitalize">toast notification</h1>
<button
x-data="{
toggleIcon: localStorage.theme ?? 'dark',
toggleTheme() {
localStorage.theme = localStorage.theme === 'dark' ? 'light' : 'dark'
this.toggleIcon = localStorage.theme
updateTheme()
}
}"
type="button"
x-on:click="toggleTheme"
class="fixed z-10 flex items-center px-4 py-2 text-white bg-black rounded-lg dark:text-black top-2 right-2 dark:bg-white"
>
<span class="capitalize" x-text="toggleIcon"></span>
</button>
<div
x-data="{ data: {
redirect: {},
progressBar: {},
position: {},
}
}"
class="flex flex-wrap gap-4"
>
<div
class="flex flex-col w-full gap-2 px-2 overflow-y-auto font-semibold capitalize max-h-96 md:w-5/12"
>
<label class="flex flex-col">
<span class="text-xl underline">class list</span>
<input
type="text"
x-model.fill="data.classList"
value="text-black bg-gradient-to-t from-emerald-400 via-sky-100 to-cyan-300 dark:text-white dark:bg-gradient-to-tl dark:from-slate-600 dark:via-neutral-800 dark:to-stone-300"
placeholder="toast class list"
/>
</label>
<label class="flex flex-col">
<span class="text-xl underline">title</span>
<input
type="text"
x-model="data.title"
placeholder="title"
/>
</label>
<label class="flex flex-col">
<span class="text-xl underline">message</span>
<input
type="text"
x-model="data.message"
placeholder="message"
/>
</label>
<label class="flex flex-col">
<span class="text-xl underline">icon</span>
<input
type="text"
x-model.fill="data.icon"
value="🍞"
placeholder="icon"
/>
</label>
<label class="flex flex-col">
<span class="text-xl underline">duration (in seconds)</span>
<input
type="number"
max="1000"
maxlength="4"
min="-1"
x-model="data.duration"
placeholder="duration (in seconds)"
/>
</label>
<div>
<span class="text-xl underline">close button</span>
<div class="flex flex-row gap-2">
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="true"
x-model="data.closeButton"
/>
<span>yes</span>
</label>
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="false"
x-model="data.closeButton"
/>
<span>no</span>
</label>
</div>
</div>
<div class="flex flex-row flex-wrap w-full gap-2">
<label class="flex flex-col">
<span class="text-xl underline">position x</span>
<select x-model="data.position.x">
<option value="right">right (default)</option>
<option value="center">center</option>
<option value="left">left</option>
</select>
</label>
<label class="flex flex-col">
<span class="text-xl underline">position y</span>
<select x-model="data.position.y">
<option value="bottom">bottom (default)</option>
<option value="top">top</option>
</select>
</label>
<label class="flex flex-col">
<span class="text-xl underline"
>position z (z-index)</span
>
<input
type="number"
min="1"
x-model="data.position.z"
placeholder="position z"
/>
</label>
</div>
<label class="flex flex-col">
<span class="text-xl underline">Margin Width</span>
<input
type="text"
x-model.fill="data.marginWidth"
value="20px"
placeholder="Margin X"
/>
</label>
<div>
<span class="text-xl underline">redirect</span>
<div class="flex flex-row gap-2">
<label class="flex flex-col flex-grow">
<span>url</span>
<input
type="text"
x-model="data.redirect.url"
placeholder="url"
/>
</label>
<div>
<span>open on new window</span>
<div class="flex flex-row gap-2">
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="true"
x-model="data.redirect.newWindow"
/>
<span>yes</span>
</label>
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="false"
x-model="data.redirect.newWindow"
/>
<span>no</span>
</label>
</div>
</div>
</div>
</div>
<div>
<span class="text-xl underline">progress bar</span>
<div class="flex flex-row gap-2">
<div>
<span>show</span>
<div class="flex flex-row gap-2">
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="true"
x-model="data.progressBar.show"
/>
<span>yes</span>
</label>
<label class="flex flex-row items-center gap-1">
<input
type="radio"
value="false"
x-model="data.progressBar.show"
/>
<span>no</span>
</label>
</div>
</div>
<label class="flex flex-col flex-grow">
<span>class list for progress bar</span>
<input
type="text"
x-model="data.progressBar.classList"
placeholder="class list"
/>
</label>
</div>
</div>
</div>
<div
class="relative w-full p-4 pb-16 text-white bg-slate-600 md:w-5/12 grow rounded-xl"
>
<div class="absolute z-10 md:bottom-2 md:left-2 right-2">
<button
type="button"
class="px-4 py-2 text-white bg-black rounded-xl w-fit"
x-on:click="$dispatch('showToastNotification', data)"
>
Create Toast
</button>
<button
type="button"
class="px-4 py-2 text-white bg-black rounded-xl w-fit"
x-on:click="$dispatch('clearToastNotification')"
>
Clear Toast
</button>
</div>
<h3 class="mb-4 text-xl">Generated code:</h3>
<code class="select-all">
<span class="block"
><span class="text-sky-400">const</span>
<span class="text-cyan-400"
>createToastNotification</span
>
=
<span class="text-amber-500">ToastNotification</span
>();</span
>
<span class="inline text-cyan-400"
>createToastNotification</span
>.<span class="text-amber-500">create</span>
<span class="inline" x-text="'({'"></span>
<template x-for="(value, key) in data">
<div
class="flex ml-2"
x-bind:class="(!value || (typeof value === 'object' && Object.values(value).every(v => !v))) ? 'hidden' : ''"
>
<span
x-text="key + ': '"
class="text-amber-500"
x-bind:class="(!value || (typeof value === 'object' && Object.values(value).every(v => !v))) ? 'hidden' : ''"
></span>
<template x-if="typeof value === 'object'">
<div
x-bind:class="(Object.keys(value).length <= 0 || Object.values(value).every(v => !v)) ? 'hidden' : ''"
>
{
<template
x-for="(propValue, propKey) in value"
>
<div
class="ml-4"
x-bind:class="!propValue && 'hidden'"
>
<span
class="text-amber-500"
x-text="propKey +':'"
></span>
<span
x-text="'\''+propValue+'\','"
></span>
</div>
</template>
},
</div>
</template>
<template x-if="typeof value !== 'object'">
<span x-text="'\''+value+'\','"></span>
</template>
</div>
</template>
<span class="inline" x-text="'});'"></span>
</code>
</div>
</div>
<footer class="flex justify-end w-full gap-1">
Build with
<a
href="https://tailwindcss.com/"
target="_blank"
rel="noopener noreferrer"
>
<img
class="inline h-4"
src="https://upload.wikimedia.org/wikipedia/commons/d/d5/Tailwind_CSS_Logo.svg"
alt="Tailwindcss"
title="Tailwindcss"
/>
</a>
&
<a
href="https://alpinejs.dev/"
target="_blank"
rel="noopener noreferrer"
>
<img
class="inline h-6 rounded-sm"
src="https://github.com/alpinejs.png?size=400"
alt="Alpine.js"
title="Alpine.js"
/>
</a>
</footer>
<div
class="w-full h-48 mt-4 overflow-hidden bg-slate-800"
id="toast-container"
></div>
</body>
</html>