defmodule RiverConnectWeb.Components.UI.Dialog do @moduledoc """ Implement of Dialog components from https://ui.shadcn.com/docs/components/dialog """ use RiverConnectWeb.Components.UI, :component @doc """ Dialog component ## Examples: <.dialog id="pro-dialog" open={true}> <.dialog_trigger>Click me <.dialog_content class="sm:max-w-[425px]"> <.dialog_header> <.dialog_title>Edit profile <.dialog_description> Make changes to your profile here click save when you're done
<.label for="name" class-name="text-right"> name
<.label for="username" class="text-right"> username
<.dialog_footer> <.button type="submit">save changes """ attr :id, :string, required: true attr :open, :boolean, default: false attr :class, :string, default: nil attr :"close-on-outside-click", :boolean, default: true attr :"on-open", :any, default: nil, doc: "Handler for dialog open event. Support both server event handler and JS command struct" attr :"on-close", :any, default: nil, doc: "Handler for dialog closed event. Support both server event handler and JS command struct" slot :inner_block, required: true def dialog(assigns) do event_map = %{} |> add_event_mapping(assigns, "opened", :"on-open") |> add_event_mapping(assigns, "closed", :"on-close") assigns = assigns |> assign(:event_map, json(event_map)) |> assign(initial_state: if(assigns.open, do: "open", else: "closed")) |> assign( options: json(%{ closeOnOutsideClick: assigns[:"close-on-outside-click"], animations: get_animation_config() }) ) ~H"""
{render_slot(@inner_block)}
""" end attr :class, :string, default: nil attr :as, :any, default: "div" slot :inner_block, required: true attr :rest, :global def dialog_trigger(assigns) do ~H""" <.dynamic data-part="trigger" data-action="open" tag={@as} class={classes(["", @class])} {@rest}> {render_slot(@inner_block)} """ end attr :class, :string, default: nil slot :inner_block, required: true def dialog_content(assigns) do ~H"""