toast/01-toast-basic-toast
A simple toast notification. Click the button to trigger a toast message with default styling.
Loading interactive preview
Temporary notification messages.
import { useRef } from 'react';
import { Button } from 'ui-lab-components/button';
import { toast, Toaster } from 'ui-lab-components/toast';
export function Example() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div
ref={containerRef}
className="relative isolate flex min-h-64 w-full self-stretch items-center justify-center overflow-hidden"
>
<Button
size="sm"
onClick={() =>
toast({
toasterId: "toast-playground",
title: "Notification",
description: "This is a toast message",
variant: "default",
position: "bottom-right",
duration: 5000,
})
}
>
Show Toast
</Button>
<Toaster
toasterId="toast-playground"
container={() => containerRef.current}
/>
</div>
);
}A simple toast notification. Click the button to trigger a toast message with default styling.
import { Button } from 'ui-lab-components/button'
import { toast } from 'ui-lab-components/toast'
import { Toaster } from 'ui-lab-components/toast';
export const metadata = {
title: 'Basic Toast',
description: 'A simple toast notification. Click the button to trigger a toast message with default styling.'
};
export default function Example() {
return (
<>
<Button
size="sm"
onClick={() => toast({ toasterId: 'basic-toast', title: 'Notification', description: 'This is a toast message' })}>
Show Toast
</Button>
<Toaster toasterId="basic-toast" />
</>
);
}
Toast notification for successful operations.
import { Button } from 'ui-lab-components/button'
import { toast } from 'ui-lab-components/toast'
import { Toaster } from 'ui-lab-components/toast';
export const metadata = {
title: 'Success Toast',
description: 'Toast notification for successful operations.'
};
export default function Example() {
return (
<>
<Button
size="sm"
onClick={() =>
toast({
toasterId: 'success-toast',
title: 'Success',
description: 'Operation completed successfully',
variant: 'success',
})
}
>
Show Success
</Button>
<Toaster toasterId="success-toast" />
</>
);
}
Toast notification for errors or destructive operations.
import { Button } from 'ui-lab-components/button'
import { toast } from 'ui-lab-components/toast'
import { Toaster } from 'ui-lab-components/toast';
export const metadata = {
title: 'Danger Toast',
description: 'Toast notification for errors or destructive operations.'
};
export default function Example() {
return (
<>
<Button
size="sm"
onClick={() =>
toast({
toasterId: 'danger-toast',
title: 'Error',
description: 'Something went wrong',
variant: 'danger',
})
}
>
Show Error
</Button>
<Toaster toasterId="danger-toast" />
</>
);
}
Toast notification for informational messages.
import { Button } from 'ui-lab-components/button'
import { toast } from 'ui-lab-components/toast'
import { Toaster } from 'ui-lab-components/toast';
export const metadata = {
title: 'Info Toast',
description: 'Toast notification for informational messages.'
};
export default function Example() {
return (
<>
<Button
size="sm"
onClick={() =>
toast({
toasterId: 'info-toast',
title: 'Info',
description: 'Here is some useful information',
variant: 'info',
})
}
>
Show Info
</Button>
<Toaster toasterId="info-toast" />
</>
);
}
Toast notification for warnings.
import { Button } from 'ui-lab-components/button'
import { toast } from 'ui-lab-components/toast'
import { Toaster } from 'ui-lab-components/toast';
export const metadata = {
title: 'Warning Toast',
description: 'Toast notification for warnings.'
};
export default function Example() {
return (
<>
<Button
size="sm"
onClick={() =>
toast({
toasterId: 'warning-toast',
title: 'Warning',
description: 'Please be careful',
variant: 'warning',
})
}
>
Show Warning
</Button>
<Toaster toasterId="warning-toast" />
</>
);
}