Flowbite::Toast
Renders a toast notification element.
Usage
<%= render(Flowbite::Toast.new(message: "Something has happened!")) %>
Passing options to the default button
<%= render(Flowbite::Toast.new(
button: {options: {data: {action: "toast#dismiss"}}},
message: "Something has happened!"
)) %>
Using the button slot
<%= render(Flowbite::Toast.new(message: "Something has happened!")) do |toast| %>
<% toast.with_button do %>
<%= render(Flowbite::Toast::CloseButton.new(data: {action: "toast#dismiss"})) %>
<% end %>
<% end %>
Examples
Styles
Use these toast notification styles to show feedback messages to your users. Toast notifications appear with different colors and icons based on the style.
Dismissible
Control whether the toast can be dismissed with a close button.
Custom Styling
Add custom classes to the toast container.
API reference
Flowbite
In namespace
Slots
button
|
Flowbite::Toast::CloseButton | The button rendered at the end of the toast. Defaults to a close button. Use +with_button+ to set custom content. |
|---|
Constructor
def initialize(message:, button: {}, dismissible: true, style: :default, class: nil, **options)
Parameters
button
|
Hash | Configuration for the default button, rendered using the Toast::CloseButton component. The hash can contain: - `options`: Additional HTML options to pass to the button element, e.g. `{data: {action: "toast#dismiss"}}` Alternatively, you can use the `button` slot to provide the entire button element yourself. |
|---|---|---|
class
|
Array<String> | Additional CSS classes for the toast container. |
dismissible
|
Boolean | Whether the toast can be dismissed (default: true). |
message
|
String | The message to display in the toast. |
options
|
Hash | Additional HTML options for the toast container. |
style
|
Symbol | The color style of the toast (:default, :success, :danger, :warning). |
See also
Ruby API documentation forclass Flowbite::Toast