Module: Trestle::ModalHelper
- Included in:
- Controller::Modal
- Defined in:
- app/helpers/trestle/modal_helper.rb
Instance Method Summary collapse
-
#modal_dialog_attributes ⇒ Object
Returns the HTML attributes to apply to the inner modal dialog (.modal-dialog) <div>.
-
#modal_options ⇒ Object
Returns a hash of the currently defined modal options.
-
#modal_options!(options) ⇒ Object
Merges the given options with the existing hash of defined modal options.
-
#modal_wrapper_attributes ⇒ Object
Returns the HTML attributes to apply to the modal wrapper (.modal) <div>.
Instance Method Details
#modal_dialog_attributes ⇒ Object
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", [:class]].compact, role: "document" } end |
#modal_options ⇒ Object
Returns a hash of the currently defined modal options
24 25 26 |
# File 'app/helpers/trestle/modal_helper.rb', line 24 def @_modal_options ||= {} end |
#modal_options!(options) ⇒ Object
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 () .merge!() end |
#modal_wrapper_attributes ⇒ Object
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", [:wrapper_class]].compact, tabindex: "-1", role: "dialog", data: { controller: ["modal", [:controller]].compact.join(" ") } }.deep_merge(.except(:class, :wrapper_class, :controller)) end |