Class: NfgUi::Components::Elements::Alert

Overview

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

Constant Summary

Constants included from Traits::Theme

Traits::Theme::COLOR_TRAITS, Traits::Theme::TRAITS

Constants included from Traits::Dismiss

Traits::Dismiss::TRAITS

Constants included from Traits::Alert

Traits::Alert::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::Theme

#danger_trait, #dark_trait, #info_trait, #light_trait, #outlined_trait, #primary_trait, #secondary_trait, #success_trait, #warning_trait, #white_trait

Methods included from Traits::Dismiss

#dismissible_trait

Methods included from Traits::Alert

#tip_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 Utilities::Iconable

#icon

Methods included from Bootstrap::Utilities::Themeable

#outlined, #theme

Methods included from Bootstrap::Utilities::Headable

#heading

Methods included from Bootstrap::Utilities::Dismissible

#dismissible

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

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nfg_ui/components/elements/alert.rb', line 19

def render
  # NOTE: concat statement must be surrounded by capture blocks.
  # If you see duplication of content, it is likely because that
  # a concat has been called outside of a capture block.
  # This is specifically true when some of those concats are nested
  # or are within a block defined within the capture block
  (:div, html_options) do
    capture do
      if dismissible
        concat(NfgUi::Components::Elements::Button.new({ traits: [:close], dismiss: :alert }, view_context).render)
      end

      if icon
        concat(NfgUi::Components::Patterns::Media.new({}, view_context).render {
          capture do

            concat(NfgUi::Components::Elements::MediaObject.new({}, view_context).render {
              (:div, class: 'mr-2') do
                NfgUi::Components::Foundations::Icon.new({ traits: [icon] }, view_context).render
              end
            })
            concat(NfgUi::Components::Elements::MediaBody.new({}, view_context).render {
              capture do
                if heading
                  concat(NfgUi::Components::Foundations::Typeface.new({ heading: heading, class: 'alert-heading' }, view_context).render)
                end
                concat(block_given? ? yield : body)
              end
            })
          end
        })
      else
        if heading
          concat(NfgUi::Components::Foundations::Typeface.new({ heading: heading, class: 'alert-heading' }, view_context).render)
        end

        concat(block_given? ? yield : body)
      end
    end
  end
end