Module: ModalHelper
- Defined in:
- app/helpers/modal_helper.rb
Constant Summary collapse
- MODAL_ID =
"modal"
- LINK_OPTIONS =
{ data: { turbo_frame: MODAL_ID, controller: "modal-link", action: "modal-link#onClick", modal_type: "", } }.freeze
Instance Method Summary collapse
- #modal_content(options = {}, &block) ⇒ Object
- #modal_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object (also: #modal_link)
- #modal_tag(modal_id = MODAL_ID) ⇒ Object
Instance Method Details
#modal_content(options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/modal_helper.rb', line 30 def modal_content( = {}, &block) modal_id = .fetch(:modal_id, MODAL_ID) turbo_frame_tag modal_id, data: { hidden: "" } do tag.div(class: "modal-wrapper") do tag.div(class: "modal animate-in #{.delete(:modal_classes)}", data: { action: <<~ACTIONS keyup@window->modal#keyup scrim:hide@window->modal#close ACTIONS }) do yield if block end end end end |
#modal_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object Also known as: modal_link
20 21 22 23 24 25 26 |
# File 'app/helpers/modal_helper.rb', line 20 def modal_link_to(name = nil, = nil, = nil, &block) if block link_to name, LINK_OPTIONS.deep_merge( || {}), &block else link_to name, , LINK_OPTIONS.deep_merge( || {}) end end |
#modal_tag(modal_id = MODAL_ID) ⇒ Object
12 13 14 15 16 17 |
# File 'app/helpers/modal_helper.rb', line 12 def modal_tag(modal_id = MODAL_ID) turbo_frame_tag modal_id, data: { controller: "modal", modal_target: "turboFrame", action: <<~ACTIONS } modal:open@window->modal#open modal:close@window->modal#close ACTIONS end |