Module: Decidim::ModalHelper

Included in:
LayoutHelper
Defined in:
app/helpers/decidim/modal_helper.rb

Overview

This helper includes methods to generate modal windows on the layout. The trigger element must contain a “data-dialog-open” attribute, you may specify data-dialog-open=“<seed>” also, where seed must match with the provided id option: <%= decidim_modal id: seed %>. In a very similar way, you also can add your custom close button through data-dialog-close=“<seed>”

Options available:

- id: String. Unique identifier for the dialog, if the page has distinct modal windows (default: "")
- class: String. CSS classes for the modal content.
- closable: Boolean. Whether the modal can be closed or not (default: true)

Instance Method Summary collapse

Instance Method Details

#decidim_modal(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/decidim/modal_helper.rb', line 15

def decidim_modal(opts = {}, &)
  opts[:closable] = true unless opts.has_key?(:closable)

  button = if opts[:closable] == false
             ""
           else
             (
               :button,
               "&times".html_safe,
               type: :button,
               data: { dialog_close: opts[:id] || "", dialog_closable: "" },
               "aria-label": t("close_modal", scope: "decidim.shared.confirm_modal")
             )
           end

  content = opts[:remote].nil? ? button + capture(&).html_safe : button + icon("loader-3-line")
  (:div, id: opts[:id], data: { dialog: opts[:id] || "" }.merge(opts[:data] || {})) do
    (:div, id: "#{opts[:id]}-content", class: opts[:class]) do
      content
    end
  end
end