Class: NfgUi::Components::Patterns::PageHeader

Inherits:
Base show all
Includes:
Traits::PageHeader, Utilities::BrowserDetectable, Utilities::Iconable, Utilities::Renderable, Utilities::ResourceThemeable, Utilities::Titleable
Defined in:
lib/nfg_ui/components/patterns/page_header.rb

Overview

PageHeader doc coming soon

Constant Summary

Constants included from Traits::PageHeader

Traits::PageHeader::TRAITS

Constants included from Utilities::ResourceThemeable

Utilities::ResourceThemeable::DEFAULT_THEME_COLOR, Utilities::ResourceThemeable::FALLBACK_ICON

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::PageHeader

#sticky_trait

Methods included from Utilities::Titleable

#title

Methods included from Utilities::ResourceThemeable

#resource_theme_color, #resource_theme_name

Methods included from Utilities::Renderable

#render_if, #render_unless

Methods included from Utilities::Iconable

#icon

Methods included from Utilities::BrowserDetectable

#browser

Methods included from Utilities::Traitable

#traits, #utility_initialize

Methods included from Utilities::Describable

#describe

Methods inherited from Bootstrap::Components::Base

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

Constructor Details

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

Instance Method Details

#dataObject



16
17
18
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 16

def data
  sticky ? super.merge!(toggle: 'sticky-div') : super
end

#full_widthObject

Supplies a slightly smaller design-system approved column structure when set to false (as used in Evo), by default. DMS, however requires a simple ‘col’ (full width) layout and will have :full_width set to true manually while both apps co-exist with slightly different page layouts.



25
26
27
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 25

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

#renderObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 47

def render
  html_options[:class] ||= ''
  html_options[:class] << ' container-fluid'

  (:div, html_options) do
    (:div, class: 'row') do
      (:div, class: column_structure_css_classes) do
        (:div, class: 'row align-items-center') do
          concat((:div, class: 'col py-2') {
            NfgUi::Components::Patterns::Media.new({}, view_context).render do
              capture do
                concat(NfgUi::Components::Elements::MediaObject.new({}, view_context).render {
                  (:div, class: 'mt-lg-1 mr-2 h3') do
                    NfgUi::Components::Foundations::Icon.new({ traits: [resource_theme_icon], class: "text-#{resource_theme_color} mr-0" }, view_context).render
                  end
                })
                concat(NfgUi::Components::Elements::MediaBody.new({}, view_context).render {
                  (:h1) do
                    if subtitle
                      concat((:span, title, class: 'mr-2'))
                      concat((:small, subtitle, class: 'text-muted'))

                    else
                      concat(title)
                    end
                  end
                })
              end
            end
          })
          if body
            concat((:div, class: 'col-12 col-md-auto py-2') {
              NfgUi::Components::Patterns::ButtonToolbar.new({ class: 'align-items-center' }, view_context).render do
                (block_given? ? yield : body)
              end
            })
          end
        end
      end
    end
  end
end

#resource_theme_iconObject



38
39
40
41
42
43
44
45
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 38

def resource_theme_icon
  # Prefer :icon in options over resource_theme_icon autolookup
  # #icon is made available by Iconable,
  # effectively allowing `icon: 'example'` to overwrite
  # the auto resource_theme_icon version.
  return icon if icon.present?
  super
end

#stickyObject



29
30
31
32
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 29

def sticky
  return if Rails.env.test? || browser.mobile?
  options.fetch(:sticky, true)
end

#subtitleObject



34
35
36
# File 'lib/nfg_ui/components/patterns/page_header.rb', line 34

def subtitle
  options.fetch(:subtitle, nil)
end