Class: PhlexKit::Avatar
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Avatar
- 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
-
#initialize(size: :md, **attrs) ⇒ Avatar
constructor
A new instance of Avatar.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
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 |