Class: Bootstrap5Helper::Overlay
- Defined in:
- lib/bootstrap5_helper/overlay.rb,
lib/bootstrap5_helper/overlay/menu.rb
Overview
Builds a Overlay component that can be used in other components.
Defined Under Namespace
Classes: Menu
Instance Method Summary collapse
-
#button(context = :primary, opts = {}, &block) ⇒ String
Used to generate a button for the dropdown.
-
#caret(context = :primary, opts = {}) ⇒ String
Used to generate a button with just the caret, to open the dropdown.
-
#initialize(template, *tag_or_options, &block) ⇒ Overlay
constructor
Class constructor.
-
#menu(*tag_or_options) {|Menu| ... } ⇒ Menu
Used to create a new
Overlay::Menu
. -
#to_s ⇒ String
String reprentation 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, tag, opts) ⇒ Overlay #initialize(template, opts) ⇒ Overlay
Class constructor
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bootstrap5_helper/overlay.rb', line 27 def initialize(template, *, &block) super(template) @tag, args = (*, {}) @split = args.fetch(:split, false) @centered = args.fetch(:centered, false) @id = args.fetch(:id, uuid) @class = args.fetch(:class, '') @data = args.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#button(context = :primary, opts = {}, &block) ⇒ String
Used to generate a button for the dropdown. This button just opens the coresponding dropdown menu.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bootstrap5_helper/overlay.rb', line 50 def (context = :primary, opts = {}, &block) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}).merge( 'bs-toggle' => 'dropdown', 'bs-display' => 'static' ) content_tag( :button, id: id, type: 'button', class: "dropdown-toggle btn btn-#{context} #{klass}", data: data, aria: { haspopup: true, expanded: false }, &block ) end |
#caret(context = :primary, opts = {}) ⇒ String
Used to generate a button with just the caret, to open the dropdown.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bootstrap5_helper/overlay.rb', line 78 def caret(context = :primary, opts = {}) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}).merge('bs-toggle' => 'dropdown') content_tag( :button, id: id, type: 'button', class: "dropdown-toggle btn btn-#{context} #{klass} dropdown-toggle-split", data: data, aria: { haspopup: true, expanded: false } ) do content_tag(:span, 'Toggle Dropdown', class: 'visually-hidden') end end |
#menu(*tag_or_options) {|Menu| ... } ⇒ Menu
Used to create a new Overlay::Menu
104 105 106 |
# File 'lib/bootstrap5_helper/overlay.rb', line 104 def (*, &block) Menu.new(@template, *, &block) end |
#to_s ⇒ String
String reprentation of the object.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/bootstrap5_helper/overlay.rb', line 112 def to_s content_tag( @tag || :div, id: @id, class: "#{@type} #{alignment_type_class} #{@class}", data: @data ) do @content.call(self) end end |