Sonner
A toast notification system for displaying brief, non-intrusive messages.
Usage
import { Toaster, toast } from '@acronis-platform/shadcn-uikit';Add <Toaster /> to your root layout, then call toast() anywhere in your app.
Basic
A simple toast notification.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerBasic() {
return (
<Button onClick={() => toast('Event has been created')}>Show Toast</Button>
);
}
With Description
Toast with a title and description body.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerWithDescription() {
return (
<Button
onClick={() =>
toast('Event has been created', {
description: 'Sunday, December 03, 2023 at 9:00 AM',
})
}
>
Show Toast with Description
</Button>
);
}
Success
A success-styled toast notification.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerSuccess() {
return (
<div className="flex flex-wrap gap-3">
<Button onClick={() => toast.success('Successfully saved!')}>
Success
</Button>
<Button
onClick={() =>
toast.success('Profile updated', {
description: 'Your profile has been updated successfully.',
})
}
>
Success with Description
</Button>
</div>
);
}
Error
An error-styled toast notification.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerError() {
return (
<div className="flex flex-wrap gap-3">
<Button onClick={() => toast.error('Something went wrong')}>Error</Button>
<Button
onClick={() =>
toast.error('Failed to save', {
description:
'There was an error saving your changes. Please try again.',
})
}
>
Error with Description
</Button>
</div>
);
}
Warning
A warning-styled toast notification.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerWarning() {
return (
<div className="flex flex-wrap gap-3">
<Button onClick={() => toast.warning('Low disk space')}>Warning</Button>
<Button
onClick={() =>
toast.warning('Storage warning', {
description:
'Your storage is almost full. Please free up some space.',
})
}
>
Warning with Description
</Button>
</div>
);
}
With Action
Toast with an action button the user can click.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerWithAction() {
return (
<Button
onClick={() =>
toast('Event has been created', {
description: 'Sunday, December 03, 2023 at 9:00 AM',
action: {
label: 'Undo',
onClick: () => toast.success('Undo successful'),
},
})
}
>
Toast with Action
</Button>
);
}
Promise
Toast that tracks a promise lifecycle (loading, success, error).
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerPromise() {
return (
<Button
onClick={() => {
const promise = () =>
new Promise((resolve) =>
setTimeout(() => resolve({ name: 'Sonner' }), 2000)
);
toast.promise(promise, {
loading: 'Loading...',
success: (data: any) => {
return `${data.name} toast has been added`;
},
error: 'Error',
});
}}
>
Promise Toast
</Button>
);
}
Positions
Toasts displayed at different screen positions.
View sourceHide source
import { toast } from '@acronis-platform/shadcn-uikit/react';
import { Button } from '@acronis-platform/shadcn-uikit/react';
export function SonnerPositions() {
return (
<div className="grid grid-cols-3 gap-3">
<Button onClick={() => toast('Top Left', { position: 'top-left' })}>
Top Left
</Button>
<Button onClick={() => toast('Top Center', { position: 'top-center' })}>
Top Center
</Button>
<Button onClick={() => toast('Top Right', { position: 'top-right' })}>
Top Right
</Button>
<Button onClick={() => toast('Bottom Left', { position: 'bottom-left' })}>
Bottom Left
</Button>
<Button
onClick={() => toast('Bottom Center', { position: 'bottom-center' })}
>
Bottom Center
</Button>
<Button
onClick={() => toast('Bottom Right', { position: 'bottom-right' })}
>
Bottom Right
</Button>
</div>
);
}
API Reference
Toaster
Prop
Type
The Toaster component pre-configures theme integration, custom icons for each toast type, and Acronis-branded styling. Use the toast() function to trigger notifications: toast(), toast.success(), toast.error(), toast.warning(), toast.info(), toast.loading(), toast.promise().