Phoenix LiveView MultiSelect Component

This project implements an Elixir Phoenix LiveView component that has a capability of selecting multiple checkboxed items from a list.

Example

The component supports the following options:

Here's a sample video illustrating what this component looks like in action.

This component is inspired by this article but is a complete rewrite with added features for usability.

Author

Serge Aleynikov

Installation

Include the project in the mix.exs as a dependency:

defp deps do
[
{:phoenix_multi_select, "~> 0.0"},
...
]

Run mix deps.get, and mix multi_select.install. This will modify the following files:

If the AlpineJS support is requested (:use_alpinejs options), the root.html.heex and app.js will be checked for installation of AlpineJS.

Usage

In your project locate this file {{your_project}}_web.ex, and add:

defp html_helpers do
quote do
...
use Phoenix.LiveView.Components.MultiSelect ## <--- add this line
...
end
end

Now in the *.html.heex templates you can use the multi_select LiveView component like this:

<.multi_select
id="some-id"
options={
{id: 1, label: "Option1"},
{id: 2, label: "Option2"},
...
}
/>

For list of the available component's options see Phoenix.LiveView.Components.MultiSelect.multi_select/1

Customization (config.exs file)

config :phoenix_multi_select,
class_prefix: "some-class-name"
config :phoenix_multi_select,
class_module: MyModule

Here's is an example of implementation of such a module:

my_module.ex:
=============
defmodule MyModule do
def apply_css(_tag, def_css_classes), do:
String.replace(def_css_classes, "primary", "pink")
end
config :phoenix_multi_select,
use_alpinejs: true

Demo

The demo project is located in the examples/ directory, and can be compiled and run with:

cd examples
make
make run

Now you can visit localhost:4000 from your browser.