YaVendio Registry
Components

YA Sonner

Toast notification component built on Sonner with semantic variants for feedback messages

The YaSonner is the toast notification component of the YaVendio Design System. Built on top of Sonner, it provides semantic variants for different types of feedback: default, success, info, warning, and error/destructive.

Styling approach:

  • default and error toasts use custom YaVendio design tokens from Figma
  • success, info, and warning toasts use Sonner's richColors (enabled by default)

Supports customizable title, description, action buttons, and close button on hover.

Quick Start

pnpm dlx shadcn@latest add @yavendio/ya-sonner
npx shadcn@latest add @yavendio/ya-sonner
yarn dlx shadcn@latest add @yavendio/ya-sonner

Add the YaSonner component to your root layout:

app/layout.tsx
import { YaSonner } from '@/components/ui/ya-sonner'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        {children}
        <YaSonner />
      </body>
    </html>
  )
}

Then use the toast function anywhere in your app:

import { toast } from '@/components/ui/ya-sonner'

export default function Example() {
  return (
    <button onClick={() => toast('Event created successfully')}>
      Show Toast
    </button>
  )
}

Toast Types

Five semantic variants for different types of feedback.

TypeUsageColorsStyling
defaultGeneral messagesStone (neutral)YaVendio tokens
successConfirmations, completionsGreenSonner richColors
infoInformational noticesBlueSonner richColors
warningWarnings, cautionsOrangeSonner richColors
errorErrors, failuresDestructive (red)YaVendio tokens
import { toast } from '@/components/ui/ya-sonner'

// Default toast
toast('Default message')

// Success
toast.success('Changes saved!')

// Info
toast.info('Important information')

// Warning
toast.warning('Warning')

// Error/Destructive
toast.error('Something went wrong')

With Title and Description

Add context with a title and description.

toast('Are you absolutely sure?', {
  description: 'This action cannot be undone.',
})

With Action

Add an action button for user interaction.

toast('Event has been created', {
  description: 'Sunday, December 3, 2023 at 9:00 AM',
  action: {
    label: 'Undo',
    onClick: () => console.log('Undo'),
  },
})

Destructive

For error states and critical failures.

toast.error('Uh oh! Something went wrong.', {
  description: 'There was a problem with your request.',
  action: {
    label: 'Retry',
    onClick: () => retryOperation(),
  },
})

Promise

Show loading, success, and error states for async operations.

toast.promise(saveChanges(), {
  loading: 'Saving...',
  success: (data) => `${data.name} has been saved`,
  error: 'Error saving changes',
})

All Variants

Complete overview of all toast types with actions.

Positioning

Control where toasts appear on screen.

<YaSonner position="top-left" />
<YaSonner position="top-center" />
<YaSonner position="top-right" />
<YaSonner position="bottom-left" />
<YaSonner position="bottom-center" />
<YaSonner position="bottom-right" /> {/* Default */}

Dismissing Toasts

// Dismiss a specific toast
const toastId = toast('Loading...')
toast.dismiss(toastId)

// Dismiss all toasts
toast.dismiss()

Duration

Control how long toasts are displayed.

// Custom duration (milliseconds)
toast('Quick message', { duration: 2000 })

// Infinite (user must dismiss)
toast('Important!', { duration: Infinity })

Props

YaSonner (Toaster)

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Toast position
expandbooleanfalseExpand toasts by default
richColorsbooleantrueUse rich colors for success/info/warning variants
closeButtonbooleanfalseShow close button by default
durationnumber4000Default duration in ms
classNamestring-Additional classes

toast() Options

OptionTypeDescription
descriptionstring | ReactNodeSecondary text
action{ label: string; onClick: () => void }Action button
cancel{ label: string; onClick?: () => void }Cancel button
durationnumberOverride default duration
iconReactNodeCustom icon
idstring | numberCustom toast ID

Accessibility

Best Practices

DoDon't
Use appropriate semantic type for contextUse error type for non-error messages
Keep messages concise and actionableLong paragraphs in toast descriptions
Provide undo actions for destructive operationsSilent deletions without feedback
Use promise toasts for async operationsLeave users without loading feedback
Position toasts away from critical UIToasts blocking important content

On this page