Module: ModalHelper

Defined in:
app/helpers/modal_helper.rb

Constant Summary collapse

"modal"
{ data: {
  turbo_frame: MODAL_ID,
  controller:  "modal-link",
  action:      "modal-link#onClick",
  modal_type:  "",
} }.freeze

Instance Method Summary collapse

Instance Method Details



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(options = {}, &block)
  modal_id = options.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 #{options.delete(:modal_classes)}",
              data:  {
                action: <<~ACTIONS
                  keyup@window->modal#keyup
                  scrim:hide@window->modal#close
                ACTIONS
              }) do
        yield if block
      end
    end
  end
end

See Also:

  • for argument details


20
21
22
23
24
25
26
# File 'app/helpers/modal_helper.rb', line 20

def modal_link_to(name = nil, options = nil, html_options = nil, &block)
  if block
    link_to name, LINK_OPTIONS.deep_merge(options || {}), &block
  else
    link_to name, options, LINK_OPTIONS.deep_merge(html_options || {})
  end
end


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