Gathering detailed insights and metrics for vue-sonner
Gathering detailed insights and metrics for vue-sonner
Gathering detailed insights and metrics for vue-sonner
Gathering detailed insights and metrics for vue-sonner
npm install vue-sonner
Typescript
Module System
Node Version
NPM Version
99.4
Supply Chain
100
Quality
90.1
Maintenance
100
Vulnerability
100
License
Vue (64.93%)
TypeScript (31.39%)
CSS (1.85%)
JavaScript (1.3%)
HTML (0.53%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,150 Stars
258 Commits
62 Forks
2 Watchers
3 Branches
25 Contributors
Updated on Jun 29, 2025
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
vue-sonner@2.0.1
Unpacked Size
198.47 kB
Size
47.22 kB
File Count
31
NPM Version
10.9.2
Node Version
22.14.0
Published on
Jun 23, 2025
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
25
An opinionated toast component for Vue. It's a Vue port of Sonner
https://user-images.githubusercontent.com/6118824/228208185-be5aefd4-7fa8-4f95-a41c-88a60c0e2800.mp4
Vue Sonner
is an opinionated toast component for Vue. It's customizable, but styled by default. Comes with a swipe to dismiss animation.
To start using the library, install it in your project:
1pnpm install vue-sonner 2or 3yarn add vue-sonner
To run the test you need two separate CLI window :
To launch the test, you need to go in the test directory
1cd ./test
and launch the following command
1cd ./test 2pnpm test:e2e --ui
This command will build the vue-sonner library in lib mode, and add a watch so every time you modify the code of the library, you will have a new bundle and can run the test again.
1pnpm build:dev
1<!-- App.vue --> 2<template> 3 <Toaster /> 4 <button @click="() => toast('My first toast')">Render a toast</button> 5</template> 6 7<script lang="ts" setup> 8 import 'vue-sonner/style.css' 9 import { Toaster, toast } from 'vue-sonner' 10</script>
Use vue-sonner/nuxt
module
1// nuxt.config.ts
2export default defineNuxtConfig({
3 ...
4 modules: ['vue-sonner/nuxt']
5 vueSonner: {
6 css: false // true by default to include css file
7 }
8})
Use Toaster
component and $toast
function anywhere in the Vue SFC
1<!-- app.vue --> 2<template> 3 <div> 4 <Toaster position="top-right" /> 5 <button @click="() => $toast('My first toast')">Render a toast</button> 6 </div> 7</template> 8 9<script setup lang="ts"> 10 const { $toast } = useNuxtApp() 11</script>
EMS version
1https://cdn.jsdelivr.net/npm/vue-sonner/+esm
Most basic toast. You can customize it (and any other type) by passing an options object as the second argument.
1toast('Event has been created')
With custom description:
1toast('Event has been created', { 2 description: 'Monday, January 3rd at 6:00pm' 3})
Renders a checkmark icon in front of the message.
1toast.success('Event has been created')
Renders an error icon in front of the message.
1toast.error('Event has not been created')
Renders a button.
1toast('Event has been created', { 2 action: { 3 label: 'Undo', 4 onClick: () => console.log('Undo') 5 } 6})
Starts in a loading state and will update automatically after the promise resolves or fails.
You can pass a function to the success/error messages to incorporate the result/error of the promise.
1toast.promise(() => new Promise((resolve) => setTimeout(resolve, 2000)), { 2 loading: 'Loading', 3 success: (data: any) => 'Success', 4 error: (data: any) => 'Error' 5})
You can pass a Vue Component as the first argument instead of a string to render custom Component while maintaining default styling. You can use the headless version below for a custom, unstyled toast.
1<script lang="ts" setup> 2 import { defineComponent, h, markRaw } from 'vue' 3 4 const CustomDiv = defineComponent({ 5 setup() { 6 return () => 7 h('div', { 8 innerHTML: 'A custom toast with unstyling' 9 }) 10 } 11 }) 12 13 toast(markRaw(CustomDiv)) 14</script>
You can use toast.custom
to render an unstyled toast with custom jsx while maintaining the functionality.
1<script lang="ts" setup> 2import { markRaw } from 'vue' 3 4import HeadlessToast from './HeadlessToast.vue' 5 6toast.custom(markRaw(HeadlessToast), { duration: 999999 }) 7</script>
You can change the theme using the theme
prop. Default theme is light.
1<Toaster theme="dark" />
You can change the position through the position
prop on the <Toaster />
component. Default is top-right
.
1<!-- Available positions --> 2<!-- top-left, top-center, top-right, bottom-left, bottom-center, bottom-right --> 3 4<Toaster position="top-center" />
Toasts can also be expanded by default through the expand
prop. You can also change the amount of visible toasts which is 3 by default.
1<Toaster expand :visibleToasts="9" />
You can style your toasts globally with the toastOptions
prop in the Toaster
component.
1<Toaster 2 :toastOptions="{ 3 style: { background: 'red' }, 4 class: 'my-toast', 5 descriptionClass: 'my-toast-description' 6 }" 7/>
1toast('Event has been created', { 2 style: { 3 background: 'red' 4 }, 5 class: 'my-toast', 6 descriptionClass: 'my-toast-description' 7})
The preferred way to style the toasts with tailwind is by using the unstyled
prop. That will give you an unstyled toast which you can then style with tailwind.
1<Toaster 2 :toastOptions="{ 3 unstyled: true, 4 classes: { 5 toast: 'bg-blue-400', 6 title: 'text-red-400', 7 description: 'text-red-400', 8 actionButton: 'bg-zinc-400', 9 cancelButton: 'bg-orange-400', 10 closeButton: 'bg-lime-400' 11 } 12 }" 13/>
You can do the same when calling toast()
.
1toast('Hello World', { 2 unstyled: true, 3 classes: { 4 toast: 'bg-blue-400', 5 title: 'text-red-400 text-2xl', 6 description: 'text-red-400', 7 actionButton: 'bg-zinc-400', 8 cancelButton: 'bg-orange-400', 9 closeButton: 'bg-lime-400' 10 } 11})
Styling per toast type is also possible.
1<Toaster 2 :toastOptions="{ 3 unstyled: true, 4 classes: { 5 error: 'bg-red-400', 6 success: 'text-green-400', 7 warning: 'text-yellow-400', 8 info: 'bg-blue-400' 9 } 10 }" 11/>
You can change the default icons using slots:
1<Toaster> 2 <template #loading-icon> 3 <LoadingIcon /> 4 </template> 5 <template #success-icon> 6 <SuccessIcon /> 7 </template> 8 <template #error-icon> 9 <ErrorIcon /> 10 </template> 11 <template #info-icon> 12 <InfoIcon /> 13 </template> 14 <template #warning-icon> 15 <WarningIcon /> 16 </template> 17</Toaster>
Add a close button to all toasts that shows on hover by adding the closeButton
prop.
1<Toaster closeButton />
You can make error and success state more colorful by adding the richColors
prop.
1<Toaster richColors />
Offset from the edges of the screen.
1<Toaster offset="80px" />
You can pass onDismiss
and onAutoClose
callbacks. onDismiss
gets fired when either the close button gets clicked or the toast is swiped. onAutoClose
fires when the toast disappears automatically after it's timeout (duration
prop).
1toast('Event has been created', { 2 onDismiss: (t) => console.log(`Toast with id ${t.id} has been dismissed`), 3 onAutoClose: (t) => 4 console.log(`Toast with id ${t.id} has been closed automatically`) 5})
You can change the duration of each toast by using the duration property, or change the duration of all toasts like this:
1<Toaster :duration="10000" />
1toast('Event has been created', { 2 duration: 10000 3}) 4 5If you want a toast to stay on screen forever, you can set the duration to `Infinity`. 6 7// Persisent toast 8toast('Event has been created', { 9 duration: Infinity 10})
To remove a toast programmatically use toast.dismiss(id)
.
1const toastId = toast('Event has been created') 2 3toast.dismiss(toastId)
You can also dismiss all toasts at once by calling toast.dismiss()
without an id.
1toast.dismiss()
You can focus on the toast area by pressing ⌥/alt + T. You can override it by providing an array of event.code values for each key.
1<Toaster hotkey="['KeyC']" />
MIT @xiaoluoboding
No vulnerabilities found.
No security vulnerabilities found.
vuetify-sonner
Stackable toast component for Vuetify.
@hoppscotch/vue-sonner
[![NPM][npmBadge]][npmUrl] [![Minzip Package][bundlePhobiaBadge]][bundlePhobiaUrl] [![NPM Download][npmDtBadge]][npmDtUrl]
vue-sonner-test
[![NPM][npmBadge]][npmUrl] [![Minzip Package][bundlePhobiaBadge]][bundlePhobiaUrl] [![NPM Download][npmDtBadge]][npmDtUrl]
@neoncoder/vuetify-sonner
Stackable toast component for Vuetify.