Method: Bootstrap4Helper::Dropdown#button

Defined in:
lib/bootstrap4_helper/dropdown.rb

#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.

Parameters:

  • context (Symbol) (defaults to: :primary)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :split (Boolean)
  • :id (String)
  • :class (String)
  • :data (Hash)

Returns:

  • (String)


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 button(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' : ''

  (
    :button,
    id:    id,
    type:  'button',
    class: "dropdown-toggle btn btn-#{context} #{klass} #{extra}",
    data:  data,
    aria:  { haspopup: true, expanded: false }
  ) do
    split ? (:span, 'Toggle Dropdwon', class: 'sr-only') : yield
  end
end