Class: Bootstrap4Helper::Dropdown
- Defined in:
- lib/bootstrap4_helper/dropdown.rb,
lib/bootstrap4_helper/dropdown/menu.rb
Overview
Builds a Dropdown component that can be used in other components.
Defined Under Namespace
Classes: Menu
Instance Method Summary collapse
-
#button(context = :primary, opts = {}) ⇒ String
Used to generate a button for the dropdown.
-
#initialize(template, type = :dropdown, opts = {}, &block) ⇒ Dropdown
constructor
Class constructor.
-
#menu(opts = {}, &block) ⇒ Dropdown::Menu
Used to create a new ‘Dropdown::Menu`.
-
#to_s ⇒ String
String reprentation of the object.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, type = :dropdown, opts = {}, &block) ⇒ Dropdown
Class constructor
15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap4_helper/dropdown.rb', line 15 def initialize(template, type = :dropdown, opts = {}, &block) super(template) @type = type @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#button(context = :primary, opts = {}) ⇒ String
Used to generate a button for the dropdown. The buttons default as just a button that opens the coresponding dropdown menu. The ‘split: true` option make the button just the arrow indicator that open the menu.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bootstrap4_helper/dropdown.rb', line 37 def (context = :primary, opts = {}) split = opts.fetch(:split, false) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}).merge(toggle: 'dropdown') extra = split ? 'dropdown-toggle-split' : '' content_tag( :button, id: id, type: 'button', class: "dropdown-toggle btn btn-#{context} #{klass} #{extra}", data: data, aria: { haspopup: true, expanded: false } ) do split ? content_tag(:span, 'Toggle Dropdwon', class: 'sr-only') : yield end end |
#menu(opts = {}, &block) ⇒ Dropdown::Menu
Used to create a new ‘Dropdown::Menu`
64 65 66 |
# File 'lib/bootstrap4_helper/dropdown.rb', line 64 def (opts = {}, &block) Menu.new(@template, opts, &block) end |
#to_s ⇒ String
String reprentation of the object.
72 73 74 75 76 |
# File 'lib/bootstrap4_helper/dropdown.rb', line 72 def to_s content_tag :div, id: @id, class: "#{container_class} #{@class}", data: @data do @content.call(self) end end |