Module: ModalStack::Helpers::ModalBackLinkHelper

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

Overview

Renders a button (or link) that steps back through the top layer’s path. Wired to the ‘modal-stack-back-link` Stimulus controller, which delegates to `orchestrator.pathBack`.

<%= modal_back_link "Back" %>
<%= modal_back_link "Back to step 1", steps: 2 %>
<%= modal_back_link class: "btn btn-link" do %>
  <span aria-hidden="true">←</span> Back
<% end %>

Constant Summary collapse

"modal-stack-back-link"
"click->modal-stack-back-link#trigger"

Instance Method Summary collapse

Instance Method Details

rubocop:disable Metrics/CyclomaticComplexity

Raises:

  • (ArgumentError)


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

def modal_back_link(name = nil, options = {}, &block) # rubocop:disable Metrics/CyclomaticComplexity
  if block
    options = name.is_a?(Hash) ? name : {}
    name = capture(&block)
  end
  options = options.dup
  steps = Integer(options.delete(:steps) || 1)
  raise ArgumentError, "steps must be a positive integer, got #{steps.inspect}" if steps < 1

  options[:data] = back_link_data(options.delete(:data) || {}, steps)
  options[:type] ||= "button"

  button_tag(name || I18n.t("modal_stack.back", default: "Back"), **options)
end