Class: PhlexKit::Avatar

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

Overview

Avatar, ported from ruby_ui's RubyUI::Avatar — a round image with a fallback (initials). Keeps ruby_ui's phlex-kit--avatar Stimulus controller (shows the image once it loads, else the fallback). Compose AvatarImage + AvatarFallback; fallback-only is fine (the controller no-ops without an image). SIZES.fetch fails loud. Tailwind → vanilla .pk-avatar* (avatar.css).

Constant Summary collapse

SIZES =
{ xs: "xs", sm: "sm", md: nil, lg: "lg", xl: "xl" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(size: :md, **attrs) ⇒ Avatar

Returns a new instance of Avatar.



10
11
12
13
# File 'app/components/phlex_kit/avatar/avatar.rb', line 10

def initialize(size: :md, **attrs)
  @size = size.to_sym
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



15
16
17
# File 'app/components/phlex_kit/avatar/avatar.rb', line 15

def view_template(&block)
  span(**mix({ class: classes, data: { controller: "phlex-kit--avatar" } }, @attrs), &block)
end