Module: Trestle::ModalHelper

Included in:
Controller::Modal
Defined in:
app/helpers/trestle/modal_helper.rb

Instance Method Summary collapse

Instance Method Details

Returns the HTML attributes to apply to the inner modal dialog (.modal-dialog) <div>



41
42
43
44
45
46
# File 'app/helpers/trestle/modal_helper.rb', line 41

def modal_dialog_attributes
  {
    class: ["modal-dialog", modal_options[:class]].compact,
    role: "document"
  }
end

Returns a hash of the currently defined modal options



24
25
26
# File 'app/helpers/trestle/modal_helper.rb', line 24

def modal_options
  @_modal_options ||= {}
end

Merges the given options with the existing hash of defined modal options.

Trestle uses Bootstrap modal markup (getbootstrap.com/docs/5.3/components/modal/) to render modals, which consist of an outer .modal wrapper div with an inner .modal-dialog div.

The ‘class` attribute (e.g. `“modal-lg”`) is applied to the inner element, and all other attributes are applied to the outer element. A class can be applied to the wrapper element using the `wrapper_class` option.

Examples

<% modal_options! class: "modal-lg", controller: "modal-stimulus" %>

<% modal_options! wrapper_class: "custom-modal-animation" %>


19
20
21
# File 'app/helpers/trestle/modal_helper.rb', line 19

def modal_options!(options)
  modal_options.merge!(options)
end

Returns the HTML attributes to apply to the modal wrapper (.modal) <div>



29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/trestle/modal_helper.rb', line 29

def modal_wrapper_attributes
  {
    class: ["modal", "fade", modal_options[:wrapper_class]].compact,
    tabindex: "-1",
    role: "dialog",
    data: {
      controller: ["modal", modal_options[:controller]].compact.join(" ")
    }
  }.deep_merge(modal_options.except(:class, :wrapper_class, :controller))
end