Class: Daisy::DataDisplay::AvatarComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent, LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/data_display/avatar_component.rb

Overview

Note:

Whenever no src is given — including icon-only avatars — the wrapper defaults to where:bg-neutral where:text-neutral-content so the placeholder text or icon stays readable. These defaults are suppressed whenever skeleton appears in wrapper_css, allowing the skeleton shimmer to render correctly without the neutral background bleeding through. Use wrapper_css: "skeleton" to display a properly colored skeleton avatar.

The Avatar component displays an image, icon, or placeholder text to represent a user or entity. It provides a consistent, circular display with fallback options when an image is not available.

Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.

It utilizes the CSS where() pseudo-class to reduce the specificity to 0 to allow for easy overriding while giving you some sane defaults.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods included from LocoMotion::Concerns::IconableComponent

#has_icons?, #left_icon_html, #render_left_icon, #render_right_icon, #right_icon_html

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws, &block) ⇒ AvatarComponent

Create a new avatar component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • src (String)

    URL to the avatar image. If not provided, the component will display an icon or placeholder content.

  • icon (String)

    Name of the icon to display when no image is provided. If neither src nor icon is provided, placeholder content from the block will be shown.

  • icon_css (String)

    The CSS classes to apply to the icon.

  • icon_html (Hash)

    Additional HTML attributes to apply to the icon.

  • icon_options (Hash)

    Additional keyword arguments forwarded to the icon component (e.g. tip:).

  • href (String)

    A path or URL to which the user will be directed when the avatar is clicked. Forces the Avatar to use an <a> tag.

  • target (String)

    The HTML target attribute for the <a> tag (_blank, _parent, or a specific tab / window / iframe, etc).

  • tip (String)

    The tooltip text to display when hovering over the component.

  • alt (String)

    The alt text for the image, used by screen readers and shown when the image fails to load. Omitted when not provided.



89
90
91
92
93
94
# File 'app/components/daisy/data_display/avatar_component.rb', line 89

def initialize(**kws, &block)
  super

  @src = config_option(:src)
  @alt = config_option(:alt)
end

Instance Method Details

#before_renderObject



96
97
98
99
100
101
# File 'app/components/daisy/data_display/avatar_component.rb', line 96

def before_render
  # Run component setup *before* super to allow BaseComponent hooks to run last
  setup_component

  super
end