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
-
#dialog(text, title:, okay: t('bh.okay'), **options) ⇒ Object
A link reading
textand the dialog it opens: headedtitlewith an X to close it, holding the block, and closed as well by a footer button readingokay—Okayunless told otherwise, or none at all forfalse.
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 okay — Okay
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'), **, &) id = "dialog-#{text.parameterize}" data = { **.fetch(:data, {}), bs_toggle: 'dialog', bs_target: "##{id}" } parts = [bh_dialog_header(id, title), tag.div(capture(&), class: 'dialog-body')] parts.push (okay) if okay safe_join [ link_to(text, "##{id}", **, data:), tag.dialog(safe_join(parts), class: 'dialog dialog-slide-down', id:, aria: { labelledby: "#{id}-title" }), ] end |