Class: NfgUi::Components::Patterns::Collapse

Overview

Button Group doesn’t have any customizations unique to the design system yet As such, the NFG UI button group is simply a bootstrap button group behind the scenes. Traits will eventually be connected here.

Constant Summary

Constants included from Traits::Collapse

Traits::Collapse::TRAITS

Constants included from Traits

Traits::REGISTERED_TRAITS, Traits::TRAIT_MODULES

Instance Attribute Summary

Attributes inherited from Bootstrap::Components::Base

#body, #options, #view_context

Instance Method Summary collapse

Methods included from Traits::Collapse

#collapsed_trait, #collapsible_trait, #navbar_trait

Methods included from Utilities::Renderable

#render_if, #render_unless

Methods included from Utilities::Describable

#data, #describe

Methods included from Utilities::Traitable

#traits, #utility_initialize

Methods included from Bootstrap::Utilities::Headable

#heading

Methods inherited from Bootstrap::Components::Collapse

#navbar

Methods included from Bootstrap::Utilities::Collapsible

#collapse, #collapsed, #collapsible

Methods inherited from Bootstrap::Components::Base

#component_family, #data, #href, #html_options, #id, #initialize, #style

Constructor Details

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

Instance Method Details

#component_initializeObject

Because it is common to forget to add the required :id to the component options when doing a “speed built” collapse, example:

ui.nfg :collapse, :collapsed, body: ‘Collapse body content’, heading: ‘My Link’

Send in a random string that is carried through from the speed built heading / button AND to the collapse component.



26
27
28
29
30
31
# File 'lib/nfg_ui/components/patterns/collapse.rb', line 26

def component_initialize
  # Only create and supply a random ID this when a :heading is present
  return unless heading
  new_id = options[:id].nil? ? random_id : options[:id]
  options[:id] = new_id
end

#renderObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nfg_ui/components/patterns/collapse.rb', line 33

def render
  capture do
    if heading
      icon = options.fetch(:icon, 'caret-down')
      opts = { collapse: "##{html_options[:id]}", body: heading, icon: icon, class: 'pl-0 text-left' }
      opts.merge!(traits: [:link, :block])
      concat(NfgUi::Components::Elements::Button.new(opts, view_context).render)
    end
    concat(super)
  end
end