diff --git a/lib/decentralised_book_index_web/components/my_components.ex b/lib/decentralised_book_index_web/components/my_components.ex index dfc5b6c..698b05f 100644 --- a/lib/decentralised_book_index_web/components/my_components.ex +++ b/lib/decentralised_book_index_web/components/my_components.ex @@ -12,6 +12,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents do import MyComponents.Buttons, only: [ success_button: 1, primary_button: 1, + add_button: 1, save_button: 1, edit_button: 1, cancel_button: 1, diff --git a/lib/decentralised_book_index_web/components/my_components/buttons.ex b/lib/decentralised_book_index_web/components/my_components/buttons.ex index 60fa87b..4bd62f5 100644 --- a/lib/decentralised_book_index_web/components/my_components/buttons.ex +++ b/lib/decentralised_book_index_web/components/my_components/buttons.ex @@ -69,6 +69,31 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.Buttons do slot :inner_block, required: true + def add_button(assigns) do + ~H""" + <.link + class={[ + "phx-submit-loading:opacity-75 rounded-lg py-2 px-3 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mb-2 bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-blue-800", + "text-sm font-semibold leading-6 text-white active:text-white/80", + "flex items-center gap-1", + @class + ]} + {@rest} + > + + {render_slot(@inner_block)} + + """ + end + + attr :type, :string, default: nil + attr :class, :string, default: nil + attr :rest, :global, include: ~w(disabled form name value) + + slot :inner_block, required: true + def save_button(assigns) do ~H""" <.success_button 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 fd6d2b7..538098f 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 @@ -7,7 +7,6 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
<.header> {@title} - <:subtitle>Use this form to manage book records in your database. <.simple_form @@ -86,14 +85,15 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do - + + <.inputs_for :let={bid_form} field={@form[:bids]}> - @@ -101,7 +101,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do <.input field={bid_form[:bid]} /> - @@ -118,9 +120,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
TypeType Id
+ <.input field={bid_form[:type]} /> + <.button_link phx-click="remove-bid" phx-value-path={bid_form.name} @@ -110,7 +110,9 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do size="xs" inverse > - <.icon name="hero-trash" class="size-5" /> +
- <.button_link phx-click="add-bid" phx-target={@myself} kind="primary" size="sm" inverse> + <.add_button phx-click="add-bid" phx-target={@myself} class="w-44"> Add Book Id - + + """ end @@ -161,14 +164,15 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do - + + <.inputs_for :let={author_roles_form} field={@form[:author_roles]}> - @@ -176,7 +180,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do <.input field={author_roles_form[:role]} /> - @@ -193,9 +199,9 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
AuthorAuthor Role
+ <.input field={author_roles_form[:author_id]} /> + <.button_link phx-click="remove-author-role" phx-value-path={author_roles_form.name} @@ -185,7 +189,9 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do size="xs" inverse > - <.icon name="hero-trash" class="size-5" /> +
- <.button_link phx-click="add-author-role" phx-target={@myself} kind="primary" size="sm" inverse> + <.add_button phx-click="add-author-role" phx-target={@myself} class="w-40"> Add Author - + """ end