From 0794f740d1ad9bb45b9ed3949a297b0c53a6d7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lobo?= <30907944+joaodiaslobo@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:55:48 +0100 Subject: [PATCH 1/4] feat: avatar group component (#529) --- assets/css/components/avatar.css | 6 + lib/atomic_web/components/avatar.ex | 75 ++++++- .../components/department_card.ex | 34 +-- .../live/department_live/show.html.heex | 24 ++- storybook/components/avatar_group.story.exs | 196 ++++++++++++++++++ 5 files changed, 313 insertions(+), 22 deletions(-) create mode 100644 storybook/components/avatar_group.story.exs diff --git a/assets/css/components/avatar.css b/assets/css/components/avatar.css index 1bdae7f01..74e76cd17 100644 --- a/assets/css/components/avatar.css +++ b/assets/css/components/avatar.css @@ -94,4 +94,10 @@ .atomic-avatar--src { @apply bg-transparent; +} + +/* Avatar Group */ + +.atomic-avatar-grouped { + @apply ring-1 ring-white; } \ No newline at end of file diff --git a/lib/atomic_web/components/avatar.ex b/lib/atomic_web/components/avatar.ex index 9dacd363a..2db005261 100644 --- a/lib/atomic_web/components/avatar.ex +++ b/lib/atomic_web/components/avatar.ex @@ -21,7 +21,7 @@ defmodule AtomicWeb.Components.Avatar do doc: "The size of the avatar." attr :color, :atom, - default: :primary, + default: :light_gray, values: [ :primary, :secondary, @@ -36,13 +36,13 @@ defmodule AtomicWeb.Components.Avatar do :light, :dark ], - doc: "Button color." + doc: "Avatar color." attr :class, :string, default: "", doc: "Additional classes to apply to the component." def avatar(assigns) do ~H""" - + <%= if @src do %> <% else %> @@ -56,7 +56,62 @@ defmodule AtomicWeb.Components.Avatar do """ end - defp generate_classes(assigns) do + attr :items, :list, required: true, doc: "The list of avatars to display." + + attr :spacing, :integer, + default: -1, + values: [-3, -2, -1, 0, 1, 2, 3], + doc: "The spacing between avatars." + + attr :type, :atom, + values: [:user, :organization, :company], + default: :user, + doc: "The type of entity associated with the avatars." + + attr :size, :atom, + values: [:xs, :sm, :md, :lg, :xl], + default: :md, + doc: "The size of the avatars." + + attr :color, :atom, + default: :light_gray, + values: [ + :primary, + :secondary, + :info, + :success, + :warning, + :danger, + :gray, + :light_gray, + :pure_white, + :white, + :light, + :dark + ], + doc: "Avatar color." + + attr :wrap, :boolean, default: false, doc: "Whether to wrap the avatars in a flex container." + + attr :class, :string, default: "", doc: "Additional classes to apply to the component." + + attr :avatar_class, :string, + default: "", + doc: "Additional classes to apply to the individual avatars." + + def avatar_group(assigns) do + ~H""" + + """ + end + + defp generate_avatar_classes(assigns) do [ "atomic-avatar", assigns.src && "atomic-avatar--src", @@ -66,4 +121,16 @@ defmodule AtomicWeb.Components.Avatar do assigns.class ] end + + defp generate_avatar_group_spacing_class(spacing) do + %{ + -3 => "-space-x-3", + -2 => "-space-x-2", + -1 => "-space-x-1", + 0 => "space-x-0", + 1 => "space-x-1", + 2 => "space-x-2", + 3 => "space-x-3" + }[spacing] + end end diff --git a/lib/atomic_web/live/department_live/components/department_card.ex b/lib/atomic_web/live/department_live/components/department_card.ex index f67f711f7..34c885c4f 100644 --- a/lib/atomic_web/live/department_live/components/department_card.ex +++ b/lib/atomic_web/live/department_live/components/department_card.ex @@ -24,18 +24,28 @@ defmodule AtomicWeb.DepartmentLive.Components.DepartmentCard do

<%= gettext("Archived") %>

- + <.avatar_group + size={:xs} + color={:light_gray} + spacing={-2} + class="min-h-8 mt-4 mb-2" + items={ + @collaborators + |> Enum.take(4) + |> Enum.map(fn person -> + %{ + name: person.user.name + } + end) + |> then(fn avatars -> + if length(@collaborators) > 4 do + Enum.concat(avatars, [%{name: "+#{length(@collaborators) - 4}", auto_generate_initials: false}]) + else + avatars + end + end) + } + /> """ diff --git a/lib/atomic_web/live/department_live/show.html.heex b/lib/atomic_web/live/department_live/show.html.heex index 67b1a647d..2807cd7a1 100644 --- a/lib/atomic_web/live/department_live/show.html.heex +++ b/lib/atomic_web/live/department_live/show.html.heex @@ -165,12 +165,24 @@