LedgerUI.Components.PillSelect (LedgerUI v0.2.0)

Copy Markdown View Source

A quick filter of chips where the chosen ones take the accent: one choice by default, several with multiple.

<.pill_select field={@form[:canal]} options={["Todos", "Balcão", "Online"]} />
<.pill_select field={@form[:categorias]} multiple options={~w(Tintas Básico Ferramentas)} />
<.pill_select name="canal" value="todos" options={[
  %{label: "Todos", value: "todos", count: 128},
  %{label: "Balcão", value: "balcao", count: 64}
]} />

Options are strings, {label, value} tuples or maps with :label, :value, :count and :disabled. Each pill is a lu-chip button (aria-pressed) and the choice is made in the browser by the LedgerUI.PillSelect hook; the values travel in hidden inputs (name, or name[] with multiple, preceded by an empty one so an emptied choice still reaches the server) that fire a bubbling input event, so the form's phx-change runs. Without a form, on_change is pushed on each click with %{"id" => id, "value" => value} to target.

Summary

Functions

pill_select(assigns)

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:any) - Defaults to nil.
  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • options (:list) (required)
  • multiple (:boolean) - Defaults to false.
  • label (:string) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • disabled (:boolean) - Defaults to false.
  • on_change (:string) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • wrapper_class (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["form"].