Class: DaisyUI::AvatarGroup

Inherits:
BaseComponent show all
Defined in:
app/components/daisy_ui/data_display/avatar_group.rb

Overview

Avatar group component that displays a collection of avatars with customizable styling

Examples:

Basic usage

<%= render(AvatarGroupComponent.new) do |group| %>
  <% group.with_avatar(img_src: "path/to/image.jpg", img_alt: "User 1") %>
  <% group.with_avatar(img_src: "path/to/image.jpg", img_alt: "User 2") %>
<% end %>

With max display and counter

<%= render(AvatarGroupComponent.new(max_display: 2)) do |group| %>
  <% group.with_avatar(img_src: "path/to/image.jpg", img_alt: "User 1") %>
  <% group.with_avatar(img_src: "path/to/image.jpg", img_alt: "User 2") %>
  <% group.with_avatar(img_src: "path/to/image.jpg", img_alt: "User 3") %>
<% end %>

Constant Summary collapse

SIZES =
Avatar::SIZES
SHAPES =
Avatar::SHAPES
DEFAULT_SPACING =
1.5

Instance Method Summary collapse

Constructor Details

#initialize(size: nil, shape: nil, spacing: DEFAULT_SPACING, max_display: nil, **system_arguments) ⇒ AvatarGroup

Initializes a new Avatar Group component



39
40
41
42
43
44
45
46
# File 'app/components/daisy_ui/data_display/avatar_group.rb', line 39

def initialize(size: nil, shape: nil, spacing: DEFAULT_SPACING, max_display: nil, **system_arguments)
  @size = size
  @shape = shape
  @spacing = spacing.to_f
  @max_display = max_display&.to_i

  super(**system_arguments)
end

Instance Method Details

#callString



49
50
51
52
53
54
55
56
# File 'app/components/daisy_ui/data_display/avatar_group.rb', line 49

def call
  tag.div(**html_attributes) do
    content = []
    content.concat(displayed_avatars)
    content << render_counter if remaining_count
    safe_join(content)
  end
end