Skip to content

Getting Started

Install

bash
npm install @notifi/vue

Headless by design

Notifi is headless and ships no styles. You can render plain text, or integrate any UI kit/component (e.g., your design system) as the notification content.

Mount

Use the NotifContainer component to render and manage notifications.

vue
<template>
  <NotifContainer />
</template>
<script setup lang="ts">
import { NotifContainer } from '@notifi/vue'
</script>

Show a notification

ts
import { notif } from '@notifi/vue'

const id = notif('Hello Notifi!', { duration: 2500 })

function closeNotification() {
  notif.dismiss(id)
}

function closeAllNotifications() {
  notif.dismiss()
}

API

ts
import { notif } from '@notifi/vue'

// Dismiss by id
notif.dismiss(id)

// Dismiss all
notif.dismiss()

// Get full history (including dismissed until cleaned)
const history = notif.getHistory()

// Get active notifications (not dismissed)
const active = notif.getNotifications()

Notification parameters (ExternalNotification)

nametypedefaultdescription
idstring | numberauto-generatedOptional custom id for the notification. Useful for targeted dismiss/update.
classstring-Extra class applied to the notification root.
styleCSSProperties-Inline styles; supports CSS variables like --notifi-*.
durationnumberlibrary defaultAuto close delay in ms. Use Infinity to disable auto close.
dismissiblebooleantrueWhether the notification can be dismissed via swipe/click.
noPauseOnHoverbooleanfalseIf true, hovering will not pause the auto-close timer.
onDismiss(notification) => void-Called when the notification is dismissed manually or by swipe.
onAutoClose(notification) => void-Called when the notification is closed by timer.
position'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end'container defaultPosition override per notification.
testIdstring-Testing id set on the notification element.
notificationContainerIdstring-Send notification to a specific NotifContainer instance with matching id.

NotifContainer props (NotificationContainerProps)

nametypedefaultdescription
idstring-Identifier to isolate notifications for this NotifContainer instance.
position'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end''bottom-end'Default position for notifications without an explicit position.
expandbooleanfalseExpand the stack on hover/interact.
gapnumber8Gap between stacked notifications (px).
widthnumber448Width of the notification list (px).
visibleNotificationsnumber5How many notifications are visible in the stack.
durationnumber-Default duration for notifications created while this container is mounted.
notificationOptionsNotificationOptions{}Default options applied to each created notification.
classstring``Extra class on the notification list (ol[data-notifi-notifer]).
rootClassstring``Extra class on the outer container section[data-notifi-container].
styleCSSProperties-Inline styles; can provide --notifi-* CSS variables per container.
ariaLabelstring"Notifications"Accessible label for the live region.
offset{ top?; end?; bottom?; start? } | string | number32 (px)Viewport offsets for desktop. Numbers are px; strings accept any CSS length.
mobileOffset{ top?; end?; bottom?; start? } | string | number16 (px)Viewport offsets for mobile (applied under 600px).
absolutebooleanfalsePosition container absolutely instead of fixed.
swipeDirectionsArray<'top' | 'right' | 'bottom' | 'left'>['left','right']Allowed swipe-to-dismiss directions.

Custom notification component props (NotificationComponentProps)

When creating a custom notification component library integration, you receive several props from Notifi:

nametypedescription
pausedbooleanWhether the notification timer is currently paused (user hovering).
onCloseNotification() => voidCall this function to programmatically dismiss the notification.
onUpdateHeight() => voidCall this when your component height changes to update layout calculations.
durationnumberOriginal duration of the notification in milliseconds.
remainingTimenumberRemaining time until auto-close (not reactive - update manually on pause/resume).

Example custom component integration

ts
import { h, defineComponent, type PropType } from 'vue'
import type { NotificationComponentProps } from '@notifi/core'

// Your custom toast component
const CustomToast = defineComponent({
  props: {
    title: String,
    message: String,
    // NotificationComponentProps from Notifi
    ...({} as PropType<NotificationComponentProps>)
  },
  setup(props) {
    return () => h('div', {
      class: 'custom-toast',
      onClick: () => props.onCloseNotification?.()
    }, [
      h('h4', props.title),
      h('p', props.message),
      // Show remaining time
      h('small', `${Math.round(props.remainingTime)}ms left`)
    ])
  }
})

// Create notification with custom component
notif(h(CustomToast, {
  title: 'Success!',
  message: 'Your data has been saved.'
}), {
  duration: 5000,
  dismissible: true
})

Best practices for custom components

  • Handle height changes: Call onUpdateHeight() when your component size changes (e.g., dynamic content, icon loading).
  • Respect auto-pause: Check the paused prop to show/hide pause indicators in your UI.
  • Provide dismiss action: Use onCloseNotification() for close buttons or swipe gestures.
  • Duration integration: Use remainingTime to show progress bars or countdown timers (note: not reactive).