class NfgUi::Components::Elements::SlatItem

Slat doc coming soon

Public Instance Methods

caption() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 14
def caption
  options.fetch(:caption, nil)
end
component_family() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 18
def component_family
  :slats
end
render() { |: body)| ... } click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 33
def render
  content_tag(base_element, slat_item_html_options) do
    if slat_header
      concat(content_tag(:h6, slat_header, class: 'display-4 slat-column-header', **tooltip_html_options))
    end
    if heading
      if href
        concat(content_tag(:a, href: view_context.url_for(href)) {
          NfgUi::Components::Foundations::Typeface.new({ subheading: heading, tooltip: tooltip }, view_context).render
        })
      else
        concat(NfgUi::Components::Foundations::Typeface.new({ subheading: heading, tooltip: tooltip }, view_context).render)
      end
    end
    concat(block_given? ? yield : body)
    if caption
      concat(NfgUi::Components::Foundations::Typeface.new({ caption: caption, class: 'mb-0', tooltip: (tooltip unless heading) }, view_context).render)
    end
  end
end
slat_header() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 22
def slat_header
  options.fetch(:slat_header, nil)
end
tooltip() click to toggle source

Leverage custom tooltip implementation so that tooltips are connected to slat item text and not the slat item containing div (resulting in better UI)

# File lib/nfg_ui/components/elements/slat_item.rb, line 29
def tooltip
  options.fetch(:tooltip, nil)
end

Private Instance Methods

non_html_attribute_options() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 85
def non_html_attribute_options
  super.push(:slat_header, :caption, :tooltip)
end
resized?() click to toggle source

:sm is the default size, and is not given a `slat-item-sm` class name. thus, reject :sm from resizable symbols.

# File lib/nfg_ui/components/elements/slat_item.rb, line 81
def resized?
  [:md, :lg, :xl].include?(size)
end
slat_item_html_options() click to toggle source

Strip the href from html_options and pass it to the header

# File lib/nfg_ui/components/elements/slat_item.rb, line 68
def slat_item_html_options
  options = html_options.except(:href)

  # merge in tooltip only if leveraging block body content
  # tooltip_html_options will return {} if no tooltip so this is a safe merge
  options.merge!(tooltip_html_options) unless (heading || caption || slat_header)

  options
end
tooltip_data_attributes() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 61
def tooltip_data_attributes
  { toggle: 'tooltip',
    placement: :top,
    html: 'true' }
end
tooltip_html_options() click to toggle source
# File lib/nfg_ui/components/elements/slat_item.rb, line 56
def tooltip_html_options
  return {} unless tooltip
  { title: tooltip, data: options[:data].merge(tooltip_data_attributes) }
end