Components
Toast
A short message in the corner that says what just happened, then gets out of the way.
import { Button } from "@sideby/ui/button";
import { toast } from "@sideby/ui/sonner";
<Button variant="outline" onclick={() => toast.success("Loaded. Everyone is watching the same thing now.")}>Show toast</Button> When to use it
Use a toast to confirm something the room just did, or to say that something changed without anyone asking: the video loaded, the host left, a link would not play. It appears in the bottom-right corner, stays for about 4 seconds and leaves on its own.
A toast is never the only place a fact lives. If someone has to act on it to keep watching, put it in the page too, next to the control it is about. Errors that belong to a field go under the field.
Examples
import { Button } from "@sideby/ui/button";
import { toast } from "@sideby/ui/sonner";
<Button variant="outline" onclick={() => toast.success("Loaded. Everyone is watching the same thing now.")}>Success</Button>
<Button variant="outline" onclick={() => toast.error("That link is playing hard to get. Try a direct video file or a YouTube link.")}>Error</Button>
<Button variant="outline" onclick={() => toast.info("The host wandered off. We'll hold the room for 30 seconds, then turn off the lights.")}>Info</Button>
<Button
variant="outline"
onclick={() =>
toast.promise(fetchVideo(), {
loading: "Fetching the video for the room.",
success: "Loaded. Everyone is watching the same thing now.",
error: "That link is playing hard to get. Try a direct video file or a YouTube link.",
})}
>
Loading, then success
</Button>
<Button
variant="outline"
onclick={() =>
toast("Leo is the host now.", {
action: { label: "Undo", onClick: () => makeHost(me) },
})}
>
With an action
</Button> Setup
Mount the Toaster once, in the root layout. It takes its theme from the sideby theme controller, so it switches when the theme toggle does. Then call toast from anywhere.
<!-- src/routes/+layout.svelte -->
<script lang="ts">
import { Toaster } from "@sideby/ui/sonner";
</script>
<Toaster /> The skin
- A toast sits on the card surface with a hairline edge and the popover shadow, because it floats above the page.
- A small tone mark before the words shows the type: the complete tone for success, destructive for an error, a quiet grey for info and a pulsing in-flight mark while something loads. An error also gets the destructive edge.
- The mark is decorative. The words carry the meaning on their own, so the toast still makes sense in forced-colors mode, to a screen reader or to someone who does not see the hue.
- Actions are extra-small buttons: the action in the default style, a cancel in the ghost style. The close button is a ghost icon button labelled Dismiss.
Keyboard
- Alt+T moves focus to the notifications region. Tab then reaches each toast and its buttons.
- Enter or Space on an action runs it and closes the toast.
- Hovering over a toast or focusing one pauses every timer, so nothing disappears while someone is reading it.
Accessibility
- The region is polite. Success, info and loading toasts are read when the screen reader finishes what it is saying.
- Errors are assertive.
toast.errormarks the toastimportant, so it is read at once. Passimportant: falseif an error can wait. A promise toast that ends in an error stays polite; passimportant: trueto the promise if its failure must interrupt. - Reduced motion is respected. With reduced motion on, toasts appear and leave without sliding, and the loading mark stops pulsing.
- Text only. Titles and descriptions render as text, never as HTML, so a name or an error from the server cannot inject markup.
- Toasts can be swiped away on touch screens, and every toast that is not loading has the Dismiss button too.
Copy
- Say what happened, then what to do. “That link is playing hard to get. Try a direct video file or a YouTube link.” If nothing needs doing, say that: “Everyone is watching the same thing now.”
- Follow the voice. Wit is welcome, as long as the facts come first.
- No emoji, and at most one exclamation mark per screen. Most toasts need none.
- One or two sentences. Put what happened in the title and the next step in the description when it runs long.
- Action labels are verbs: “Undo”, “Retry”, “Copy link”.