@@ -17,8 +17,8 @@ defmodule PetalComponents.Field do
17
17
18
18
It's possible to support custom field types by using the `type={%{type="SomeCustomType", other_assigns...}}.`
19
19
In order to define a custom field, a module that implements `PetalComponents.Field.Extension` behavior
20
- needs to be implemented. Its `render/1` function needs to accept an assigns that will
21
- be used for passing a map obtained by merging the assigns passed to this field with the
20
+ needs to be implemented. Its `render/1` function needs to accept an assigns argument
21
+ that will be used for passing a map obtained by merging the assigns given to this field with the
22
22
assigns in the `other_assigns...` passed in the `type` field.
23
23
See the example below:
24
24
@@ -32,7 +32,7 @@ defmodule PetalComponents.Field do
32
32
@impl true
33
33
def render(assigns) do
34
34
~H'''
35
- <input id={@id} field ={@name} value={@value} class={@class} datalist={@datalist} {@rest}/>
35
+ <input id={@id} name ={@name} value={@value} class={@class} datalist={@datalist} {@rest}/>
36
36
<datalist id={@datalist}>
37
37
<option :for={{value, option} <- @options} value={value}><%= option %></option>
38
38
</datalist>
@@ -643,7 +643,7 @@ defmodule PetalComponents.Field do
643
643
644
644
module = field_type_extension ( type )
645
645
assigns = assign ( assigns , :class , [ assigns . class , get_class_for_type ( module , type ) ] )
646
- { assigns , body } = render_body ( module , assigns )
646
+ body = render_body ( module , assigns )
647
647
assigns = assign ( assigns , :body , body )
648
648
~H"""
649
649
< . field_wrapper id = { "#{ @ id } -wr" } errors = { @ errors } name = { @ name } class = { @ wrapper_class } no_margin = { @ no_margin } >
@@ -824,32 +824,23 @@ defmodule PetalComponents.Field do
824
824
end
825
825
end
826
826
827
- @ spec render_body ( nil | atom ( ) , map ( ) ) :: { map ( ) , Phoenix.LiveView.Rendered . t ( ) }
827
+ @ spec render_body ( nil | atom ( ) , map ( ) ) :: Phoenix.LiveView.Rendered . t ( )
828
828
829
829
defp render_body ( nil , assigns ) do
830
- {
831
- assigns ,
832
- ~H"""
833
- < input
834
- type = { @ type }
835
- name = { @ name }
836
- id = { @ id }
837
- value = { Phoenix.HTML.Form . normalize_value ( @ type , @ value ) }
838
- class = { @ class }
839
- required = { @ required }
840
- { @ rest }
841
- />
842
- """
843
- }
830
+ ~H"""
831
+ < input
832
+ type = { @ type }
833
+ name = { @ name }
834
+ id = { @ id }
835
+ value = { Phoenix.HTML.Form . normalize_value ( @ type , @ value ) }
836
+ class = { @ class }
837
+ required = { @ required }
838
+ { @ rest }
839
+ />
840
+ """
844
841
end
845
842
846
- defp render_body ( mod , assigns ) do
847
- rest = assigns [ :rest ] || % { }
848
- { extensions , rest } = Map . pop ( rest , :extension , % { } )
849
- new_assigns = assign ( assigns , :rest , rest )
850
- assigns = Map . merge ( new_assigns , extensions )
851
- { new_assigns , mod . render ( assigns ) }
852
- end
843
+ defp render_body ( mod , assigns ) , do: mod . render ( assigns )
853
844
854
845
# Note: we use persistent term to avoid the overhead of calling Application.get_env/2.
855
846
# Here is the corresponding performance benchmark:
0 commit comments