Class: Bootstrap5Helper::Offcanvas::Content
- Defined in:
- lib/bootstrap5_helper/offcanvas/content.rb
Overview
Builds a Content component for use in offcanvas.
Instance Method Summary collapse
- #body(opts = {}, &block) ⇒ Object
- #close_button(opts = {}) ⇒ Object
- #header(opts = {}, &block) ⇒ Object
-
#initialize(template, opts = {}, &block) ⇒ ClassName
constructor
Constructor description…
- #title(text_or_options = nil, opts = {}, &block) ⇒ Object
- #to_s ⇒ 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) ⇒ ClassName
Constructor description…
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 13 def initialize(template, opts = {}, &block) super(template) @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @aria = opts.fetch(:aria, {}) @scrollable = opts.fetch(:scrollable, false) @position = opts.fetch(:position, 'start') @backdrop = opts.fetch(:backdrop, true) @content = block || proc { '' } end |
Instance Method Details
#body(opts = {}, &block) ⇒ Object
TODO:
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 82 def body(opts = {}, &block) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}) aria = opts.fetch(:aria, {}) content_tag( :div, id: id, class: "offcanvas-body #{klass}", data: data, aria: aria, &block ) end |
#close_button(opts = {}) ⇒ Object
TODO:
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 66 def (opts = {}) klass = opts.fetch(:class, '') content_tag( config({ offcanvas: :close }, :button), class: block_given? ? klass : 'btn-close', data: { 'bs-dismiss': 'offcanvas' }, aria: { label: 'Close' } ) do block_given? ? yield : end end |
#header(opts = {}, &block) ⇒ Object
TODO:
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 29 def header(opts = {}, &block) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}) content_tag( config({ offcanvas: :header }, :div), id: id, class: "offcanvas-header #{klass}", data: data, &block ) end |
#title(text_or_options = nil, opts = {}, &block) ⇒ Object
TODO:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 46 def title( = nil, opts = {}, &block) text, args = (, opts) id = args.fetch(:id, nil) klass = args.fetch(:class, '') data = args.fetch(:data, {}) content_tag( config({ offcanvas: :title }, :h6), text, id: id, class: "offcanvas-title #{klass}", data: data, &block ) end |
#to_s ⇒ Object
TODO:
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bootstrap5_helper/offcanvas/content.rb', line 101 def to_s @data.merge!('bs-scroll': @scrollable) @data.merge!('bs-backdrop': @backdrop) content_tag( :div, id: @id, class: "offcanvas offcanvas-#{@position} #{@class}", tabindex: -1, data: @data, aria: { labelledby: 'offcanvasExampleLabel' } ) do @content.call(self) end end |