Module: ModalStack::Helpers::ModalLinkHelper

Defined in:
lib/modal_stack/helpers/modal_link_helper.rb

Overview

View helper that turns a regular link into a modal stack trigger. Falls back to plain link_to when the request comes from Hotwire Native (cf. RFC §15 Q3 — “don’t break” policy on native shells).

<%= modal_link_to "Edit", edit_project_path(@project) %>
<%= modal_link_to "Details", project_path(@project), as: :drawer, side: :right %>

Constant Summary collapse

"modal-stack-link"
"click->modal-stack-link#open"
%i[as side size width height dismissible].freeze

Instance Method Summary collapse

Instance Method Details



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/modal_stack/helpers/modal_link_helper.rb', line 17

def modal_link_to(name = nil, options = nil, html_options = nil, &block)
  if block_given?
    html_options = options
    options = name
    name = block
  end
  html_options = (html_options || {}).dup

  return link_to(name, options, html_options, &block) if hotwire_native_request?

  modal_options = html_options.extract!(*MODAL_OPTION_KEYS)
  html_options[:data] = build_modal_link_data(html_options[:data] || {}, modal_options)

  link_to(name, options, html_options, &block)
end