defmodule Paleta.Components.Form do
@moduledoc """
A simple form component that wraps a form tag and provides a default layout
"""
use Phoenix.Component
slot(:inner_block, required: true)
slot(:actions, required: false) do
attr(:align, :atom, values: [:left, :center, :right])
end
attr(:for, :any, default: %{})
attr(:as, :atom, default: :form)
attr(:event, :string, default: "save")
attr(:target, :map, default: nil)
attr(:rest, :global,
include: ~w(autocomplete name rel action enctype method novalidate target),
doc: "the arbitrary HTML attributes to apply to the form tag"
)
@doc """
Renders a simple form with a default layout.
## Examples
<.simple_form>
"""
def simple_form(%{actions: []} = assigns) do
assigns
|> assign(:actions_align, :right)
|> do_simple_form()
end
def simple_form(%{actions: [actions]} = assigns) do
assigns
|> assign(:actions_align, Map.get(actions, :align, :right))
|> do_simple_form()
end
defp do_simple_form(assigns) do
~H"""