defmodule RiverConnectWeb.Components.UI.Avatar do @moduledoc """ Implementation of avatar component for user profile pictures with fallback support. Avatars are visual representations of users, typically displaying a profile picture or initials as a fallback. The component consists of a container, image, and fallback elements to ensure consistent display even when images fail to load. ## Examples: <.avatar> <.avatar_image src="/images/profile.jpg" alt="User avatar" /> <.avatar_fallback>JD <.avatar class="h-12 w-12"> <.avatar_image src={@user.avatar_url} alt={@user.name} /> <.avatar_fallback> """ use RiverConnectWeb.Components.UI, :component @doc """ Renders an avatar container. The avatar container is a wrapper that holds the avatar image and fallback content. ## Options * `:class` - Additional CSS classes to apply to the avatar container. ## Examples <.avatar> <.avatar_image src="/images/profile.jpg" alt="User avatar" /> <.avatar_fallback>JD <.avatar class="h-16 w-16">... """ attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: false def avatar(assigns) do ~H""" {render_slot(@inner_block)} """ end @doc """ Renders an avatar image. The image is set to display only after it has loaded, preventing layout shifts and allowing the fallback to show during loading. ## Options * `:src` - The URL of the avatar image. * `:alt` - The alt text for the image for accessibility. * `:class` - Additional CSS classes to apply to the image. ## Examples <.avatar_image src="/images/profile.jpg" alt="User profile" /> <.avatar_image src={@user.avatar_url} alt={@user.name} class="border-2" /> """ attr :class, :string, default: nil attr :rest, :global, include: ~w(alt src) def avatar_image(assigns) do ~H""" """ end @doc """ Renders an avatar fallback element. The fallback is displayed when the avatar image is not available or during image loading. This can contain text (like user initials) or an icon. ## Options * `:class` - Additional CSS classes to apply to the fallback element. ## Examples <.avatar_fallback>JD <.avatar_fallback class="bg-primary text-primary-foreground"> """ attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: false def avatar_fallback(assigns) do ~H""" {render_slot(@inner_block)} """ end end