Class: PhlexKit::AvatarImage

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/avatar/avatar_image.rb

Overview

The image inside a PhlexKit::Avatar. NOT lazy-loaded on purpose (the controller hides a not-yet-loaded image so the fallback shows; a lazy image that never paints would never fire load). See avatar.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

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

Returns a new instance of AvatarImage.



6
7
8
9
10
# File 'app/components/phlex_kit/avatar/avatar_image.rb', line 6

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

Instance Method Details

#view_templateObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/components/phlex_kit/avatar/avatar_image.rb', line 12

def view_template
  img(**mix({
    src: @src,
    alt: @alt,
    class: "pk-avatar-image",
    data: {
      phlex_kit__avatar_target: "image",
      action: "load->phlex-kit--avatar#showImage error->phlex-kit--avatar#showFallback"
    }
  }, @attrs))
end