Class: Bootstrap5Helper::Modal
- Defined in:
- lib/bootstrap5_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, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ Modal
Class constructor
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bootstrap5_helper/modal.rb', line 21 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) @static = opts.fetch(:static, false) @fullscreen = opts.fetch(:fullscreen, false) @size = opts.fetch(:size, nil) @content = block || proc { '' } end |
Instance Method Details
#body(opts = {}, &block) ⇒ String
Builds the body component.
55 56 57 |
# File 'lib/bootstrap5_helper/modal.rb', line 55 def body(opts = {}, &block) build_main_component :body, opts, &block end |
#close_button(opts = {}) ⇒ String
Builds a close button component.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bootstrap5_helper/modal.rb', line 89 def (opts = {}) klass = opts.fetch(:class, '') content_tag( :button, type: 'button', class: block_given? ? klass : 'btn-close', data: { 'bs-dismiss': 'modal' }, aria: { label: 'Close' } ) do block_given? ? yield : end end |
#footer(opts = {}, &block) ⇒ String
Builds the footer component.
67 68 69 |
# File 'lib/bootstrap5_helper/modal.rb', line 67 def (opts = {}, &block) build_main_component :footer, opts, &block end |
#header(opts = {}, &block) ⇒ String
Build the header component for the modal.
43 44 45 |
# File 'lib/bootstrap5_helper/modal.rb', line 43 def header(opts = {}, &block) build_main_component :header, opts, &block end |
#title(opts = {}, &block) ⇒ String
Builds a title component.
79 80 81 |
# File 'lib/bootstrap5_helper/modal.rb', line 79 def title(opts = {}, &block) build_sub_component config({ modals: :title }, :h5), :title, opts, &block end |
#to_s ⇒ String
String representation of the object.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bootstrap5_helper/modal.rb', line 109 def to_s @data.merge!('bs-backdrop' => 'static', 'bs-keyboard' => false) if @static content_tag( :div, id: @id, class: "modal #{@class}", tabindex: -1, role: 'dialog', data: @data ) do content_tag( :div, class: "modal-dialog #{size} #{scrollable} #{vcentered} #{fullscreen}", role: 'document' ) do content_tag(:div, class: 'modal-content') { @content.call(self) } end end end |