3 | 5 | Elegant, responsive and lightweight notification plugin with no dependencies. 6 |
7 | 8 |9 | Documentation 10 |
11 | 12 | # Nuxt Toast 13 | 14 | [![npm version][npm-version-src]][npm-version-href] 15 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 16 | [![License][license-src]][license-href] 17 | [![Nuxt][nuxt-src]][nuxt-href] 18 | 19 | A Nuxt module for easily integrating [iziToast](https://github.com/marcelodolza/iziToast) notifications into your Nuxt 4 application. 20 | 21 | ## Features 22 | 23 | - 🔔 Easily show toast notifications in your Nuxt 4 app 24 | - 🎨 Customizable styles and icons 25 | - ⚡ Supports auto-imported composable (`useToast()` by default) 26 | - 🔧 Fully configurable via `nuxt.config.ts` 27 | - 🔄 Supports changing the composable name dynamically 28 | 29 | ## Quick Setup 30 | 31 | Install the module to your Nuxt application with one command: 32 | 33 | ```bash 34 | npx nuxi module add nuxt-toast 35 | ``` 36 | 37 | ### **Manual Installation** 38 | 39 | If you prefer to install manually, run: 40 | 41 | ```bash 42 | # Using npm 43 | npm install nuxt-toast 44 | 45 | # Using yarn 46 | yarn add nuxt-toast 47 | 48 | # Using pnpm 49 | pnpm add nuxt-toast 50 | 51 | # Using bun 52 | bun add nuxt-toast 53 | ``` 54 | 55 | Then, add it to your Nuxt config: 56 | 57 | ```ts 58 | export default defineNuxtConfig({ 59 | modules: [ 60 | 'nuxt-toast' 61 | ] 62 | }) 63 | ``` 64 | ## 🚀 Usage 65 | 66 | Once installed, you can use `useToast()` anywhere in your Nuxt app: 67 | 68 | ### **Basic Example** 69 | 70 | ```vue 71 | 80 | ``` 81 | 82 | ### **Customizing Toast Appearance & Options** 83 | 84 | ```vue 85 | 95 | ``` 96 | 97 | ### **Dynamically Hiding Toasts** 98 | 99 | ```vue 100 | 115 | ``` 116 | 117 | ### **Configuration Options** 118 | 119 | You can configure the module in your `nuxt.config.ts`: 120 | 121 | ```ts 122 | export default defineNuxtConfig({ 123 | modules: ['nuxt-toast'], 124 | toast: { 125 | composableName: 'useNotification', // Customize the composable name 126 | settings: { 127 | // Global iziToast settings applied to all toasts 128 | rtl: true, 129 | position: 'topCenter', 130 | timeout: 3000, 131 | // ... see https://github.com/marcelodolza/iziToast for all options 132 | } 133 | } 134 | }) 135 | ``` 136 | 137 | #### **Customizing the Composable Name** 138 | 139 | If you've modified the `composableName` in `nuxt.config.ts`: 140 | 141 | ```ts 142 | export default defineNuxtConfig({ 143 | toast: { composableName: 'useNotification' } 144 | }) 145 | ``` 146 | 147 | Then use the updated composable name in your component: 148 | 149 | ```vue 150 | 156 | ``` 157 | 158 | #### **Global iziToast Settings** 159 | 160 | You can pass any [iziToast configuration options](https://github.com/marcelodolza/iziToast#settings) through the `settings` property: 161 | 162 | ```ts 163 | export default defineNuxtConfig({ 164 | toast: { 165 | settings: { 166 | rtl: true, // Right-to-left support 167 | position: 'topRight', // Default position 168 | timeout: 5000, // Default timeout 169 | closeOnEscape: true, // Close on ESC key 170 | closeOnClick: true, // Close on click 171 | pauseOnHover: true, // Pause on hover 172 | // ... and many more options 173 | } 174 | } 175 | }) 176 | ``` 177 | 178 | This ensures consistency with your custom naming convention. 🚀 179 | 180 | 181 | 182 | [npm-version-src]: https://img.shields.io/npm/v/nuxt-toast/latest.svg?style=flat&colorA=020420&colorB=00DC82 183 | [npm-version-href]: https://npmjs.com/package/nuxt-toast 184 | [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-toast.svg?style=flat&colorA=020420&colorB=00DC82 185 | [npm-downloads-href]: https://npm.chart.dev/nuxt-toast 186 | [license-src]: https://img.shields.io/npm/l/nuxt-toast.svg?style=flat&colorA=020420&colorB=00DC82 187 | [license-href]: https://npmjs.com/package/nuxt-toast 188 | [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js 189 | [nuxt-href]: https://nuxt.com 190 | 191 | --------------------------------------------------------------------------------