defmodule RiverConnectWeb.Components.UI.Alert do @moduledoc """ Implementation of alert component for displaying important messages to users. Alerts are used to communicate status, warnings, or contextual feedback to users. They can be configured with different variants to indicate severity and typically consist of a title and a description. ## Examples: <.alert> <.alert_title>Note <.alert_description>This is a standard informational alert. <.alert variant="destructive"> <.alert_title>Error <.alert_description> There was a problem with your request. Please try again. <.alert> <.alert_title>Success <.alert_description>Your changes have been saved successfully. """ use RiverConnectWeb.Components.UI, :component @doc """ Renders an alert container. The alert component displays important messages or feedback to users with styling appropriate for the context. ## Options * `:variant` - The visual style of the alert. Available variants: * `"default"` - Standard alert styling (default) * `"destructive"` - Red-tinted styling for errors and warnings * `:class` - Additional CSS classes to apply to the alert container. ## Examples <.alert> <.alert_title>Information <.alert_description>This is an informational message. <.alert variant="destructive" class="mt-4"> <.alert_title>Warning <.alert_description>This action cannot be undone. """ attr :variant, :string, default: "default", values: ~w(default destructive) attr :class, :string, default: nil slot :inner_block, required: true attr :rest, :global, default: %{} def alert(assigns) do assigns = assign(assigns, :variant_class, variant(assigns)) ~H""" """ end @doc """ Renders an alert title. The title component is used to provide a concise heading for the alert message. ## Options * `:class` - Additional CSS classes to apply to the title. ## Examples <.alert_title>Success <.alert_title class="text-primary">Important Notice """ attr :class, :string, default: nil attr :rest, :global, include: ~w(disabled form name value) slot :inner_block, required: true def alert_title(assigns) do ~H"""
{render_slot(@inner_block)}
""" end @doc """ Renders an alert description. The description provides more detailed information about the alert message. ## Options * `:class` - Additional CSS classes to apply to the description. ## Examples <.alert_description>Your account has been updated successfully. <.alert_description class="text-gray-600"> Please review the changes before continuing. """ attr :class, :string, default: nil attr :rest, :global, include: ~w(disabled form name value) slot :inner_block, required: true def alert_description(assigns) do ~H"""
{render_slot(@inner_block)}
""" end @variants %{ variant: %{ "default" => "bg-background text-foreground", "destructive" => "bg-background border-destructive/50 text-destructive dark:border-destructive [&>span]:text-destructive" } } @default_variants %{ variant: "default" } defp variant(variants) do variants = Map.merge(@default_variants, variants) Enum.map_join(variants, " ", fn {key, value} -> @variants[key][value] end) end end