Class: Bootstrap4Helper::Modal
- Defined in:
- lib/bootstrap4_helper/modal.rb
Overview
Builds a Modal window component.
Instance Method Summary collapse
-
#body(opts = {}, &block) ⇒ String
Builds the body component.
-
#close_button(opts = {}) ⇒ String
Builds a close button component.
-
#footer(opts = {}, &block) ⇒ String
Builds the footer component.
-
#header(opts = {}, &block) ⇒ String
Build the header component for the modal.
-
#initialize(template, opts = {}, &block) ⇒ Modal
constructor
Class constructor.
-
#title(opts = {}, &block) ⇒ String
Builds a title component.
-
#to_s ⇒ String
String representation of the object.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ Modal
Class constructor
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bootstrap4_helper/modal.rb', line 17 def initialize(template, opts = {}, &block) super(template) @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @scrollable = opts.fetch(:scrollable, false) @vcentered = opts.fetch(:vcentered, false) @size = opts.fetch(:size, nil) @content = block || proc { '' } end |
Instance Method Details
#body(opts = {}, &block) ⇒ String
Builds the body component.
49 50 51 |
# File 'lib/bootstrap4_helper/modal.rb', line 49 def body(opts = {}, &block) build_main_component :body, opts, &block end |
#close_button(opts = {}) ⇒ String
Builds a close button component.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bootstrap4_helper/modal.rb', line 83 def (opts = {}) klass = opts.fetch(:class, '') content_tag( :button, type: 'button', class: block_given? ? klass : 'close', data: { dismiss: 'modal' }, aria: { label: 'Close' } ) do block_given? ? yield : end end |
#footer(opts = {}, &block) ⇒ String
Builds the footer component.
61 62 63 |
# File 'lib/bootstrap4_helper/modal.rb', line 61 def (opts = {}, &block) build_main_component :footer, opts, &block end |
#header(opts = {}, &block) ⇒ String
Build the header component for the modal.
37 38 39 |
# File 'lib/bootstrap4_helper/modal.rb', line 37 def header(opts = {}, &block) build_main_component :header, opts, &block end |
#title(opts = {}, &block) ⇒ String
Builds a title component.
73 74 75 |
# File 'lib/bootstrap4_helper/modal.rb', line 73 def title(opts = {}, &block) build_sub_component :h5, :title, opts, &block end |
#to_s ⇒ String
String representation of the object.
101 102 103 104 105 106 107 |
# File 'lib/bootstrap4_helper/modal.rb', line 101 def to_s content_tag :div, id: @id, class: "modal #{@class}", tabindex: -1, role: 'dialog', data: @data do content_tag :div, class: "modal-dialog #{size} #{scrollable} #{vcentered}", role: 'document' do content_tag(:div, class: 'modal-content') { @content.call(self) } end end end |