Module: ModalStack::TurboStreamsExtension
- Defined in:
- lib/modal_stack/turbo_streams_extension.rb
Overview
Custom Turbo Stream actions for stack manipulation. Mixed into Turbo::Streams::TagBuilder via the :turbo_streams_tag_builder load hook so the standard ‘turbo_stream.foo(…)` form keeps working alongside.
Constant Summary collapse
- HISTORY_MODES =
%i[push replace].freeze
Instance Method Summary collapse
-
#modal_close_all ⇒ Object
Tear down the entire stack.
-
#modal_pop ⇒ Object
Pop the top layer.
-
#modal_push(content = nil, variant: :modal, dismissible: true, url: nil, side: nil, size: nil, width: nil, height: nil, **rendering) ⇒ Object
Push a new layer on top of the stack.
-
#modal_replace(content = nil, variant: nil, dismissible: nil, url: nil, history: :replace, layer_id: nil, side: nil, size: nil, width: nil, height: nil, **rendering) ⇒ Object
Replace the top layer’s content.
Instance Method Details
#modal_close_all ⇒ Object
Tear down the entire stack.
63 64 65 |
# File 'lib/modal_stack/turbo_streams_extension.rb', line 63 def modal_close_all turbo_stream_action_tag(:modal_close_all, target: ModalStack::TARGET_ID) end |
#modal_pop ⇒ Object
Pop the top layer.
32 33 34 |
# File 'lib/modal_stack/turbo_streams_extension.rb', line 32 def modal_pop turbo_stream_action_tag(:modal_pop, target: ModalStack::TARGET_ID) end |
#modal_push(content = nil, variant: :modal, dismissible: true, url: nil, side: nil, size: nil, width: nil, height: nil, **rendering) ⇒ Object
Push a new layer on top of the stack. The content is rendered using the same options as Turbo’s standard stream actions (partial:/locals:/template:/…).
variant: :modal (default) | :drawer | :bottom_sheet | :confirmation dismissible: true (default) | false url: override the URL associated with this layer (defaults to the request path) side: only meaningful for :drawer — :left | :right | :top | :bottom size: :sm | :md | :lg | :xl | string width/height: CSS length values (e.g. “42rem”, “70vh”, “min(90vw, 56rem)”)
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/modal_stack/turbo_streams_extension.rb', line 20 def modal_push(content = nil, variant: :modal, dismissible: true, url: nil, side: nil, size: nil, width: nil, height: nil, **rendering, &) template = render_template(ModalStack::TARGET_ID, content, **rendering, &) turbo_stream_action_tag( :modal_push, target: ModalStack::TARGET_ID, template: template, data: modal_data(variant: variant, dismissible: dismissible, url: url, side: side, size: size, width: width, height: height) ) end |
#modal_replace(content = nil, variant: nil, dismissible: nil, url: nil, history: :replace, layer_id: nil, side: nil, size: nil, width: nil, height: nil, **rendering) ⇒ Object
Replace the top layer’s content. Defaults to history.replaceState (no new history entry). Pass history: :push for a wizard-step semantic where browser-back returns to the previous step.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/modal_stack/turbo_streams_extension.rb', line 39 def modal_replace(content = nil, variant: nil, dismissible: nil, url: nil, history: :replace, layer_id: nil, side: nil, size: nil, width: nil, height: nil, **rendering, &) raise ArgumentError, "history: must be #{HISTORY_MODES.inspect}, got #{history.inspect}" unless HISTORY_MODES.include?(history) template = render_template(ModalStack::TARGET_ID, content, **rendering, &) turbo_stream_action_tag( :modal_replace, target: ModalStack::TARGET_ID, template: template, data: modal_data( variant: variant, dismissible: dismissible, url: url, side: side, size: size, width: width, height: height, history_mode: history, layer_id: layer_id ) ) end |