Efferd

Sonner

Component 6

About

a colorfull Sonner

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Sonner to your project and fits it to your theme.

Code

How Sonner is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

'use client';
import { Button } from '@/components/ui/button';
import { Toaster } from '@/components/ui/sonner';
import { toast } from 'sonner';
import React from 'react';

export default function DemoOne() {
	const [activeType, setActiveType] = React.useState(allTypes[0]);

	return (
		<div className="relative flex min-h-screen w-full items-start justify-center">
			<Toaster />
			<div className="max-w-md space-y-5 pt-32">
				<div className="flex flex-wrap gap-2">
					{allTypes.map((type) => (
						<Button
							data-active={activeType.name === type.name}
							onClick={() => {
								type.action();
								setActiveType(type);
							}}
							key={type.name}
						>
							{type.name}
						</Button>
					))}
				</div>
				<div className="w-full h-full border p-2 rounded-md text-muted-foreground">
				<code>
					{activeType.snippet}
				</code>
				</div>
			</div>
		</div>
	);
}

const promiseCode = '`${data.name} toast has been added`';

const allTypes = [
	{
		name: 'Default',
		snippet: `toast('Event has been created')`,
		action: () => toast('Event has been created'),
	},
	{
		name: 'Description',
		snippet: `toast.message('Event has been created', {
  description: 'Monday, January 3rd at 6:00pm',
})`,
		action: () =>
			toast('Event has been created', {
				description: 'Monday, January 3rd at 6:00pm',
			}),
	},
	{
		name: 'Success',
		snippet: `toast.success('Event has been created')`,
		action: () => toast.success('Event has been created'),
	},
	{
		name: 'Info',
		snippet: `toast.info('Be at the area 10 minutes before the event time')`,
		action: () => toast.info('Be at the area 10 minutes before the event time'),
	},
	{
		name: 'Warning',
		snippet: `toast.warning('Event start time cannot be earlier than 8am')`,
		action: () => toast.warning('Event start time cannot be earlier than 8am'),
	},
	{
		name: 'Error',
		snippet: `toast.error('Event has not been created')`,
		action: () => toast.error('Event has not been created'),
	},
	{
		name: 'Action',
		snippet: `toast('Event has been created', {
  action: {
    label: 'Undo',
    onClick: () => console.log('Undo')
  },
})`,
		action: () =>
			toast.message('Event has been created', {
				action: {
					label: 'Undo',
					onClick: () => console.log('Undo'),
				},
			}),
	},
	{
		name: 'Promise',
		snippet: `const promise = () => new Promise(
		(resolve) => setTimeout(() => resolve({ name: 'Sonner' }), 2000));

toast.promise(promise, {
  loading: 'Loading...',
  success: (data) => {
    return ${promiseCode};
  },
  error: 'Error',
});`,
		action: () =>
			toast.promise<{ name: string }>(
				() =>
					new Promise((resolve) => {
						setTimeout(() => {
							resolve({ name: 'Sonner' });
						}, 2000);
					}),
				{
					loading: 'Loading...',
					success: (data) => {
						return `${data.name} toast has been added`;
					},
					error: 'Error',
				},
			),
	},
	{
		name: 'Custom',
		snippet: `toast(<div>A custom toast with default styling</div>)`,
		action: () => toast(<div>A custom toast with default styling</div>, { duration: 1000000 }),
	},
];

Dependencies

More by Efferd

View all
  • Testimonials Columns

    Testimonials Columns

    7.1K
  • Zoom Parallax

    Zoom Parallax

    5.2K
  • Dotted Surface

    Dotted Surface

    3.5K
  • Footer Section

    Footer Section

    2.7K
  • Grid Feature Cards

    Grid Feature Cards

    1.9K
  • Logo Cloud 2

    Logo Cloud 2

    1.6K
  • Header 3

    Header 3

    1.6K
  • Logo Cloud 3

    Logo Cloud 3

    1.5K