class NfgUi::Components::Elements::Avatar

Activity doc coming soon

Public Instance Methods

alt() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 13
def alt
  options.fetch(:alt, nil)
end
image() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 17
def image
  options.fetch(:image, nil)
end
render() { |: body), class: body_css_class)| ... } click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 21
def render
  content_tag(as, html_options) do
    if image.present?
      image_tag view_context.image_path(image), alt: alt.presence
    elsif body.present?
      content_tag(:span, (block_given? ? yield : body), class: body_css_class)
    end
  end
end
size() click to toggle source

Set the default size if no size is set. Avatars, unlike other components, always have a size provided to them. This also rejects nil from fetching as a fallback

# File lib/nfg_ui/components/elements/avatar.rb, line 35
def size
  options[:size] || default_size
end

Private Instance Methods

body_css_class() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 41
def body_css_class
  'avatar-text'
end
default_html_wrapper_element() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 45
def default_html_wrapper_element
  :div
end
default_size() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 49
def default_size
  :md
end
non_html_attribute_options() click to toggle source
# File lib/nfg_ui/components/elements/avatar.rb, line 53
def non_html_attribute_options
  super.push(:image, :alt)
end
resized?() click to toggle source

Sizable doesn't allow components to use illegal sizes (anything other than :sm or :lg) When an illegal size is detected, it does not generate the size css class (e.g.: 'avatar-xl')

nfg_ui implements more sizes than “sm” and “lg”, We set resized? updated restrictions here, instead. allowing updated size css classes to be passed to html_options

# File lib/nfg_ui/components/elements/avatar.rb, line 63
def resized?
  [:sm, :md, :lg, :xl].include?(size)
end