Module: Bh::Helpers::Dialogs

Included in:
Bh::Helpers
Defined in:
lib/bh/helpers/dialogs.rb

Overview

A dialog a page opens from a link, with none of Bootstrap's markup written by hand.

Instance Method Summary collapse

Instance Method Details

#dialog(text, title:, okay: t('bh.okay'), **options) ⇒ Object

A link reading text and the dialog it opens: headed title with an X to close it, holding the block, and closed as well by a footer button reading okayOkay unless told otherwise, or none at all for false. The two share an id made from the link's own words, so a page needs to invent none; Bootstrap's own data-bs-toggle does the opening, and the browser's element brings the backdrop, the focus trap and Esc. Any other option is an attribute of the link.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bh/helpers/dialogs.rb', line 11

def dialog(text, title:, okay: t('bh.okay'), **options, &)
  id = "dialog-#{text.parameterize}"
  data = { **options.fetch(:data, {}), bs_toggle: 'dialog', bs_target: "##{id}" }
  parts = [bh_dialog_header(id, title), tag.div(capture(&), class: 'dialog-body')]
  parts.push bh_dialog_footer(okay) if okay

  safe_join [
    link_to(text, "##{id}", **options, data:),
    tag.dialog(safe_join(parts), class: 'dialog dialog-slide-down', id:,
                                 aria: { labelledby: "#{id}-title" }),
  ]
end