> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Show Toast

> Display a notification from any UI interaction.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

`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.

<ComponentPreview json={{"view":{"cssClass":"gap-2","type":"Row","children":[{"type":"Button","label":"Notify","variant":"default","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Something happened"}},{"type":"Button","label":"Warn me","variant":"outline","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Improbability levels rising","variant":"warning"}}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQnV0dG9uLCBSb3cKZnJvbSBwcmVmYWJfdWkuYWN0aW9ucyBpbXBvcnQgU2hvd1RvYXN0Cgp3aXRoIFJvdyhnYXA9Mik6CiAgICBCdXR0b24oIk5vdGlmeSIsIG9uX2NsaWNrPVNob3dUb2FzdCgiU29tZXRoaW5nIGhhcHBlbmVkIikpCiAgICBCdXR0b24oIldhcm4gbWUiLCB2YXJpYW50PSJvdXRsaW5lIiwKICAgICAgICAgICBvbl9jbGljaz1TaG93VG9hc3QoIkltcHJvYmFiaWxpdHkgbGV2ZWxzIHJpc2luZyIsIHZhcmlhbnQ9Indhcm5pbmciKSkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Button, Row
    from prefab_ui.actions import ShowToast

    with Row(gap=2):
        Button("Notify", on_click=ShowToast("Something happened"))
        Button("Warn me", variant="outline",
               on_click=ShowToast("Improbability levels rising", variant="warning"))
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-2",
        "type": "Row",
        "children": [
          {
            "type": "Button",
            "label": "Notify",
            "variant": "default",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "Something happened"}
          },
          {
            "type": "Button",
            "label": "Warn me",
            "variant": "outline",
            "size": "default",
            "disabled": false,
            "onClick": {
              "action": "showToast",
              "message": "Improbability levels rising",
              "variant": "warning"
            }
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Variants

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

<ComponentPreview json={{"view":{"cssClass":"gap-2 flex-wrap","type":"Row","children":[{"type":"Button","label":"Default","variant":"outline","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Something happened"}},{"type":"Button","label":"Success","variant":"success","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Towel registered","variant":"success"}},{"type":"Button","label":"Error","variant":"destructive","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Towel not found","variant":"error"}},{"type":"Button","label":"Warning","variant":"warning","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Improbability drive unstable","variant":"warning"}},{"type":"Button","label":"Info","variant":"info","size":"default","disabled":false,"onClick":{"action":"showToast","message":"42 towels in inventory","variant":"info"}}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQnV0dG9uLCBSb3cKZnJvbSBwcmVmYWJfdWkuYWN0aW9ucyBpbXBvcnQgU2hvd1RvYXN0Cgp3aXRoIFJvdyhnYXA9MiwgY3NzX2NsYXNzPSJmbGV4LXdyYXAiKToKICAgIEJ1dHRvbigiRGVmYXVsdCIsIHZhcmlhbnQ9Im91dGxpbmUiLAogICAgICAgICAgIG9uX2NsaWNrPVNob3dUb2FzdCgiU29tZXRoaW5nIGhhcHBlbmVkIikpCiAgICBCdXR0b24oIlN1Y2Nlc3MiLCB2YXJpYW50PSJzdWNjZXNzIiwKICAgICAgICAgICBvbl9jbGljaz1TaG93VG9hc3QoIlRvd2VsIHJlZ2lzdGVyZWQiLCB2YXJpYW50PSJzdWNjZXNzIikpCiAgICBCdXR0b24oIkVycm9yIiwgdmFyaWFudD0iZGVzdHJ1Y3RpdmUiLAogICAgICAgICAgIG9uX2NsaWNrPVNob3dUb2FzdCgiVG93ZWwgbm90IGZvdW5kIiwgdmFyaWFudD0iZXJyb3IiKSkKICAgIEJ1dHRvbigiV2FybmluZyIsIHZhcmlhbnQ9Indhcm5pbmciLAogICAgICAgICAgIG9uX2NsaWNrPVNob3dUb2FzdCgiSW1wcm9iYWJpbGl0eSBkcml2ZSB1bnN0YWJsZSIsIHZhcmlhbnQ9Indhcm5pbmciKSkKICAgIEJ1dHRvbigiSW5mbyIsIHZhcmlhbnQ9ImluZm8iLAogICAgICAgICAgIG9uX2NsaWNrPVNob3dUb2FzdCgiNDIgdG93ZWxzIGluIGludmVudG9yeSIsIHZhcmlhbnQ9ImluZm8iKSkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Button, Row
    from prefab_ui.actions import ShowToast

    with Row(gap=2, css_class="flex-wrap"):
        Button("Default", variant="outline",
               on_click=ShowToast("Something happened"))
        Button("Success", variant="success",
               on_click=ShowToast("Towel registered", variant="success"))
        Button("Error", variant="destructive",
               on_click=ShowToast("Towel not found", variant="error"))
        Button("Warning", variant="warning",
               on_click=ShowToast("Improbability drive unstable", variant="warning"))
        Button("Info", variant="info",
               on_click=ShowToast("42 towels in inventory", variant="info"))
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-2 flex-wrap",
        "type": "Row",
        "children": [
          {
            "type": "Button",
            "label": "Default",
            "variant": "outline",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "Something happened"}
          },
          {
            "type": "Button",
            "label": "Success",
            "variant": "success",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "Towel registered", "variant": "success"}
          },
          {
            "type": "Button",
            "label": "Error",
            "variant": "destructive",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "Towel not found", "variant": "error"}
          },
          {
            "type": "Button",
            "label": "Warning",
            "variant": "warning",
            "size": "default",
            "disabled": false,
            "onClick": {
              "action": "showToast",
              "message": "Improbability drive unstable",
              "variant": "warning"
            }
          },
          {
            "type": "Button",
            "label": "Info",
            "variant": "info",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "42 towels in inventory", "variant": "info"}
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Description Text

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

<ComponentPreview json={{"view":{"type":"Button","label":"Deploy","variant":"default","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Deployment complete","description":"3 agents online","variant":"success"}}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQnV0dG9uCmZyb20gcHJlZmFiX3VpLmFjdGlvbnMgaW1wb3J0IFNob3dUb2FzdAoKQnV0dG9uKAogICAgIkRlcGxveSIsCiAgICBvbl9jbGljaz1TaG93VG9hc3QoCiAgICAgICAgIkRlcGxveW1lbnQgY29tcGxldGUiLAogICAgICAgIGRlc2NyaXB0aW9uPSIzIGFnZW50cyBvbmxpbmUiLAogICAgICAgIHZhcmlhbnQ9InN1Y2Nlc3MiLAogICAgKSwKKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Button
    from prefab_ui.actions import ShowToast

    Button(
        "Deploy",
        on_click=ShowToast(
            "Deployment complete",
            description="3 agents online",
            variant="success",
        ),
    )
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "Button",
        "label": "Deploy",
        "variant": "default",
        "size": "default",
        "disabled": false,
        "onClick": {
          "action": "showToast",
          "message": "Deployment complete",
          "description": "3 agents online",
          "variant": "success"
        }
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Duration

By default the host decides how long toasts persist. Override with `duration` (in milliseconds):

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
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.

<ComponentPreview json={{"view":{"cssClass":"gap-2","type":"Row","children":[{"type":"Button","label":"Success callback","variant":"success","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Saved successfully!","variant":"success"}},{"type":"Button","label":"Error callback","variant":"destructive","size":"default","disabled":false,"onClick":{"action":"showToast","message":"Could not save: connection timed out","variant":"error"}}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQnV0dG9uLCBSb3cKZnJvbSBwcmVmYWJfdWkuYWN0aW9ucyBpbXBvcnQgU2hvd1RvYXN0Cgp3aXRoIFJvdyhnYXA9Mik6CiAgICBCdXR0b24oIlN1Y2Nlc3MgY2FsbGJhY2siLCB2YXJpYW50PSJzdWNjZXNzIiwKICAgICAgICAgICBvbl9jbGljaz1TaG93VG9hc3QoIlNhdmVkIHN1Y2Nlc3NmdWxseSEiLCB2YXJpYW50PSJzdWNjZXNzIikpCiAgICBCdXR0b24oIkVycm9yIGNhbGxiYWNrIiwgdmFyaWFudD0iZGVzdHJ1Y3RpdmUiLAogICAgICAgICAgIG9uX2NsaWNrPVNob3dUb2FzdCgiQ291bGQgbm90IHNhdmU6IGNvbm5lY3Rpb24gdGltZWQgb3V0IiwgdmFyaWFudD0iZXJyb3IiKSkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Button, Row
    from prefab_ui.actions import ShowToast

    with Row(gap=2):
        Button("Success callback", variant="success",
               on_click=ShowToast("Saved successfully!", variant="success"))
        Button("Error callback", variant="destructive",
               on_click=ShowToast("Could not save: connection timed out", variant="error"))
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-2",
        "type": "Row",
        "children": [
          {
            "type": "Button",
            "label": "Success callback",
            "variant": "success",
            "size": "default",
            "disabled": false,
            "onClick": {"action": "showToast", "message": "Saved successfully!", "variant": "success"}
          },
          {
            "type": "Button",
            "label": "Error callback",
            "variant": "destructive",
            "size": "default",
            "disabled": false,
            "onClick": {
              "action": "showToast",
              "message": "Could not save: connection timed out",
              "variant": "error"
            }
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

Wire these onto a `CallTool` with `on_success` and `on_error`. The `{{ $error }}` variable captures the error message from the server.

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
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

<Card icon="code" title="ShowToast Parameters">
  <ParamField body="message" type="str" required>
    Toast message text. Can be passed as a positional argument. Supports `{{ key }}` interpolation.
  </ParamField>

  <ParamField body="description" type="str | None" default="None">
    Optional secondary text displayed below the message.
  </ParamField>

  <ParamField body="variant" type="&#x22;default&#x22; | &#x22;success&#x22; | &#x22;error&#x22; | &#x22;warning&#x22; | &#x22;info&#x22; | None" default="None">
    Visual style of the toast.
  </ParamField>

  <ParamField body="duration" type="int | None" default="None">
    Auto-dismiss duration in milliseconds. When omitted, the host decides.
  </ParamField>
</Card>

## Protocol Reference

```json ShowToast theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "action": "showToast",
  "message": "string (required)",
  "description?": "string",
  "variant?": "default | success | error | warning | info",
  "duration?": "number"
}
```

For the complete protocol schema, see [ShowToast](/protocol/show-toast).
