Skip to main content

Toast

Stable

Ephemeral notifications via imperative API. toast() can be called from anywhere — event handlers, async functions, outside React tree. ToastProvider is included in VhyxUIProvider.

FeedbackImperative APIVhyxSeal

Interactive example

Click to trigger different toast variants

Import

tsx
// Imperative API — import anywhere in your app
import { toast } from '@vhyxui/react'

// ToastProvider is already included in VhyxUIProvider
// Place VhyxUIProvider once at your app root
import { VhyxUIProvider } from '@vhyxui/react'

API methods

tsx
toast('Message')                      // default variant
toast.success('Upload complete')      // success (green)
toast.danger('Something failed')      // danger (red)
toast.warning('Low disk space')       // warning (amber)
toast.info('Update available')        // info (blue)

// With options
toast.success('Done', {
  description: 'All 42 files uploaded.',
  duration: 8000,
  action: { label: 'View', onClick: openPanel },
})

// Dismiss
const id = toast('Loading…', { duration: Infinity })
toast.dismiss(id)    // dismiss specific toast
toast.dismiss()      // dismiss all toasts
All toast() variants

States

With action button
Persistent toast (Infinity duration)

Props

toast() options

PropTypeDefaultDescription
message *stringPrimary message text.
descriptionstringSupplementary text rendered below the message.
durationnumber5000Auto-dismiss delay in ms. Pass Infinity to prevent auto-dismiss.
action{ label: string; onClick: () => void }Optional action button rendered inside the toast.
dismissiblebooleantrueShows a dismiss button.

ToastProvider props

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Position of the toast region on screen.
maxToastsnumber5Maximum simultaneous toasts visible.
defaultDurationnumber5000Default auto-dismiss duration for all toasts.

Accessibility

  • Toast region has role="status", aria-live="polite" — toasts are announced at next opportunity.
  • aria-atomic="false" — each toast announced individually, not as a group.
  • Dismiss button has aria-label="Dismiss".
  • For critical messages use toast.danger() which upgrades to aria-live="assertive".
  • Consider duration: Infinity for users who need more time to read notifications.

Keyboard navigation

KeyAction
TabMove focus into the toast region.
EscapeDismiss the focused toast.
EnterActivate the action button if present.

Agent contract

Default VhyxSeal contract shipped with every Toast.

Default contract
{
  "type": "display",
  "intent": "notify",
  "description": "Displays a transient notification message to the user",
  "requires": [],
  "requiredPermissions": [],
  "consequence": "None — display only. Disappears after the configured duration.",
  "affects": [],
  "reversible": false,
  "safetyLevel": "low",
  "requiresConfirmation": false,
  "destructive": false,
  "contractVersion": "0.0.1",
  "fingerprint": "vhyxs_3900ef64"
}

Theming

Override these CSS tokens to theme Toast.

--vhyx-z-toastZ-index (500)
--vhyx-shadow-lgToast shadow
--vhyx-color-surface-raisedToast background
--vhyx-radius-lgToast border radius
--vhyx-duration-normalSlide-in animation duration
--vhyx-easing-springEntry easing

Examples

Async form submission with feedback

Show loading then success or error

Custom provider position

tsx
// In your app root — VhyxUIProvider accepts ToastProvider props
<VhyxUIProvider toastPosition="top-center" toastMaxToasts={3}>
  {children}
</VhyxUIProvider>