Toast
A toast confirms that something happened, such as a save or a send, with a short message that goes away by itself.
When to use
Section titled “When to use”- Use it to confirm an action the person just took: “Rilis tersimpan.”
- Use it for errors that are not tied to one field: “Belum bisa mengirim. Coba lagi sebentar.”
- Show validation errors under their field, not in a toast; the message comes from the backend.
- Use a Dialog when the person must decide something.
Do and don’t
Section titled “Do and don’t”Anatomy
Section titled “Anatomy”- 1Status icon
- 2Message
- 3Close
A message on popover with a border, radius-lg and shadow-lg, with an icon in the status color: success, info, warning or destructive. Toasts stack in a corner and follow the page’s mode.
Variants
Section titled “Variants”toast() for a plain message, and toast.success, toast.info, toast.warning, toast.error for a status icon.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
toast.success(message) from sonner |
toast.success(message) from vue-sonner |
ShadToaster.of(context).show(ShadToast(...)) |
function | none | Shows a toast. |
<Toaster /> once in the app |
<Toaster /> once in the app |
ShadToaster (in ShadApp) |
element | none | Where toasts appear. |
position on Toaster |
position on Toaster |
alignment |
string | bottom-right |
Corner of the screen. |
The Sosialoka Toaster reads light or dark from data-theme or the .dark class on <html>, so it needs no theme provider.
import { toast } from "sonner"import { Button } from "@/components/ui/button"import { Toaster } from "@/components/ui/sonner"
export default function SonnerDemo() { return ( <div className="flex flex-wrap gap-2"> <Button variant="outline" onClick={() => toast.success("Rilis tersimpan.")}> Simpan </Button> <Button variant="outline" onClick={() => toast.error("Belum bisa mengirim. Coba lagi sebentar.")}> Kirim </Button> <Toaster /> </div> )}<script setup lang="ts">import { toast } from "vue-sonner"import { Button } from "@/components/ui/button"import { Toaster } from "@/components/ui/sonner"</script>
<template> <div class="flex flex-wrap gap-2"> <Button variant="outline" @click="toast.success('Rilis tersimpan.')">Simpan</Button> <Button variant="outline" @click="toast.error('Belum bisa mengirim. Coba lagi sebentar.')">Kirim</Button> <Toaster /> </div></template>// ShadApp already wraps the app in a ShadToaster.import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class SonnerDemo extends StatelessWidget { const SonnerDemo({super.key});
@override Widget build(BuildContext context) { return Wrap( spacing: 8, children: [ ShadButton.outline( child: const Text('Simpan'), onPressed: () => ShadToaster.of(context).show(const ShadToast(description: Text('Rilis tersimpan.'))), ), ShadButton.outline( child: const Text('Kirim'), onPressed: () => ShadToaster.of(context).show( const ShadToast.destructive(description: Text('Belum bisa mengirim. Coba lagi sebentar.')), ), ), ], ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/sonner.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/sonner.jsonAccessibility
Section titled “Accessibility”- Toasts are announced politely by screen readers and don’t take focus.
- Keep them short; anything people must act on belongs in the page or a dialog.
