Toast
Toasts are lightweight, non-blocking notifications. They are designed to mimic the push notifications popularized by mobile and desktop operating systems.
Bootstrap Reference
Quick Start
In FastStrap, we use SimpleToast for the most common case: a simple text message with a variant color.
Live Preview
Success! Item added to cart.
Visual Examples & Use Cases
1. SimpleToast Variants
Standard colors to communicate status.
Code & Output
2. Full Control (Standard Toast)
For rich content, headers, and custom timing, use the base Toast component.
Code & Output
Live Preview (Rich Toast)
Messenger
Just now
Your message has been sent.
3. Toast Container
Toasts are often grouped. FastStrap handles the ToastContainer logic to ensure they stack correctly in the corner of the screen.
from faststrap import ToastContainer, add_bootstrap
# 1. Add container to your main layout
app_layout = [
MainView(),
ToastContainer(position="bottom-end") # Global container
]
Practical Functionality
1. Triggering Toasts via HTMX
The most common implementation is to return a Toast as part of an HTMX response (using hx-swap="beforeend" targetting the Toast Container).
@app.route("/add_item")
def add_item():
# ... logic ...
return SimpleToast("Item Added", variant="success") # Appends to existing list
Parameter Reference
| FastStrap Param | Type | Bootstrap Attribute | Description |
|---|---|---|---|
title |
Any |
.toast-header |
Optional header element/text. |
autohide |
bool |
data-bs-autohide |
If True, closes automatically. |
delay |
int |
data-bs-delay |
Duration in milliseconds before closing. |
duration (SimpleToast) |
int |
CSS animation delay | Duration in milliseconds before fade out. |
position |
str |
- | Location: top-end, bottom-start, etc. |
faststrap.components.feedback.toast.SimpleToast(*children, title=None, variant=None, duration=None, position=None, **kwargs)
Simple Toast component that works without JavaScript.