Skip to content

Commit daf535e

Browse files
committed
Add field type extensions
This change enables to extend fields with custom types in order to be able to inject custom body in a field wrapper.
1 parent 86c39b9 commit daf535e

File tree

5 files changed

+278
-34
lines changed

5 files changed

+278
-34
lines changed

config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import Config
22

33
config :phoenix, :json_library, Jason
4+
5+
import_config "#{config_env()}.exs"

config/test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Config
2+
3+
config :wallaby, :chromedriver,
4+
binary: System.get_env("CHROMEDRIVER", "/usr/bin/chromedriver")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule PetalComponents.Field.Extension do
2+
@moduledoc """
3+
Behavior for field extensions.
4+
"""
5+
6+
@doc """
7+
This callback function takes assigns and returns a rendered field's body.
8+
9+
## Example
10+
@behaviour PetalComponents.Field.Extension
11+
12+
def render(assigns) do
13+
~H'''
14+
<div>Custom Field</div>
15+
'''
16+
end
17+
"""
18+
@callback render(assigns :: map) :: map
19+
20+
@doc """
21+
This callback function is used to get classes for the custom field.
22+
23+
## Example
24+
@behaviour PetalComponents.Field.Extension
25+
26+
def get_class_for_type("pretty_field"), do: "pc-text-input"
27+
"""
28+
@callback get_class_for_type(String.t) :: String.t
29+
30+
@optional_callbacks get_class_for_type: 1
31+
end

0 commit comments

Comments
 (0)