Module: UltimateTurboModal::Helpers::ViewHelper
- Defined in:
- lib/ultimate_turbo_modal/helpers/view_helper.rb
Instance Method Summary collapse
- #drawer(position: nil, size: nil, **options, &block) ⇒ Object
- #modal ⇒ Object
-
#modal_confirm(body = nil, title: nil, accept: nil, cancel: nil, variant: nil, native: nil, **data) ⇒ Object
Builds the
dataattributes for an element that should prompt before acting. -
#modal_confirm_template(**options) ⇒ Object
Renders the inert the Turbo Confirm dialog is cloned from.
Instance Method Details
#drawer(position: nil, size: nil, **options, &block) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/ultimate_turbo_modal/helpers/view_helper.rb', line 9 def drawer(position: nil, size: nil, **, &block) cfg = UltimateTurboModal.configuration.drawer_config position = UltimateTurboModal::Base.validate_drawer_position!(position || cfg.position) size = UltimateTurboModal::Base.validate_drawer_size!(size || cfg.size) modal(drawer_position: position, size: size, **, &block) end |
#modal ⇒ Object
5 6 7 |
# File 'lib/ultimate_turbo_modal/helpers/view_helper.rb', line 5 def modal(**, &) render(UltimateTurboModal.new(request:, **), &) end |
#modal_confirm(body = nil, title: nil, accept: nil, cancel: nil, variant: nil, native: nil, **data) ⇒ Object
Builds the data attributes for an element that should prompt before
acting. The options are JSON-encoded into data-turbo-confirm because
Turbo rewrites a link with data-turbo-method into a synthetic form and
copies only a fixed set of attributes across -- sibling
data-turbo-confirm-* attributes on a link would be dropped.
link_to "Delete", post_path(post), data: modal_confirm(
"This can't be undone.", title: "Delete post?", accept: "Delete",
variant: :danger, turbo_method: :delete)
native: true opts this one confirmation back out to window.confirm.
On a link that is the only way to say it, since Turbo drops sibling
data-turbo-confirm-native along with everything else.
39 40 41 42 43 44 45 |
# File 'lib/ultimate_turbo_modal/helpers/view_helper.rb', line 39 def modal_confirm(body = nil, title: nil, accept: nil, cancel: nil, variant: nil, native: nil, **data) payload = {title: title, body: body, accept: accept, cancel: cancel, variant: variant, native: native&.to_s}.compact raise ArgumentError, "modal_confirm requires a body or at least one option" if payload.empty? {turbo_confirm: payload.to_json}.merge(data) end |
#modal_confirm_template(**options) ⇒ Object
Renders the inert the Turbo Confirm dialog is cloned from.
Place it once in your layout: its presence is what enables the feature.
Renders nothing when config.confirm.enabled is false, which turns the
feature off without touching the layout.
20 21 22 23 24 |
# File 'lib/ultimate_turbo_modal/helpers/view_helper.rb', line 20 def modal_confirm_template(**) return unless UltimateTurboModal.configuration.confirm_config.enabled render(UltimateTurboModal.confirm(request:, **)) end |