defmodule Noora.Tooltip do @moduledoc """ Renders a tooltip component with a trigger, customizable size, title, description, and optional icon. ## Example ```elixir <.tooltip id="help-tooltip" title="Click to learn more"> <:trigger :let={attrs}> <.tooltip id="info-tooltip" size="large" title="Important Information" description="This feature is currently in beta."> <:trigger :let={attrs}> <.icon name="info" /> <:icon> <.icon name="alert-circle" /> ``` """ use Phoenix.Component import Noora.Utils attr(:id, :string, required: true) attr(:disabled, :boolean, default: false) attr(:size, :string, values: ~w(small large), default: "small", doc: "Size of the tooltip") attr(:title, :string, required: true, doc: "Tooltip title") attr(:description, :string, doc: "Tooltip description. Only shown when `size` is set to large.") slot(:trigger, required: true, doc: "Tooltip trigger") slot(:icon, doc: "Icon to be rendered inside the tooltip. Only shown when `size` is set to large." ) slot(:inner_block, doc: "Content to be rendered inside the tooltip") def tooltip(assigns) do ~H"""
{render_slot(@trigger, %{"data-part" => "trigger"})}
<%= if @size == "small" do %>
{@title}
<% end %> <%= if @size == "large" do %>
{render_slot(@icon)}
{@title} {@description}
<% end %>
""" end end