Module: Wabi::TurboStreamExtensions
- Defined in:
- lib/wabi/turbo_stream_extensions.rb
Overview
Extends ‘Turbo::Streams::TagBuilder` with a `wabi_toast` shorthand that appends a server-rendered Toast component into the singleton Toaster container.
In a Rails controller / Turbo Stream view:
render turbo_stream: turbo_stream.wabi_toast(
title: "Saved",
description: "Profile updated.",
appearance: :success,
)
Equivalent to:
render turbo_stream: turbo_stream.append(
"wabi-toaster",
Components::UI::Toast.new(title: "Saved", description: "...", appearance: :success),
)
The user app must have run ‘bin/rails g wabi:add toast` first so that `Components::UI::Toast` is defined.
NOTE: this module is named ‘Wabi::TurboStreamExtensions` (NOT `Wabi::Rails::TurboStreamExtensions`) because nesting a `Rails` module inside `Wabi` shadows the top-level `Rails` constant from generators that reference `Rails::Generators::Base`, breaking gem load order.
Instance Method Summary collapse
Instance Method Details
#wabi_toast(toaster_id: "wabi-toaster", **toast_options) ⇒ Object
31 32 33 34 |
# File 'lib/wabi/turbo_stream_extensions.rb', line 31 def wabi_toast(toaster_id: "wabi-toaster", **) toast_class = wabi_resolve_toast_class append(toaster_id, toast_class.new(**)) end |