Class: KozenetUi::AvatarComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/kozenet_ui/avatar_component.rb

Overview

Avatar component for user profiles and images Supports images, initials, and icons with multiple sizes

Examples:

With image

<%= kz_avatar(src: user.avatar_url, alt: user.name) %>

With initials

<%= kz_avatar(initials: "JD", variant: :primary) %>

With custom size

<%= kz_avatar(src: url, size: :lg) %>

Constant Summary

Constants inherited from BaseComponent

BaseComponent::UNSET

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_options, #size, #variant

Instance Method Summary collapse

Constructor Details

#initialize(src: nil, alt: "Avatar", initials: nil, variant: :primary, size: :md, html_options: {}) ⇒ AvatarComponent

rubocop:disable Metrics/ParameterLists



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/kozenet_ui/avatar_component.rb', line 17

def initialize(
  src: nil,
  alt: "Avatar",
  initials: nil,
  variant: :primary,
  size: :md,
  html_options: {}
)
  super(variant: variant, size: size, **html_options)
  @src = src
  @alt = alt
  @initials = initials
end

Instance Method Details

#callObject

rubocop:enable Metrics/ParameterLists



32
33
34
35
36
# File 'app/components/kozenet_ui/avatar_component.rb', line 32

def call
  tag.div(**html_attrs) do
    avatar_content
  end
end