Module: UI::AvatarImageBehavior

Included in:
AvatarImage, AvatarImageComponent
Defined in:
app/behaviors/ui/avatar_image_behavior.rb

Overview

AvatarImageBehavior

Shared behavior for AvatarImage component across ERB, ViewComponent, and Phlex implementations. This module provides consistent styling and HTML attribute generation for avatar images.

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

Instance Method Summary collapse

Instance Method Details

#avatar_image_classes ⇒ Object

Returns combined CSS classes for the avatar image



22
23
24
25
26
27
28
# File 'app/behaviors/ui/avatar_image_behavior.rb', line 22

def avatar_image_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  TailwindMerge::Merger.new.merge([
    avatar_image_base_classes,
    classes_value
  ].compact.join(" "))
end

#avatar_image_data_attributes ⇒ Object

Returns data attributes for Stimulus target



31
32
33
34
35
36
# File 'app/behaviors/ui/avatar_image_behavior.rb', line 31

def avatar_image_data_attributes
  {
    "ui--avatar_target": "image",
    slot: "avatar-image"
  }
end

#avatar_image_html_attributes ⇒ Object

Returns HTML attributes for the avatar image element



12
13
14
15
16
17
18
19
# File 'app/behaviors/ui/avatar_image_behavior.rb', line 12

def avatar_image_html_attributes
  {
    src: @src,
    alt: @alt,
    class: avatar_image_classes,
    data: avatar_image_data_attributes
  }
end