Toast Bootstrap5

Toast Bootstrap5

Bootstrap 5 toast notifications from flash messages

Renders Bootstrap 5 toast notifications from your Yii Framework 3 application's session flash messages. Queue a message from a controller with FlashToastInterface, render it in your layout with $toast->render($this) - no manual partials, no bundled JS asset. Requires Bootstrap 5's JS bundle to be loaded on the page for the dismiss and auto-hide behavior.

Types

The first argument to add() is a ToastType case. Each maps to a Bootstrap 5 text-bg-* color and an ARIA live-region role - urgent types interrupt with role="alert", the rest announce politely with role="status".

ToastType::SUCCESS
text-bg-success
Polite status message (role="status").
ToastType::ERROR
text-bg-danger
Urgent alert (role="alert"); stays up until dismissed by default, so it isn't lost to a timer.
ToastType::WARNING
text-bg-warning
Urgent alert (role="alert").
ToastType::INFO
text-bg-info
Polite status message (role="status").

Options

delay array
['success' => 4000, 'error' => null, 'warning' => 6000, 'info' => 4000]
Milliseconds before a toast auto-hides, keyed by type; null leaves it up until dismissed manually, the default for error.
icons array
['success' => 'check-circle-fill', 'error' => 'exclamation-octagon-fill', 'warning' => 'exclamation-triangle-fill', 'info' => 'info-circle-fill']
Bootstrap Icon name keyed by type (requires yiirocks/svg-inline-bootstrap; renders without an icon if it is not installed); null disables that type's icon.
position string
'top-0 end-0'
Space-separated Bootstrap position utility classes for the toast container.

Example

use YiiRocks\ToastBootstrap5\ToastType;

$this->toast->add(ToastType::ERROR, 'Something went wrong.');

Support

Create an issue →
Packagist Version PHP Version Downloads Last Commit GitHub Workflow Status