Skip to content

Add field type extensions #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Config

config :phoenix, :json_library, Jason

if File.exists?("config/#{config_env()}.exs"), do: import_config "#{config_env()}.exs"
4 changes: 4 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Config

config :wallaby, :chromedriver,
binary: System.get_env("CHROMEDRIVER", "/usr/bin/chromedriver")
31 changes: 31 additions & 0 deletions lib/petal_components/behaviors/field_extension.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule PetalComponents.Field.Extension do
@moduledoc """
Behavior for field extensions.
"""

@doc """
This callback function takes assigns and returns a rendered field's body.

## Example
@behaviour PetalComponents.Field.Extension

def render(assigns) do
~H'''
<div>Custom Field</div>
'''
end
"""
@callback render(assigns :: map()) :: Phoenix.LiveView.Rendered.t()

@doc """
This callback function is used to get classes for the custom field.

## Example
@behaviour PetalComponents.Field.Extension

def get_class_for_type("pretty_field"), do: "pc-text-input"
"""
@callback get_class_for_type(String.t()) :: String.t()

@optional_callbacks get_class_for_type: 1
end
Loading