From 179da78355620d28fc846b1b361e43405804cbec Mon Sep 17 00:00:00 2001 From: Tiago Moraes Date: Tue, 20 Feb 2024 20:36:17 -0300 Subject: [PATCH 1/2] Remove dependency on Surface Forms --- .../catalogue/components/playground_tools.ex | 13 +- .../catalogue/components/prop_input.ex | 111 ++++++++++++------ .../catalogue/components/state_dialog.ex | 13 +- mix.lock | 4 +- priv/catalogue/editable_props/playground.ex | 8 +- .../sample_components/editable_props.ex | 8 +- 6 files changed, 95 insertions(+), 62 deletions(-) diff --git a/lib/surface/catalogue/components/playground_tools.ex b/lib/surface/catalogue/components/playground_tools.ex index ca770d2..b930f33 100644 --- a/lib/surface/catalogue/components/playground_tools.ex +++ b/lib/surface/catalogue/components/playground_tools.ex @@ -5,7 +5,6 @@ defmodule Surface.Catalogue.Components.PlaygroundTools do alias Surface.Catalogue.Components.Tabs.TabItem alias Surface.Catalogue.Components.PropInput alias Surface.Catalogue.Components.StateDialog - alias Surface.Components.Form alias Surface.Catalogue.Playground @event_log_tab 2 @@ -55,20 +54,20 @@ defmodule Surface.Catalogue.Components.PlaygroundTools do
-
+ <.form for={%{}} as={:props_values} phx-change="change" autocomplete="off"> {#for prop <- @props} - + {/for} - +
-
+ <.form for={%{}} as={:props_values} phx-change="change" autocomplete="off"> {#for slot <- @slots} - + {/for} - +
diff --git a/lib/surface/catalogue/components/prop_input.ex b/lib/surface/catalogue/components/prop_input.ex index 0d9cd48..f76a2db 100644 --- a/lib/surface/catalogue/components/prop_input.ex +++ b/lib/surface/catalogue/components/prop_input.ex @@ -3,14 +3,10 @@ defmodule Surface.Catalogue.Components.PropInput do use Surface.Component - alias Surface.Components.Form.{TextInput, Checkbox, Select, NumberInput} - prop prop, :map prop value, :any - prop form, :form - prop nil_placeholder, :string, default: "nil" data placeholder, :any @@ -26,7 +22,7 @@ defmodule Surface.Catalogue.Components.PropInput do
- <.input prop={@prop} value={@value} form={@form} placeholder={@placeholder} /> + <.input prop={@prop} value={@value} placeholder={@placeholder} />
@@ -42,20 +38,36 @@ defmodule Surface.Catalogue.Components.PropInput do defp input(assigns) do case {assigns.prop.type, get_choices(assigns.prop)} do {:boolean, _} -> + assigns = + assign_new(assigns, :checked, fn -> + Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value]) + end) + ~F""" - + + {error_message(@prop)} """ {:string, []} -> ~F""" - {error_message(@prop)} @@ -66,7 +78,9 @@ defmodule Surface.Catalogue.Components.PropInput do ~F"""
- + {Phoenix.HTML.Form.options_for_select(@choices, @value)} +
{error_message(@prop)} @@ -74,12 +88,15 @@ defmodule Surface.Catalogue.Components.PropInput do {:atom, []} -> ~F""" - {error_message(@prop)} @@ -91,7 +108,9 @@ defmodule Surface.Catalogue.Components.PropInput do ~F"""
- + {Phoenix.HTML.Form.options_for_select(@choices, value_to_string(@value))} +
{error_message(@prop)} @@ -99,12 +118,15 @@ defmodule Surface.Catalogue.Components.PropInput do {:css_class, _} -> ~F""" - {error_message(@prop)} @@ -112,12 +134,15 @@ defmodule Surface.Catalogue.Components.PropInput do {:number, []} -> ~F""" - {error_message(@prop)} @@ -125,12 +150,15 @@ defmodule Surface.Catalogue.Components.PropInput do {:integer, []} -> ~F""" - {error_message(@prop)} @@ -141,7 +169,9 @@ defmodule Surface.Catalogue.Components.PropInput do ~F"""
- + {Phoenix.HTML.Form.options_for_select(@choices, @value)} +
{error_message(@prop)} @@ -149,12 +179,15 @@ defmodule Surface.Catalogue.Components.PropInput do {type, []} when type in [:list, :keyword] -> ~F""" - {error_message(@prop)} diff --git a/lib/surface/catalogue/components/state_dialog.ex b/lib/surface/catalogue/components/state_dialog.ex index 4b68ff3..b9db0dd 100644 --- a/lib/surface/catalogue/components/state_dialog.ex +++ b/lib/surface/catalogue/components/state_dialog.ex @@ -11,9 +11,6 @@ defmodule Surface.Catalogue.Components.StateDialog do data show_private, :boolean, default: false data playground_pid, :pid, default: nil - alias Surface.Components.Form - alias Surface.Components.Form.Checkbox - def update(assigns, socket) do socket = if assigns[:component_id] do @@ -55,12 +52,13 @@ defmodule Surface.Catalogue.Components.StateDialog do