ModernToast
ModernToast is an opinionated alternative to the core Bootstrap Toast. It is for polished app-style notifications with configurable position, timing, style, and queue behavior.
Use core Toast when you want Bootstrap's native toast structure. Use ModernToast when you want a more modern product UI surface.
Import
Basic Usage
With Placement, Duration, And Style
ModernToast(
"Invite sent",
"We emailed the new team member.",
intent="success",
placement=ToastPlacement(position="top-end"),
duration=4000,
visual_style="glass",
)
Toast Stack
ModernToastStack(
ModernToast("Saved", intent="success"),
ModernToast("Sync delayed", "Trying again soon.", intent="warning"),
placement=ToastPlacement(position="bottom-end"),
)
With Action
ModernToast(
"Project archived",
"You can restore it from settings.",
intent="warning",
action={"label": "Undo", "style": "btn-link"},
)
Parameters
ModernToast
| Param | Type | Default | Description |
|---|---|---|---|
title |
str |
required | Main toast title. |
message |
str \| None |
None |
Optional message. |
intent |
ToastIntent |
info |
Semantic intent: success, error, warning, info, loading. |
visual_style |
ToastStyle |
glass |
Visual style: solid, soft, glass, minimal. |
placement |
ToastPlacement \| None |
bottom-right |
Position + offset + gutter. |
duration |
int \| "infinite" |
4000 |
Auto-dismiss duration in milliseconds, or "infinite" to persist. |
icon |
str \| None |
None |
Bootstrap icon override. |
action |
ToastAction \| Any \| None |
None |
Optional action button or component. |
cancel |
ToastAction \| Any \| None |
None |
Optional cancel button or component. |
dismissible |
bool |
True |
Shows the close button. |
pause_on_hover |
bool |
True |
Pause auto-dismiss timer on hover/focus. |
animation |
ToastAnimation |
slide |
Enter/exit animation, now visually distinct for each value: slide, fade, zoom, none. |
radius |
str \| None |
None |
Radius token overriding the default rounded-4: sm, md, lg, none. |
shadow |
str \| None |
None |
Shadow token overriding the default shadow-lg: sm, md, lg, none. |
title_cls / message_cls / close_button_cls |
str |
"" |
Extra classes for the title, message, and close button. |
**kwargs |
Any |
Extra attributes. |
ModernToastStack
| Param | Type | Default | Description |
|---|---|---|---|
*toasts |
Any |
Toast children. | |
placement |
ToastPlacement \| None |
bottom-right |
Stack position + offset + gutter. |
gap |
int |
2 |
Bootstrap grid gap utility suffix. |
max_visible |
int |
5 |
Maximum toasts visible at once; extras are queued (hidden) until an open toast dismisses. |
**kwargs |
Any |
Extra attributes. |
Behavior Notes
ModernToastuses a dedicated JS runtime (modern-toast.js) for auto-dismiss, keyboard dismiss, pause-on-hover, and swipe-to-dismiss.- The runtime is loaded automatically when
ModernToastorModernToastStackis used withadd_bootstrap(app, components=[ModernToast, ...]). variant,position, andstyleparameters are deprecated but still accepted withDeprecationWarning. Useintent,placement, andvisual_styleinstead.intentcontrols both the semantic role (status/alert) and the Bootstrap color classes:errorrenders asdangerandloadingasprimary(Bootstrap has noerror/loadingcolor names).- The default surface uses
rounded-4+shadow-lg; for dense dashboards preferModernToast(..., radius="md", shadow="sm"). - Global defaults are supported:
set_component_defaults("ModernToast", intent="info", duration=4000). - Close buttons, auto-dismiss, keyboard dismiss (Escape while focused), and swipe-to-dismiss are handled by the runtime; no extra wiring needed.
animationvalues produce distinct enter/exit motions:slide,fade,zoom, ornone.ModernToastStack(max_visible=...)queues toasts beyond the limit and reveals them as older toasts dismiss.
faststrap.components.feedback.modern_toast.ModernToast(title, message=None, *, intent=UNSET, visual_style='glass', placement=None, duration=UNSET, icon=None, action=None, cancel=None, dismissible=True, pause_on_hover=True, animation='slide', variant=UNSET, position=UNSET, style=UNSET, on_dismiss=None, radius=None, shadow=None, title_cls='', message_cls='', close_button_cls='', **kwargs)
Render an opinionated modern toast surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Primary toast heading. |
required |
message
|
str | None
|
Optional supporting body text. |
None
|
intent
|
ToastIntent | str | None
|
Semantic intent driving color and live-region role. |
UNSET
|
visual_style
|
ToastStyle
|
Surface treatment ( |
'glass'
|
placement
|
ToastPlacement | None
|
Positioned placement (position/offset/gutter). |
None
|
duration
|
int | Literal['infinite'] | None
|
Auto-dismiss delay in ms, or |
UNSET
|
icon
|
str | None
|
Bootstrap icon name override. |
None
|
action
|
ToastAction | Any | None
|
Optional action button spec or custom element. |
None
|
cancel
|
ToastAction | Any | None
|
Optional cancel button spec or custom element. |
None
|
dismissible
|
bool
|
Render a close button. |
True
|
pause_on_hover
|
bool
|
Pause the auto-dismiss timer while hovered/focused. |
True
|
animation
|
ToastAnimation
|
Enter/exit animation style. |
'slide'
|
radius
|
RadiusToken | str | None
|
Radius token overriding the default |
None
|
shadow
|
ShadowToken | str | None
|
Shadow token overriding the default |
None
|
title_cls
|
str
|
Extra classes for the title line. |
''
|
message_cls
|
str
|
Extra classes for the message paragraph. |
''
|
close_button_cls
|
str
|
Extra classes for the dismiss button. |
''
|
**kwargs
|
Any
|
Additional HTML attributes ( |
{}
|
Source code in src/faststrap/components/feedback/modern_toast.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
faststrap.components.feedback.modern_toast.ModernToastStack(*toasts, placement=None, gap=8, max_visible=5, position=UNSET, **kwargs)
Render a positioned stack of ModernToast components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*toasts
|
Any
|
Toast children. |
()
|
placement
|
ToastPlacement | None
|
Stack position/offset/gutter. |
None
|
gap
|
int
|
Bootstrap gap utility suffix; used when |
8
|
max_visible
|
int
|
Toasts visible at once; extras queue (hidden) until others dismiss. |
5
|
position
|
str | None
|
Deprecated; use |
UNSET
|
**kwargs
|
Any
|
Additional HTML attributes. |
{}
|