|
20 | 20 | <link href="./sonner.css" rel="stylesheet" /> |
21 | 21 | </head> |
22 | 22 | <body> |
23 | | - <div class="w-screen h-screen" flex="justify-center items-center"> |
24 | | - <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-snackbar">Test Snackbar</button> |
25 | | - <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-notif">Test Notification</button> |
26 | | - <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-custom-notif">Test Custom Notification</button> |
27 | | - <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-toast">Test Toast</button> |
28 | | - <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-sonner">Test Sonner</button> |
| 23 | + <div class="w-screen h-screen" flex="column wrap justify-center items-center"> |
| 24 | + <div class="w-full mb-2" flex="justify-center items-center"> |
| 25 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-snackbar">Test Snackbar</button> |
| 26 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-notif">Test Notification</button> |
| 27 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-custom-notif">Test Custom Notification</button> |
| 28 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-toast">Test Toast</button> |
| 29 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--blue-700);color: #fff;height: 36px;" class="js-sonner">Test Sonner</button> |
| 30 | + </div> |
| 31 | + <div class="w-full" flex="justify-center items-center"> |
| 32 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--amber-700);color: #fff;height: 36px;" class="js-snackbar2">Test Snackbar</button> |
| 33 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--amber-700);color: #fff;height: 36px;" class="js-notif2">Test Notification</button> |
| 34 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--amber-700);color: #fff;height: 36px;" class="js-toast2">Test Toast</button> |
| 35 | + <button style="padding: 0 1rem;margin-right: 1rem;background-color: var(--amber-700);color: #fff;height: 36px;" class="js-sonner2">Test Sonner</button> |
| 36 | + </div> |
29 | 37 | </div> |
30 | 38 |
|
31 | 39 | <script type="module"> |
|
34 | 42 | import notifications from "./dist/notifications.js"; |
35 | 43 | import sonner from "./dist/sonner.js"; |
36 | 44 |
|
| 45 | + let count = 0; |
| 46 | + |
| 47 | + const sonner2 = document.body.querySelector(".js-sonner2"); |
| 48 | + sonner2.addEventListener("click", ()=>{ |
| 49 | + const event = new CustomEvent("notify:sonner", { |
| 50 | + detail: { |
| 51 | + message: `Example sonner toast message.`, |
| 52 | + } |
| 53 | + }); |
| 54 | + window.dispatchEvent(event); |
| 55 | + }); |
| 56 | + |
| 57 | + const toast2 = document.body.querySelector(".js-toast2"); |
| 58 | + toast2.addEventListener("click", ()=>{ |
| 59 | + const event = new CustomEvent("notify:toast", { |
| 60 | + detail: { |
| 61 | + message: `Example toast message ${count++}.`, |
| 62 | + } |
| 63 | + }); |
| 64 | + window.dispatchEvent(event); |
| 65 | + }); |
| 66 | + |
| 67 | + const alert2 = document.body.querySelector(".js-notif2"); |
| 68 | + alert2.addEventListener("click", ()=>{ |
| 69 | + const event = new CustomEvent("notify:alert", { |
| 70 | + detail: { |
| 71 | + title: "Example Toast Message", |
| 72 | + message: "This is what a toaster message might look like. Click the button to stack notifications.", |
| 73 | + buttons: [ |
| 74 | + { |
| 75 | + label: "Reload", |
| 76 | + callback: ()=>{ location.reload(); }, |
| 77 | + }, |
| 78 | + ], |
| 79 | + duration: 10, |
| 80 | + } |
| 81 | + }); |
| 82 | + window.dispatchEvent(event); |
| 83 | + }); |
| 84 | + |
| 85 | + const snackbarButton2 = document.body.querySelector(".js-snackbar2"); |
| 86 | + snackbarButton2.addEventListener("click", ()=>{ |
| 87 | + const event = new CustomEvent("notify:snackbar", { |
| 88 | + detail: { |
| 89 | + message: "Example snackbar message.", |
| 90 | + autofocus: true, |
| 91 | + duration: Infinity, |
| 92 | + buttons: [ |
| 93 | + { |
| 94 | + label: "Reload", |
| 95 | + callback: ()=>{ location.reload(); }, |
| 96 | + }, |
| 97 | + ], |
| 98 | + } |
| 99 | + }); |
| 100 | + window.dispatchEvent(event); |
| 101 | + }); |
| 102 | + |
37 | 103 | const snackbarButton = document.body.querySelector(".js-snackbar"); |
38 | 104 | snackbarButton.addEventListener("click", () =>{ |
39 | 105 | snackbar({ |
|
88 | 154 | notifications.append(new CustomNotificationElement("Custom toaster notification example.")); |
89 | 155 | }); |
90 | 156 |
|
91 | | - let count = 0; |
92 | 157 | const toastButton = document.body.querySelector(".js-toast"); |
93 | 158 | toastButton.addEventListener("click", () => { |
94 | 159 | toaster.push({ |
|
0 commit comments