From 5232c39769169a4d8b85acb3aeca74b3a536ea3b Mon Sep 17 00:00:00 2001 From: ChivukulaVirinchi Date: Fri, 18 Oct 2024 09:47:07 +0530 Subject: [PATCH] input & migrating from phx-feedback --- assets/tailwind.config.js | 6 - lib/library_web/components/core_components.ex | 2 +- lib/library_web/components/dropdown.ex | 2 +- lib/library_web/components/error.ex | 14 + lib/library_web/components/input.ex | 1136 +++++++---------- lib/library_web/components/inputnew.ex | 94 ++ lib/library_web/components/modal.ex | 302 ++--- lib/library_web/components/test | 136 ++ .../live/post_live/form_component.ex | 21 +- .../live/post_live/index.html.heex | 431 +++---- mix.exs | 22 +- mix.lock | 76 +- 12 files changed, 1071 insertions(+), 1171 deletions(-) create mode 100644 lib/library_web/components/error.ex create mode 100644 lib/library_web/components/inputnew.ex create mode 100644 lib/library_web/components/test diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index 1d0b5a6..a7be954 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -32,12 +32,6 @@ module.exports = { // //
// - plugin(({ addVariant }) => - addVariant("phx-no-feedback", [ - ".phx-no-feedback&", - ".phx-no-feedback &", - ]), - ), plugin(({ addVariant }) => addVariant("phx-click-loading", [ ".phx-click-loading&", diff --git a/lib/library_web/components/core_components.ex b/lib/library_web/components/core_components.ex index 85a66b4..1d48780 100644 --- a/lib/library_web/components/core_components.ex +++ b/lib/library_web/components/core_components.ex @@ -368,13 +368,13 @@ defmodule LibraryWeb.CoreComponents do name={@name} id={@id} value={Phoenix.HTML.Form.normalize_value(@type, @value)} - {@rest} class={[ "mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6", "phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400", @errors == [] && "border-zinc-300 focus:border-zinc-400", @errors != [] && "border-rose-400 focus:border-rose-400" ]} + {@rest} /> <.error :for={msg <- @errors}><%= msg %>
diff --git a/lib/library_web/components/dropdown.ex b/lib/library_web/components/dropdown.ex index 368fc26..74c3d41 100644 --- a/lib/library_web/components/dropdown.ex +++ b/lib/library_web/components/dropdown.ex @@ -1,7 +1,7 @@ defmodule Dropdown do use Phoenix.Component slot :content, required: true - slot :trigger, requirded: true + slot :trigger, required: true attr :class, :string, default: "" attr :rest, :global, diff --git a/lib/library_web/components/error.ex b/lib/library_web/components/error.ex new file mode 100644 index 0000000..ed60144 --- /dev/null +++ b/lib/library_web/components/error.ex @@ -0,0 +1,14 @@ +defmodule Error do + use Phoenix.Component +slot :inner_block, required: true + + def error(assigns) do + ~H""" +

+ + <%= render_slot(@inner_block) %> +

+ """ + end + +end diff --git a/lib/library_web/components/input.ex b/lib/library_web/components/input.ex index 897e005..c80b37e 100644 --- a/lib/library_web/components/input.ex +++ b/lib/library_web/components/input.ex @@ -1,235 +1,25 @@ defmodule Input do use Phoenix.Component + attr :id, :any, default: nil + attr :name, :any + attr :label, :string, default: nil + attr :value, :any + attr :class, :string, default: "" attr :placeholder, :string, default: nil - # # # attr :type, :string, default: "text" attr :variant, :string, - default: "basic", + default: "default", values: [ - "basic", + "default", "gray", "underline", "floating-basic", "floating-gray", "floating-underline" ] - - # # attr :label, :string, default: "" - # # attr :value, :string, default: "" - slot :icon, required: false - - # # def input(assigns) do - # # case assigns.variant do - # # "basic" -> - # # ~H""" - # # - # # - # # """ - - # # "gray" -> - # # ~H""" - # #
- # # - - # # - # #
- # # <%= if @icon do %> - # # <%= render_slot(@icon) %> - # # <% end %> - # #
- # #
- # # """ - - # # "underline" -> - # # ~H""" - # #
- # # - # #
- # # <%= if @icon do %> - # # <%= render_slot(@icon) %> - # # <% end %> - # #
- # #
- # # """ - - # # "floating-basic" -> - # # ~H""" - # #
- # # - # # - # #
- # # """ - - # # "floating-gray" -> - # # ~H""" - # #
- # # - # # - # #
- # # """ - - # # "floating-underline" -> - # # ~H""" - # #
- # # - # # - # #
- # # """ - # # end - # # end - - # This - # is - # v1 - # ! - # ! - # attr :id, :any, default: nil - # attr :name, :string, default: "" - # attr :label, :string, default: nil - # attr :value, :string, default: "" - - # attr :type, :string, - # default: "text", - # values: ~w(checkbox color date datetime-local email file hidden month number password - # range radio search select tel text textarea time url week) - - # attr :field, Phoenix.HTML.FormField, - # doc: "a form field struct retrieved from the form, for example: @form[:email]" - - # attr :errors, :list, default: [] - # # attr :checked, :boolean, doc: "the checked flag for checkbox inputs" - # # attr :prompt, :string, default: nil, doc: "the prompt for select inputs" - # # attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2" - # # attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs" - - # attr :rest, :global, - # include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength - # multiple pattern placeholder readonly required rows size step) - - # def input(assigns) do - # ~H""" - #
- # <.label for={@id}><%= @label %> - # - # <.error :for={msg <- @errors}><%= msg %> - #
- # """ - # end - - # def label(assigns) do - # ~H""" - # - # """ - # end - - # def error(assigns) do - # ~H""" - #

- # <%!-- <.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" /> --%> - # <%= render_slot(@inner_block) %> - #

- # """ - # end - # end - - attr :id, :any, default: nil - attr :name, :any - attr :label, :string, default: nil - attr :value, :any + attr :icon, :string, default: "hero-" attr :type, :string, default: "text", @@ -253,34 +43,18 @@ defmodule Input do # HAVE TO INCLUDE @REST, @FORM AND @DISABLED @error_classes "border-red-500 focus:border-red-500 focus:ring-red-500" - @no_error_classes "border-teal-500 focus:border-green-500 focus:ring-green-500" + @no_error_classes "border-teal-500 focus:border-teal-500 focus:ring-teal-500" attr :error_classes, :string, default: @error_classes attr :no_error_classes, :string, default: @no_error_classes - # def input(assigns) do - # ~H""" - #
- # <.label for={@id}><%= @label %> - # - # <.error :for={msg <- @errors}><%= msg %> - #
- # """ - # end + attr :helper, :string, default: "" + attr :msg, :string, default: "Looks good!" + attr :hint, :string, default: "" def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do + errors = if Phoenix.Component.used_input?(field), do: field.errors, else: [] assigns |> assign(field: nil, id: assigns.id || field.id) - |> assign(:errors, Enum.map(field.errors, &translate_error(&1))) + |> assign(:errors, Enum.map(errors, &translate_error(&1))) |> assign_new(:name, fn -> if assigns.multiple, do: field.name <> "[]", else: field.name end) |> assign_new(:value, fn -> field.value end) |> input() @@ -468,447 +242,473 @@ defmodule Input do """ end - def input(assigns) do - case assigns.variant do - "basic" -> - ~H""" -
- -
- -
- - - -
- -
- - - -
-
- <.error :for={msg <- @errors}> - <%= msg %> - -
- """ - - "gray" -> - ~H""" -
- -
- + +
+ +
+ + -
- <%= if @icon do %> - <%= render_slot(@icon) %> - <% end %> -
-
- - - -
- -
- - - -
-
- <.error :for={msg <- @errors}> - <%= msg %> - +
- """ - - "underline" -> - ~H""" -
- -
- <%= if @icon do %> - <%= render_slot(@icon) %> - <% end %> -
-
- - - -
-
+ - - - -
- <.error :for={msg <- @errors}> - <%= msg %> - + +
- """ +
+ <.error :for={msg <- @errors}> + <%= msg %> + + <%= if @errors == [] do %> + +

Looks good!

+ <% end %> +
+ """ + end - "floating-basic" -> - ~H""" -
-
- - -
- - - -
- -
- - - -
-
- <.error :for={msg <- @errors}> - <%= msg %> - + def input(%{variant: "gray"} = assigns) do + ~H""" +
+
+ + <%= @hint %> +
+
+ +
+
- """ - - "floating-gray" -> - ~H""" -
-
- + + - -
- - - -
- -
- - - -
-
- <.error :for={msg <- @errors}> - <%= msg %> - +
- """ - "floating-underline" -> - ~H""" -
-
- - -
- - - -
- -
- - - -
-
- <.error :for={msg <- @errors}> - <%= msg %> - +
+ + +
- """ - end +
+

<%= @helper %>

+ <.error :for={msg <- @errors}> + <%= msg %> + + + <%= if @errors == [] do %> +

<%= @msg %>

+ <% end %> +
+ """ end + # def input(%{variant: "underline"} = assigns) do + # ~H""" + #
+ # + #
+ # + #
+ #
+ # + # + # + #
+ + #
+ # + # + # + #
+ # <.error :for={msg <- @errors}> + # <%= msg %> + # + #
+ # """ + # end + + # def input(assigns) do + # case assigns.variant do + # "floating-basic" -> + # ~H""" + #
+ #
+ # + # + #
+ # + # + # + #
+ + #
+ # + # + # + #
+ #
+ # <.error :for={msg <- @errors}> + # <%= msg %> + # + #
+ # """ + + # "floating-gray" -> + # ~H""" + #
+ #
+ # + # + #
+ # + # + # + #
+ + #
+ # + # + # + #
+ #
+ # <.error :for={msg <- @errors}> + # <%= msg %> + # + #
+ # """ + + # "floating-underline" -> + # ~H""" + #
+ #
+ # + # + #
+ # + # + # + #
+ + #
+ # + # + # + #
+ #
+ # <.error :for={msg <- @errors}> + # <%= msg %> + # + #
+ # """ + # end + # end + def label(assigns) do ~H"""