|
| 1 | +<script setup> |
| 2 | +import { h } from 'vue' |
| 3 | +import CustomToast from './components/CustomToast.vue' |
| 4 | +import AdvancedToast from './components/AdvancedToast.vue' |
| 5 | +import { useNuxtApp } from '#app' |
| 6 | +
|
| 7 | +const { $nt } = useNuxtApp() |
| 8 | +let i = 0 |
| 9 | +
|
| 10 | +function showBasicToast() { |
| 11 | + i++ |
| 12 | + $nt.show(`Hello, ${i} world!`) |
| 13 | +} |
| 14 | +
|
| 15 | +function showCustomToast() { |
| 16 | + i++ |
| 17 | + $nt.show({ |
| 18 | + content: () => |
| 19 | + h(CustomToast, { message: `Hello ${i} from Nuxt module playground!` }), |
| 20 | + transition: { |
| 21 | + name: 'fadeOut' |
| 22 | + }, |
| 23 | + theme: { |
| 24 | + containerId: 'nt-container-bottom-right', |
| 25 | + containerClass: |
| 26 | + 'absolute inset-0 pointer-events-none p-4 flex flex-col-reverse items-start gap-2', |
| 27 | + wrapperClass: 'pointer-events-auto cursor-pointer' |
| 28 | + } |
| 29 | + }) |
| 30 | +} |
| 31 | +
|
| 32 | +async function showAdvancedToast() { |
| 33 | + i++ |
| 34 | + const toast = await $nt.show({ |
| 35 | + content: () => |
| 36 | + h(AdvancedToast, { message: `Hello ${i} from Nuxt module playground!` }), |
| 37 | + dismissible: false, |
| 38 | + maxToasts: 1, |
| 39 | + theme: { |
| 40 | + containerId: 'nt-container-top-left', |
| 41 | + containerClass: |
| 42 | + 'absolute inset-0 pointer-events-none p-4 flex flex-col items-end gap-2', |
| 43 | + wrapperClass: [ |
| 44 | + 'pointer-events-auto', |
| 45 | + 'rounded', |
| 46 | + 'outline-slate-300', |
| 47 | + 'outline-offset-2', |
| 48 | + 'focus:outline', |
| 49 | + 'focus:outline-2', |
| 50 | + 'focus-within:outline', |
| 51 | + 'focus-within:outline-2' |
| 52 | + ].join(' ') |
| 53 | + }, |
| 54 | + transition: { |
| 55 | + enterActiveClass: 'transition duration-300 ease-out', |
| 56 | + enterFromClass: 'transform translate-x-full opacity-0', |
| 57 | + enterToClass: 'transform translate-x-0 opacity-100', |
| 58 | + leaveActiveClass: 'transition duration-300 ease-in', |
| 59 | + leaveFromClass: 'transform translate-x-0 opacity-100', |
| 60 | + leaveToClass: 'transform translate-x-full opacity-0' |
| 61 | + } |
| 62 | + }) |
| 63 | +
|
| 64 | + toast.el.focus() |
| 65 | +} |
| 66 | +function clearToast() { |
| 67 | + $nt.clear() |
| 68 | +} |
| 69 | +</script> |
| 70 | + |
| 71 | +<template> |
| 72 | + <div> |
| 73 | + <p>Nuxt module playground!</p> |
| 74 | + <button |
| 75 | + class="m-1 rounded border border-slate-200 px-2 py-1" |
| 76 | + @click="showBasicToast" |
| 77 | + > |
| 78 | + show basic toast |
| 79 | + </button> |
| 80 | + <button |
| 81 | + class="m-1 rounded border border-slate-200 px-2 py-1" |
| 82 | + @click="showCustomToast" |
| 83 | + > |
| 84 | + show custom toast |
| 85 | + </button> |
| 86 | + <button |
| 87 | + class="m-1 rounded border border-slate-200 px-2 py-1" |
| 88 | + @click="showAdvancedToast" |
| 89 | + > |
| 90 | + add advanced toast |
| 91 | + </button> |
| 92 | + <button |
| 93 | + class="m-1 rounded border border-slate-200 px-2 py-1" |
| 94 | + @click="clearToast" |
| 95 | + > |
| 96 | + clear all toast |
| 97 | + </button> |
| 98 | + </div> |
| 99 | +</template> |
| 100 | + |
| 101 | +<style> |
| 102 | +// Animations are taken from animate.css |
| 103 | +// https://daneden.github.io/animate.css |
| 104 | +.fadeOut { |
| 105 | + animation-name: fadeOut; |
| 106 | +} |
| 107 | +.fadeInDown { |
| 108 | + animation-name: fadeInDown; |
| 109 | +} |
| 110 | +.fadeInUp { |
| 111 | + animation-name: fadeInUp; |
| 112 | +} |
| 113 | +.fade-enter-active { |
| 114 | + transition: opacity 300ms ease-in; |
| 115 | +} |
| 116 | +.fade-leave-active { |
| 117 | + transition: opacity 150ms ease-out; |
| 118 | +} |
| 119 | +.fade-enter, |
| 120 | +.fade-leave-to { |
| 121 | + opacity: 0; |
| 122 | +} |
| 123 | +@-moz-keyframes fadeOut { |
| 124 | + from { |
| 125 | + opacity: 1; |
| 126 | + } |
| 127 | + to { |
| 128 | + opacity: 0; |
| 129 | + } |
| 130 | +} |
| 131 | +@-webkit-keyframes fadeOut { |
| 132 | + from { |
| 133 | + opacity: 1; |
| 134 | + } |
| 135 | + to { |
| 136 | + opacity: 0; |
| 137 | + } |
| 138 | +} |
| 139 | +@-o-keyframes fadeOut { |
| 140 | + from { |
| 141 | + opacity: 1; |
| 142 | + } |
| 143 | + to { |
| 144 | + opacity: 0; |
| 145 | + } |
| 146 | +} |
| 147 | +@keyframes fadeOut { |
| 148 | + from { |
| 149 | + opacity: 1; |
| 150 | + } |
| 151 | + to { |
| 152 | + opacity: 0; |
| 153 | + } |
| 154 | +} |
| 155 | +@-moz-keyframes fadeInDown { |
| 156 | + from { |
| 157 | + opacity: 0.5; |
| 158 | + transform: translate3d(0, -100%, 0); |
| 159 | + } |
| 160 | + to { |
| 161 | + opacity: 1; |
| 162 | + transform: none; |
| 163 | + } |
| 164 | +} |
| 165 | +@-webkit-keyframes fadeInDown { |
| 166 | + from { |
| 167 | + opacity: 0.5; |
| 168 | + transform: translate3d(0, -100%, 0); |
| 169 | + } |
| 170 | + to { |
| 171 | + opacity: 1; |
| 172 | + transform: none; |
| 173 | + } |
| 174 | +} |
| 175 | +@-o-keyframes fadeInDown { |
| 176 | + from { |
| 177 | + opacity: 0.5; |
| 178 | + transform: translate3d(0, -100%, 0); |
| 179 | + } |
| 180 | + to { |
| 181 | + opacity: 1; |
| 182 | + transform: none; |
| 183 | + } |
| 184 | +} |
| 185 | +@keyframes fadeInDown { |
| 186 | + from { |
| 187 | + opacity: 0.5; |
| 188 | + transform: translate3d(0, -100%, 0); |
| 189 | + } |
| 190 | + to { |
| 191 | + opacity: 1; |
| 192 | + transform: none; |
| 193 | + } |
| 194 | +} |
| 195 | +@-moz-keyframes fadeInUp { |
| 196 | + from { |
| 197 | + opacity: 0.5; |
| 198 | + transform: translate3d(0, 100%, 0); |
| 199 | + } |
| 200 | + to { |
| 201 | + opacity: 1; |
| 202 | + transform: none; |
| 203 | + } |
| 204 | +} |
| 205 | +@-webkit-keyframes fadeInUp { |
| 206 | + from { |
| 207 | + opacity: 0.5; |
| 208 | + transform: translate3d(0, 100%, 0); |
| 209 | + } |
| 210 | + to { |
| 211 | + opacity: 1; |
| 212 | + transform: none; |
| 213 | + } |
| 214 | +} |
| 215 | +@-o-keyframes fadeInUp { |
| 216 | + from { |
| 217 | + opacity: 0.5; |
| 218 | + transform: translate3d(0, 100%, 0); |
| 219 | + } |
| 220 | + to { |
| 221 | + opacity: 1; |
| 222 | + transform: none; |
| 223 | + } |
| 224 | +} |
| 225 | +@keyframes fadeInUp { |
| 226 | + from { |
| 227 | + opacity: 0.5; |
| 228 | + transform: translate3d(0, 100%, 0); |
| 229 | + } |
| 230 | + to { |
| 231 | + opacity: 1; |
| 232 | + transform: none; |
| 233 | + } |
| 234 | +} |
| 235 | +</style> |
0 commit comments