Toast
A 3D toaster whose slice of bread is a real Toast: the lever runs your work, and the slice pops with its result. Built with ui-sdk (opens in a new tab).
Installation
pnpm dlx shadcn@latest add @alexandrejoly/toastUsage
import { createToaster } from "@ui-sdk/react/toast";
import { Toast, ToastDial, ToastLever, ToastRegion, ToastStage, ToastStop,} from "@/components/ui/literal-ui/toast/toast";import { ToastAudio } from "@/components/ui/literal-ui/toast/toast-sound";
const toaster = createToaster();<Toast onToast={() => "Toast is ready"} toaster={toaster}> <ToastStage> <ToastRegion /> <ToastDial /> <ToastStop /> <ToastLever /> </ToastStage> <ToastAudio /></Toast>Examples
Async work
onToast can await real work. The lever stays down until it settles: a resolved title pops as a success, and a rejection pops its message as an error, every second save here. Stop aborts signal.
Controlled
Set toasting to start a cycle from your own code. Here the form pushes the lever down, and the slice pops with your message three seconds later. The lever, the dial and Stop still work by hand, and onToastingChange reports each start and each end.
API reference
Toast
Holds the cycle, the slice and the browning level. The slice is a toast in your toaster.
Takes every prop of div.
| Prop | Type | Default |
|---|---|---|
toasterFrom | Toaster | None |
onToastRuns once the catch holds the lever. Return a title for a success, or toast options such as | (cycle: ToastCycle) => ToastOutcome | void | Promise< | None |
canToastAsked as the lever reaches the catch. Return | () => boolean | None |
defaultLevelThe dial's browning level: how long a cycle lasts and how much it browns the slice. Default: | 1 | 2 | 3 | 4 | 5 | 3 |
levelThe browning level, controlled. | 1 | 2 | 3 | 4 | 5 | None |
onLevelChangeRuns when the dial turns to a new level. | (level: ToastLevel) => void | None |
defaultToastingStarts a cycle on mount, as if the lever had been pushed down. Default: | boolean | false |
toastingWhether a cycle runs, controlled. Set it to | boolean | None |
onToastingChangeRuns when a cycle starts, by hand or from | (toasting: boolean) => void | None |
idleTitleThe title of a fresh slice, for screen readers. Default: | string | "Plain bread, ready to toast" |
toastingTitleThe slice's title while a cycle runs. Default: | string | "Toasting…" |
ToastCycle
What onToast receives.
| Field | Type |
|---|---|
idThe slice's toast id in your toaster. | string |
levelThe dial's level for this cycle. | 1 | 2 | 3 | 4 | 5 |
browningHow toasted the slice will be once the cycle ends, from 0 to 1. Browning adds up from one cycle to the next. | number |
burntWhether that browning reads as burnt. | boolean |
signalAborted when Stop ends the cycle. The slice then goes back to what it said. | AbortSignal |
ToastStage
The toaster in 3D, with the controls laid over its parts. It shows a still picture until the scene loads, and keeps it without WebGL 2, with the slice's title written on it.
Takes every prop of div.
ToastRegion
The front slot, where the slice stands. Pull the slice up to take it out, and a fresh one drops in.
Takes every prop of UI SDK ToastRegion (opens in a new tab).
ToastDial
The browning dial. Drag up or down, or use the arrow keys.
Takes every prop of UI SDK Slider (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
aria-labelNames the dial. Default: | string | "Browning" |
ToastLever
The lever. Drag it down to the catch, or press Enter, Space or the Down arrow.
Takes every prop of UI SDK Slider (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
aria-labelNames the lever. Default: | string | "Lever" |
ToastStop
Ends the cycle early. The slice keeps its browning and its previous title.
Takes every prop of UI SDK Button (opens in a new tab).
ToastAudio
Plays the toaster's recorded sounds. It renders nothing, and loads nothing until the page is pressed. Import it from toast-sound.
| Prop | Type | Default |
|---|---|---|
mutedSilences this toaster alone. Default: | boolean | false |
ToastAudioProvider
Mutes every ToastAudio inside it, for a sound preference that covers the whole app or one part of it. It renders nothing of its own.
| Prop | Type |
|---|---|
mutedSilences the toasters below. Turned off during a press, their sounds unlock at once. | boolean |
useToastEvents
Follows what the toaster does as it happens, as ToastAudio does: the lever, the dial, Stop, each pop and each slice.
| Returns | Type |
|---|---|
subscribeCalls | (listener: (event: ToastEvent) => void) => () => void |