diff --git a/lib/decentralised_book_index_web/components/core_components.ex b/lib/decentralised_book_index_web/components/core_components.ex index 0e5a568..7df10aa 100644 --- a/lib/decentralised_book_index_web/components/core_components.ex +++ b/lib/decentralised_book_index_web/components/core_components.ex @@ -176,6 +176,69 @@ defmodule DecentralisedBookIndexWeb.CoreComponents do """ end + attr :kind, :string, + values: ~w(base primary error), + default: "base" + + attr :inverse, :boolean, default: false + attr :size, :string, values: ~w(sm xs md), default: "md" + attr :class, :string, default: "" + attr :rest, :global, include: ~w(navigate disabled patch) + + slot :inner_block + + def button_link(assigns) do + assigns = + assign(assigns, :theme, button_styles(assigns.kind, assigns.inverse, assigns.size)) + + ~H""" + <.link + class={[ + @theme, + @rest[:disabled] && "opacity-60 grayscale pointer-events-none", + @class + ]} + {@rest} + > + {render_slot(@inner_block)} + + """ + end + + def button_styles(kind, inverse, size) do + theme = + case {kind, inverse} do + {"base", false} -> + "bg-gray-100" + + {"base", true} -> + "border border-gray-500 text-gray-600" + + {"primary", false} -> + "bg-primary-600 hover:bg-primary-700 text-white" + + {"primary", true} -> + "border border-primary-700 text-primary-700 hover:bg-primary-50 font-semibold" + + {"error", false} -> + "bg-error-700 hover:bg-error-800 text-white" + + {"error", true} -> + "text-error-600 underline" + + _ -> + "" + end + + [ + "phx-submit-loading:opacity-75 rounded-lg font-medium leading-none inline-block", + size == "md" && "py-3 px-5 text-sm", + size == "sm" && "py-2 px-3 text-sm", + size == "xs" && "py-2 px-2 text-xs", + theme + ] + end + @doc """ Renders a simple form. diff --git a/lib/decentralised_book_index_web/live/book_live/form_component.ex b/lib/decentralised_book_index_web/live/book_live/form_component.ex index 9d625ce..bc92019 100644 --- a/lib/decentralised_book_index_web/live/book_live/form_component.ex +++ b/lib/decentralised_book_index_web/live/book_live/form_component.ex @@ -18,19 +18,14 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do phx-submit="save" > <%= if @form.source.type == :create do %> - <.input field={@form[:bids]} type="select" multiple label="Bids" options={[]} /> + <.input field={@form[:title]} type="text" label="Title" /> <.input - field={@form[:author_roles]} - type="select" - multiple - label="Author roles" - options={[]} - /> - <.input field={@form[:title]} type="text" label="Title" /><.input field={@form[:description]} type="text" label="Description" - /><.input field={@form[:format]} type="text" label="Format" /><.input + /> + <.bids_inputs form={@form} myself={@myself} /> + <.input field={@form[:format]} type="text" label="Format" /><.input field={@form[:language]} type="text" label="Language" @@ -38,10 +33,6 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do field={@form[:published]} type="date" label="Published" - /><.input field={@form[:publisher_id]} type="text" label="Publisher" /><.input - field={@form[:book_editions_registry_id]} - type="text" - label="Book editions registry" /> <% end %> <%= if @form.source.type == :update do %> @@ -50,11 +41,78 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do <:actions> <.button phx-disable-with="Saving...">Save Book + +
all:<%= inspect(@form, pretty: true) %>+
Bids:<%= inspect(@form[:bids], pretty: true) %>""" end + def bids_inputs(assigns) do + ~H""" +
Type | +Id | +|
---|---|---|
+ + <.input field={bid_form[:type]} /> + | ++ + <.input field={bid_form[:bid]} /> + | +