|
2 | 2 |
|
3 | 3 | > Lightweight toast-notification plugin for Vue 3 |
4 | 4 |
|
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @meforma/vue-toaster |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Import in your main.js |
| 14 | + |
| 15 | +```js |
| 16 | +import Toaster from "@incuca/vue3-toaster"; |
| 17 | + |
| 18 | +createApp(App) |
| 19 | + .use(Toaster) |
| 20 | + .mount("#app"); |
| 21 | +``` |
| 22 | + |
| 23 | +Usage in your components with Options API |
| 24 | + |
| 25 | +```js |
| 26 | +this.$toast.show(message, { ...options }); |
| 27 | +this.$toast.success(`Hey! I'm here`); |
| 28 | +this.$toast.error(`Hey! I'm here`); |
| 29 | +this.$toast.warning(`Hey! I'm here`); |
| 30 | +this.$toast.info(`Hey! I'm here`); |
| 31 | +// Close all opened toasts after 3000ms |
| 32 | +setTimeout(this.$toast.clear, 3000); |
| 33 | +``` |
| 34 | + |
| 35 | +Usage with Composition API |
| 36 | + |
| 37 | +```js |
| 38 | +import { inject } from "vue"; |
| 39 | +const toast = inject("toast"); |
| 40 | +toast.show(message, { ...options }); |
| 41 | +``` |
| 42 | + |
| 43 | +## Available options |
| 44 | + |
| 45 | +The API methods accepts these options: |
| 46 | + |
| 47 | +| Attribute | Type | Default | Description | |
| 48 | +| :------------ | :--------------: | :------------: | :---------------------------------------------------------------------------- | |
| 49 | +| message | String | -- | Message text/html (required) | |
| 50 | +| type | String | `default` | `success`, `info`, `warning`, `error` or `default` | |
| 51 | +| position | String | `bottom-right` | `top`, `bottom`, `top-right`, `bottom-right`,`top-left` or `bottom-left` | |
| 52 | +| duration | Number/Boolean | `4000` | Visibility duration in milliseconds or `false` that disables duration | |
| 53 | +| dismissible | Boolean | `true` | Allow user close by clicking | |
| 54 | +| onClick | Function | -- | Do something when user clicks | |
| 55 | +| onClose | Function | -- | Do something after toast gets dismissed | |
| 56 | +| queue | Boolean | `false` | Wait for existing to close before showing new | |
| 57 | +| maxToasts | Number/Boolean | `false` | Defines the max of toasts showed in simultaneous | |
| 58 | +| pauseOnHover | Boolean | `true` | Pause the timer when mouse hover a toast | |
| 59 | +| useDefaultCss | Boolean | `true` | Use default css styles | |
| 60 | + |
5 | 61 | ## License |
6 | 62 |
|
7 | 63 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments