Gathering detailed insights and metrics for vue3-toaster
Gathering detailed insights and metrics for vue3-toaster
Gathering detailed insights and metrics for vue3-toaster
Gathering detailed insights and metrics for vue3-toaster
A lightweight and fully customizable toast notification package that for Vue3.
npm install vue3-toaster
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Vue (46.78%)
TypeScript (46.62%)
SCSS (5.47%)
JavaScript (1.13%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
4 Stars
47 Commits
1 Forks
1 Watchers
4 Branches
1 Contributors
Updated on Feb 14, 2025
Latest Version
1.0.0
Package Id
vue3-toaster@1.0.0
Unpacked Size
109.51 kB
Size
23.05 kB
File Count
27
NPM Version
8.11.0
Node Version
16.16.0
Published on
Dec 02, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1
Revolutionize your Vue.js 3 development with vue3-toaster
, a lightweight and fully customizable toast notification package that seamlessly blends into your design, requiring zero third-party dependencies for a cleaner bundle size and offering effortless customization to match your exact design requirements.
Easily integrate toast notifications into your Vue.js components and tailor their look and feel to match your exact requirements.
Easy-to-use composables and plugins for effortless integration.
using NPM
1npm i vue3-toaster
using Yarn
1yarn add vue3-toaster
There are mainly two ways to use vue3-toaster
package.
1//main.ts/.js 2import ToastPlugin from "vue3-toaster"; 3createApp(App) 4 .use(ToastPlugin, { 5 closable: false, 6 //.. other options 7 }) 8 .mount("#app");
1<!-- App.vue --> 2<template> 3 <div> 4 <!-- you don't need to import the ToastContainer component, it's auto imported in plugin --> 5 <ToastContainer /> 6 <!-- Other stuffs --> 7 </div> 8</template>
1import ToastPlugin from "vue3-toaster"; 2export default defineNuxtPlugin((_nuxtApp) => { 3 _nuxtApp.vueApp.use(ToastPlugin, { 4 closable: false, 5 pauseOnHover: false, 6 closeOnDoubleClick: true, 7 // other options ToastContainerConfig 8 }); 9});
1<!-- layouts/default.vue --> 2<template> 3 <div> 4 <!-- you don't need to import the ToastContainer component, it's auto imported in plugin --> 5 <ToastContainer /> 6 <slot /> 7 <!-- Other stuffs --> 8 </div> 9</template>
1<!-- App.vue --> 2<script lang="ts" setup> 3 import { ToastContainer, ToastContainerConfig } from "vue3-toaster"; 4 const defaultOptions: ToastContainerConfig = { 5 pauseOnHover: true, 6 closable: true, 7 closeOnDoubleClick: false, 8 theme: { 9 // 10 }, 11 }; 12</script> 13<template> 14 <div> 15 <ToastContainer v-bind="defaultOptions" /> 16 <!-- Other stuffs --> 17 </div> 18</template>
1<!-- MyComponent.vue --> 2<script lang="ts" setup> 3 import { useToaster } from "vue3-toaster"; 4 function toast() { 5 useToaster().add({ 6 type:'info', 7 title:'Congratulations' 8 text:'You have successfully completed.' 9 }); 10 useToaster().success('this is My success toaster'); 11 } 12</script> 13<template> 14 <div> 15 <!-- Your component templated here --> 16 </div> 17</template>
CodeSandBox Composition Api example
for Nuxt js project code would be same, you just need to put
1<!-- layouts/default.vue --> 2<script lang="ts" setup> 3 import { 4 ToastContainer, 5 ToastContainerConfig, 6 useToasterConfig, 7 } from "vue3-toaster"; 8 const defaultOptions: ToastContainerConfig = { 9 pauseOnHover: true, 10 closable: true, 11 closeOnDoubleClick: false, 12 theme: { 13 // 14 }, 15 }; 16 useToasterConfig().update(defaultOptions); 17</script> 18<template> 19 <div> 20 <!-- you don't need to import the ToastContainer component, it's auto imported in plugin --> 21 <ToastContainer /> 22 <slot /> 23 <!-- Other stuffs --> 24 </div> 25</template>
Please Note:- <ToastContainer v-bind="defaultOptions"/>
and useToasterConfig().update(defaultOptions);
are alternative of each other it's recommended to use only one of them.
1import { useToaster } from "vue3-toaster"; 2// let for some use case I want only this toast message to be cleared after some event executed 3function performSomeTask() { 4 const ToasterId = useToaster().add({ 5 title: "Server Error", 6 type: "error", 7 text: "Please try again after some time.", 8 }); 9 // in next try we got success response so we don't want it to be visible so we will remove it. 10 useToaster().remove(ToasterId); 11}
(Composition API)
)1import { useToaster } from "vue3-toaster"; 2const toaster = inject("$toaster"); 3const ToasterId = toaster.add({ 4 title: Congratulations, 5 type: success, 6 text: "You have Done it.", 7});
this
(if registerd as a plugin (Option API)
)1export default { 2 methods: { 3 fireToast() { 4 const ToasterId = this.$toaster.add({ 5 title: Congratulations, 6 type: success, 7 text: "You have Done it.", 8 }); 9 }, 10 }, 11};
CodeSandBox Option Api example
this.$toaster
only works in Option API if you have registered as Pluginname | description |
---|---|
ToastVariant | main Cont |
ToastContainerTheme | Interface for Theme |
ToastContainerConfig | Interface for available option for plugin registration |
ToastProps | Interface for Toast message |
ToastSlotType | Available Slots for component |
1type ToastVariant = "warn" | "success" | "info" | "error";
1export type ToastContainerTheme = { 2 zIndex: string | number; 3 top: string; 4 bottom: string; 5 left: string; 6 right: string; 7 iconSize: string; 8 successColor: string; 9 warnColor: string; 10 infoColor: string; 11 errorColor: string; 12 gray: string; 13 toasterMaxWidth: string; 14 animationDuration: number; 15 animationFunction: 16 | "linear" 17 | "ease" 18 | "ease-in" 19 | "ease-out" 20 | "ease-in-out" 21 | "step-end" 22 | "step-start" 23 | `cubic-bezier(${number},${number},${number},${number})`; 24 toastBackgroundColor: string; 25 translateX: string; 26 direction: -1 | 1; 27};
1export type ToastContainerConfig = { 2 theme: Partial<ToastContainerTheme>; 3 pauseOnHover: boolean; 4 closable: boolean; 5 closeOnDoubleClick: boolean; 6 duration: number; 7};
1type ToastSlotProps = Readonly< 2 ToastProps & { 3 destroyToaster: () => void; 4 pauseCountdown: (value: boolean) => void; 5 } 6>;
1export type ToastSlotType = { 2 default(props: ToastSlotProps): any; 3 icon(props: Pick<ToastSlotProps, "type">): any; 4 clearIcon(props: {}): any; 5 content(props: Pick<ToastSlotProps, "type" | "text" | "title">): any; 6};
1export interface ToastProps { 2 id: string; 3 title: string; 4 type: ToastVariant; 5 text: string; 6 options: Partial<Exclude<ToastContainerConfig, "theme">>; 7}
1export interface Toaster { 2 add(_toastObj: Partial<ToastProps>): string; 3 success(message: string): string | undefined; 4 info(message: string): string | undefined; 5 warn(message: string): string | undefined; 6 error(message: string): string | undefined; 7 remove(_toastId: string): string | void; 8 clear(_toastIds?: string[]): void; 9 toasters: ComputedRef<ToastProps[]>; 10}
1interface UseToasterConfigType { 2 update(Option: ToastContainerConfig): ComputedRef<ToastContainerConfig>; 3 all: ComputedRef<ToastContainerConfig>; 4 cssVariables: Record<string, string>; 5}
1import ToastContainer from "../components/ToastContainer.vue"; 2 3interface PluginProperties{ 4 $toaster: Toaster; 5 ToastContainer: typeof ToastContainer; 6 globalProperties: { 7 $toaster: Toaster; 8 }; 9 }
name | Interface | description |
---|---|---|
useToaster | Toaster | Composable to manipulate toaster |
useToasterConfig | UseToasterConfigType | Composable to manipulate toaster Config |
It implements the Toaster interface, following are the purpose of it's methods and data.
useToaster().add()
method is the most flexible method, it takes Partial<ToastProps>
as argument where you can define the title if you want to use it different than the native titles and many more option to control the UI and UX. You can check the ToastProps interface for more details.useToaster().success()
accept string and create toaster with title as Success
.useToaster().info()
accept string and create toaster with title as Information
.useToaster().warn()
accept string and create toaster with title as Warning
.useToaster().error()
accept string and create toaster with title as Error
.Note: - All above methods return a unique uuid that can be use to manually remove the toast component before it expired.
It take cares of configuration of theme and options, it implements UseToasterConfigType, it has following methods
useToasterConfig().update()
method is used to update the global config of toaster.
note:- Alternatively you can pass props in <ToastContainer/>
component same as shown in the Vue.js project section
useToasterConfig().all
it return the all applied global configurations.useToasterConfig().cssVariables
it return the converted global theme options values in css variables.1export const defaultConfig: ToastContainerConfig = { 2 theme: { 3 zIndex: 9999, 4 top: "0", 5 bottom: "auto", 6 left: "0", 7 right: "auto", 8 iconSize: "40px", 9 successColor: "#2bde3f", 10 warnColor: "#ffc007", 11 infoColor: "#1d72f3", 12 errorColor: "#de0909", 13 gray: "#aaaaaa", 14 toasterMaxWidth: "500px", 15 animationDuration: 1000, 16 animationFunction: "ease-in-out", 17 translateX: "200px", 18 direction: 1, 19 toastBackgroundColor: "#ffff", 20 }, 21 closable: true, 22 pauseOnHover: true, 23 closeOnDoubleClick: true, 24 duration: 10, 25};
Slots interface had been defined here ToastSlotType, there are 4 slots provided by the component.
1interface { 2 id: string; 3 title: string; 4 type: ToastVariant; 5 text: string; 6 destroyToaster: () => void; 7 pauseCountdown: (value: boolean) => void; 8} 9
1interface { 2 type: "warn" | "success" | "info" | "error"; 3 title: string; 4}
1interface { 2}
1interface { 2 type: "warn" | "success" | "info" | "error"; 3 title: string; 4 text: string; 5}
No vulnerabilities found.
No security vulnerabilities found.