Skip to content

Snackbar API Reference ​

Props ​

The Snackbar component doesn't accept direct props as it works through the useSnackbar composable.

Composable: useSnackbar ​

The Snackbar component is controlled through the useSnackbar composable which provides the following interface:

Methods ​

MethodParametersDescription
showSnackbaroptions (Object)Display a snackbar notification with the specified configuration
removeNotification-Remove the currently displayed notification
clearAll-Alias for removeNotification
successprimaryMessage (String), options (Object)Show a success notification with convenience method
errorprimaryMessage (String), options (Object)Show an error notification (isPersistent: true by default)
warningprimaryMessage (String), options (Object)Show a warning notification with convenience method
infoprimaryMessage (String), options (Object)Show an info notification with convenience method

Configuration Methods ​

MethodParametersDescription
setPositionposition (String)Set the default position for snackbar notifications
setOffsetx (Number), y (Number)Set the offset from position in rem units
setDefaultTimeouttimeout (Number)Set the default auto-dismiss timeout in milliseconds

showSnackbar Options ​

The options object passed to showSnackbar has the following structure:

PropertyTypeDefaultDescription
typeString'info'Notification type: 'success', 'error', 'warning', 'info'
primaryMessageStringRequiredMain message text to display
secondaryMessageStringnullSecondary/subtitle message text
timeoutNumber4000Auto-dismiss timeout in milliseconds (0 for no auto-dismiss)
isPersistentBooleanfalseWhether the notification should persist until manually closed
showCloseButtonBooleantrueWhether to show the close button
iconStringnullCustom HTML string for icon (uses default icons if not provided)
positionStringconfig.value.positionOverride position for this notification (uses global config if not provided)

Default Configuration ​

The composable provides a config object for global settings:

PropertyTypeDefaultDescription
positionString'bottom'Default position for notifications (can be overridden per-notification)
offsetObject{ x: 1, y: 1 }Default offset from position in rem units
defaultTimeoutNumber4000Default auto-dismiss timeout in milliseconds

Valid Positions ​

The following positions are supported:

  • 'top-left'
  • 'top'
  • 'top-right'
  • 'bottom-left'
  • 'bottom'
  • 'bottom-right'

Events ​

The Snackbar component doesn't emit events directly, but the composable provides reactive state:

PropertyTypeDescription
notificationObject | nullCurrent notification object or null if none displayed
hasNotificationBooleanWhether a notification is currently displayed
notificationPositionStringCurrent notification position

Notification Object Structure ​

The notification object returned by the composable has the following structure:

PropertyTypeDescription
idStringUnique identifier for the notification
typeStringNotification type
primaryMessageStringMain message text
secondaryMessageString | nullSecondary message text
iconRefStringHTML string for the icon
showCloseButtonBooleanWhether close button is shown
timeoutNumberAuto-dismiss timeout
isPersistentBooleanWhether notification persists
notificationClassArrayCSS classes applied to notification (includes type class)
createdAtNumberTimestamp when notification was created
timeoutIdNumber | nullInternal timeout ID for auto-dismiss
positionStringPosition for this notification (overrides global config if provided)

Slots ​

The Snackbar component doesn't use slots as content is provided through the notification object.

CSS Classes ​

The component uses the following CSS classes that can be customized:

ClassDescription
.snackbar-containerMain container for positioning
.snackbar-notificationIndividual notification element
.snackbar-contentContent wrapper with flex layout
.snackbar-iconIcon container
.snackbar-messagesMessages container
.snackbar-primary-messagePrimary message text
.snackbar-secondary-messageSecondary message text
.snackbar-close-buttonClose button element
.successSuccess notification styling
.errorError notification styling
.warningWarning notification styling
.infoInfo notification styling

Position Classes ​

The component automatically applies position classes:

ClassDescription
.position-topTop center position
.position-bottomBottom center position
.position-top-leftTop left position
.position-top-rightTop right position
.position-bottom-leftBottom left position
.position-bottom-rightBottom right position

Dependencies ​

The Snackbar component depends on:

  • useSnackbar composable for state management
  • Browser's crypto.randomUUID() or fallback ID generation
  • convertRemToPixels inject for responsive positioning (optional, falls back to computed rem conversion)