Class: UI::AvatarImage

Inherits:
Phlex::HTML
  • Object
show all
Includes:
AvatarImageBehavior
Defined in:
app/components/ui/avatar_image.rb

Overview

Avatar Image - Phlex implementation

Displays the avatar image. Only renders when it has loaded successfully. Uses AvatarImageBehavior module for shared styling logic.

Based on shadcn/ui Avatar: ui.shadcn.com/docs/components/avatar Based on Radix UI Avatar: www.radix-ui.com/primitives/docs/components/avatar

Examples:

Basic usage

render UI::Image.new(
  src: "https://github.com/shadcn.png",
  alt: "User avatar"
)

Instance Method Summary collapse

Methods included from AvatarImageBehavior

#avatar_image_classes, #avatar_image_data_attributes, #avatar_image_html_attributes

Constructor Details

#initialize(src:, alt: "", classes: "", **attributes) ⇒ AvatarImage

Returns a new instance of AvatarImage.

Parameters:

  • src (String)

    Image source URL

  • alt (String) (defaults to: "")

    Alternative text for the image

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



23
24
25
26
27
28
# File 'app/components/ui/avatar_image.rb', line 23

def initialize(src:, alt: "", classes: "", **attributes)
  @src = src
  @alt = alt
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_templateObject



30
31
32
# File 'app/components/ui/avatar_image.rb', line 30

def view_template
  img(**avatar_image_html_attributes.deep_merge(@attributes))
end