Skip to main content
ShowToast displays a brief notification. It’s a client-side action — no server round-trip — so feedback is instant. Fire it directly from a button click, or use it as a CallTool callback to report success or failure after a server action completes.

Variants

The variant parameter controls the toast’s visual style. Omit it for a neutral default.

Description Text

Add a secondary line with the description parameter for toasts that need more context.

Duration

By default the host decides how long toasts persist. Override with duration (in milliseconds):
ShowToast("Quick flash", duration=1500)
ShowToast("Read this carefully", duration=10000)

As CallTool Callbacks

The most common pattern: use ShowToast as on_success and on_error callbacks on a CallTool to give feedback after a server action completes. Wire these onto a CallTool with on_success and on_error. The {{ $error }} variable captures the error message from the server.
from prefab_ui.rx import Rx

item = Rx("item")

Button(
    "Save",
    on_click=CallTool(
        "save_item",
        arguments={"data": item},
        on_success=ShowToast("Saved successfully!", variant="success"),
        on_error=ShowToast("{{ $error }}", variant="error"),
    ),
)

API Reference

ShowToast Parameters

message
str
required
Toast message text. Can be passed as a positional argument. Supports {{ key }} interpolation.
description
str | None
default:"None"
Optional secondary text displayed below the message.
variant
"default" | "success" | "error" | "warning" | "info" | None
default:"None"
Visual style of the toast.
duration
int | None
default:"None"
Auto-dismiss duration in milliseconds. When omitted, the host decides.

Protocol Reference

ShowToast
{
  "action": "showToast",
  "message": "string (required)",
  "description?": "string",
  "variant?": "default | success | error | warning | info",
  "duration?": "number"
}
For the complete protocol schema, see ShowToast.