phx_component_helpers alternatives and similar packages
Based on the "Framework Components" category.
Alternatively, view phx_component_helpers alternatives based on common mentions on social networks and blogs.
-
commanded
Use Commanded to build Elixir CQRS/ES applications -
surface
A server-side rendering component library for Phoenix -
ex_admin
ExAdmin is an auto administration package for Elixir and the Phoenix Framework -
phoenix_html
Phoenix.HTML functions for working with HTML strings and templates -
phoenix_ecto
Phoenix and Ecto integration with support for concurrent acceptance testing -
absinthe_plug
Plug support for Absinthe, the GraphQL toolkit for Elixir -
corsica
Elixir library for dealing with CORS requests. ๐ -
react_phoenix
Make rendering React.js components in Phoenix easy -
phoenix_live_reload
Provides live-reload functionality for Phoenix -
params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters. -
phoenix_pubsub_redis
The Redis PubSub adapter for the Phoenix framework -
rummage_ecto
Search, Sort and Pagination for ecto queries -
dayron
A repository `similar` to Ecto.Repo that maps to an underlying http client, sending requests to an external rest api instead of a database -
rummage_phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix. -
phoenix_token_auth
Token authentication solution for Phoenix. Useful for APIs for e.g. single page apps. -
recaptcha
A simple reCaptcha 2 library for Elixir applications. -
plug_graphql
Plug (Phoenix) integration for GraphQL Elixir -
sentinel
DEPRECATED - Phoenix Authentication library that wraps Guardian for extra functionality -
plug_rails_cookie_session_store
Rails compatible Plug session store -
multiverse
Elixir package that allows to add compatibility layers via API gateways. -
filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL. -
scrivener_headers
Scrivener pagination with headers and web linking -
access pass
provides a full user authentication experience for an API. Includes login,logout,register,forgot password, forgot username, confirmation email and all that other good stuff. Includes plug for checking for authenticated users and macro for generating the required routes. -
better_params
Cleaner request parameters in Elixir web applications ๐ -
phoenix_pubsub_rabbitmq
RabbitMQ adapter for Phoenix's PubSub layer -
plug_checkup
PlugCheckup provides a Plug for adding simple health checks to your app -
plug_statsd
Send connection response time and count to statsd -
plug_rest
REST behaviour and Plug router for hypermedia web applications in Elixir -
Votex
Implements vote / like / follow functionality for Ecto models in Elixir. Inspired from Acts as Votable gem in Ruby on Rails -
plug_canonical_host
PlugCanonicalHost ensures that all requests are served by a single canonical host. -
trailing_format_plug
An elixir plug to support legacy APIs that use a rails-like trailing format: http://api.dev/resources.json -
phoenix_html_simplified_helpers
Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )
Static code analysis for 29 languages.
Do you think we are missing an alternative of phx_component_helpers or a related project?
README
PhxComponentHelpers
๐ Demonstration & Code samples
Presentation
PhxComponentHelpers
provides helper functions meant to be used within Phoenix LiveView to make your components more configurable and extensible from templates.
It provides the following features:
- set HTML, data or phx attributes from component assigns
- set a bunch of attributes at once with any custom prefix such as
@click
orx-bind:
(for alpinejs users) - validate mandatory attributes
- set and extend CSS classes from component assigns
- forward a subset of assigns to child components
Motivation
Writing a library of stateless components is a great way to improve consistency in both your UI and code and also to get a significant productivity boost.
The best components can be used as-is without any further configuration, but are versatile enough to be customized from templates or higher level components.
Writing such components is not difficult, but involves a lot of boilerplate code. PhxComponentHelpers
is here to alleviate the pain.
Example
A lot of code samples are available on this site, but basically PhxComponentHelpers
allows you to write components as such:
defmodule Forms.Button do
use Phoenix.Component
import PhxComponentHelpers
def button(assigns) do
assigns =
assigns
|> extend_class("bg-blue-700 hover:bg-blue-900 ...")
|> set_attributes([:type, :id, :label], required: [:id])
|> set_phx_attributes()
~H"""
<button {@heex_id} {@heex_type} {@heex_phx_attributes} {@heex_class}>
<%= @label %>
</button>
"""
end
end
From templates, it looks like this:
<.form id="form" phx_submit="form_submit" class="divide-none">
<.input_group>
<.label for="name" label="Name"/>
<.text_input name="name" value={@my.name}/>
</.input_group>
<.button_group class="pt-2">
<.button type="submit" phx_click="btn-click" label="Save"/>
</.button_group>
</.form>
How does it play with the PETAL stack?
PETAL stands for Phoenix - Elixir - TailwindCSS - Alpine.js - LiveView. In recent months it has become quite popular in the Elixir ecosystem and PhxComponentHelpers
is meant to fit in.
- TailwindCSS provides a new way to structure CSS, but keeping good HTML hygiene requires to rely on a component-oriented library.
- Alpine.js is the Javascript counterpart of Tailwind. It lets you define dynamic behaviour right from your templates using HTML attributes.
The point of developing good components is to provide strong defaults in the component so that they can be used as-is, but also to let these defaults be overridden right from the templates.
Here is the definition of a typical Form button, with Tailwind
& Alpine
:
defmodule Forms.Button do
use Phoenix.Component
import PhxComponentHelpers
@css_class "inline-flex items-center justify-center p-3 w-5 h-5 border \
border-transparent text-2xl leading-4 font-medium rounded-md \
text-white bg-primary hover:bg-primary-hover"
def button(assigns) do
assigns =
assigns
|> extend_class(@css_class)
|> set_phx_attributes()
|> set_prefixed_attributes(["@click", "x-bind:"],
into: :alpine_attributes,
required: ["@click"]
)
~H"""
<button type="button" {@heex_class} {@heex_alpine_attributes} {@heex_phx_attributes}>
<%= render_block(@inner_block) %>
</button>
"""
end
end
Then in your html.leex
template you can imagine the following code, providing @click
behaviour and overriding just the few tailwind css classes you need (only p-*
, w-*
and h-*
will be replaced). No phx
behaviour here, but it's ok, it won't break ;-)
<.button class="p-0 w-7 h-7" "@click"="$dispatch('closeslideover')">
<.icon icon={:plus_circle}/>
</.button>
Forms
This library also provides Phoenix.HTML.Form
related functions so you can easily write your own my_form_for
function with your css defaults.
def my_form_for(options) when is_list(options) do
options
|> extend_form_class("mt-4 space-y-2")
|> Phoenix.LiveView.Helpers.form()
end
Then you only need to use PhxComponentHelpers.set_form_attributes/1
within your own form components in order to fetch names & values from the form. Your template will then look like this:
<.my_form_for let={f} for={@changeset} phx_submit="form_submit" class="divide-none">
<.input_group>
<.label form={f} field={:name} label="Name"/>
<.text_input form={f} field={:name}/>
</.input_group>
<.button_group class="pt-2">
<.button type="submit" label="Save"/>
</.button_group>
</.my_form_for>
Compared to Surface
Surface is a library built on top of Phoenix LiveView. Surface is much more ambitious and complex than PhxComponentHelpers
(which obviously isn't a framework, just helpers ...).
Surface
really changes the way you code user interfaces and components (you almost won't be using HTML templates anymore) whereas PhxComponentHelpers
is just some syntactic sugar to help you use raw phoenix_live_view
.
Documentation
Available on https://hexdocs.pm
Installation
Add the following to your mix.exs
.
def deps do
[
{:phx_component_helpers, "~> 1.0.0"},
{:jason, "~> 1.0"} # only required if you want to use json encoding options
]
end