Class: NfgUi::Bootstrap::Components::DropdownToggle

Inherits:
Base
  • Object
show all
Includes:
Utilities::Sizable, Utilities::Wrappable
Defined in:
lib/nfg_ui/bootstrap/components/dropdown_toggle.rb

Overview

Bootstrap Dropdown Component getbootstrap.com/docs/4.1/components/dropdowns/

Direct Known Subclasses

Components::Elements::DropdownToggle

Instance Attribute Summary

Attributes included from Utilities::Wrappable

#as

Attributes inherited from Base

#body, #options, #view_context

Instance Method Summary collapse

Methods included from Utilities::Sizable

#size

Methods included from Utilities::Wrappable

#utility_initialize

Methods inherited from Base

#html_options, #id, #initialize, #style

Constructor Details

This class inherits a constructor from NfgUi::Bootstrap::Components::Base

Instance Method Details

#component_familyObject



12
13
14
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 12

def component_family
  :dropdown
end

#dataObject



16
17
18
19
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 16

def data
  data_toggle = (options[:data] || {}).merge!(toggle: 'dropdown')
  offset.present? ? { **data_toggle, offset: offset } : data_toggle
end

#hrefObject



21
22
23
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 21

def href
  as == :a ? '#' : super
end


25
26
27
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 25

def nav_link
  options.fetch(:nav_link, false)
end

#offsetObject



29
30
31
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 29

def offset
  options.fetch(:offset, '')
end

#renderObject



46
47
48
49
50
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 46

def render
  NfgUi::Bootstrap::Components::Button.new({ as: as, theme: theme, **html_options, remove_component_css_classes: nav_link }, view_context).render do
    (block_given? ? yield : body)
  end
end

#splitObject



33
34
35
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 33

def split
  options.fetch(:split, false)
end

#themeObject

Bypass & Skip Bootstrap::Utilities::Themeable module this method just passes the options to the button component Otherwise, if utilizing :button AND Themeable, we end up with duplicate theme css classes being sent to the button… ex: <button class=‘btn-danger btn-danger’…>



42
43
44
# File 'lib/nfg_ui/bootstrap/components/dropdown_toggle.rb', line 42

def theme
  options.fetch(:theme, NfgUi::DEFAULT_BOOTSTRAP_THEME)
end