LedgerUI.Components.Pillbox (LedgerUI v0.2.0)

Copy Markdown View Source

Multiple (or single) choice drawn as pills inside the field, with a searchable list under it. It is the LedgerUI.Components.Select listbox (multiple, search="panel") and shares its hook, LedgerUI.Select (priv/static/ledger_ui/hooks/select.js).

<.pillbox field={@form[:categories]} label="Categories" options={@categories} />
<.pillbox name="tags" options={@tags} value={@chosen} create create_label="Create" />
<.pillbox name="branches" options={@branches} value={@chosen} overflow="wrap" />
<.pillbox name="product_id" value={@product_id} options={@products} multiple={false} />

The pills are submitted as name[] (an empty name[] first, so an emptied field still reaches the server); multiple={false} submits name. Each change fires a bubbling input event for phx-change. readonly keeps the values in the form but takes the x, the chevron and the list away; disabled also leaves them out of the form.

Options may carry :count (a faint mono number at the right of the row) and :color / :initials (a person: the pill gets a 22px avatar).

Summary

Functions

pillbox(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) - Defaults to [].
  • selected_options (:list) - Defaults to [].
  • label (:string) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • multiple (:boolean) - Defaults to true.
  • size (:string) - Defaults to "md". Must be one of "sm", "md", or "lg".
  • panel_min_width (:string) - Defaults to nil.
  • panel_class (:any) - Defaults to nil.
  • placeholder (:string) - Defaults to nil.
  • search_placeholder (:string) - Defaults to "Search…".
  • overflow (:string) - Defaults to "one". Must be one of "one", or "wrap".
  • create (:boolean) - Defaults to false.
  • create_label (:string) - Defaults to "Create".
  • create_hint (:string) - Defaults to "↵".
  • empty_label (:string) - Defaults to "No results found".
  • clear (:boolean) - Defaults to false.
  • clear_label (:string) - Defaults to "Clear".
  • remove_label (:string) - Defaults to "Remove".
  • hidden_label (:string) - Defaults to "%{count} hidden".
  • readonly (:boolean) - Defaults to false.
  • disabled (:boolean) - Defaults to false.
  • on_search (:string) - Defaults to nil.
  • debounce (:integer) - Defaults to 300.
  • target (:any) - Defaults to nil.
  • on_load_more (:string) - Defaults to nil.
  • has_more (:boolean) - Defaults to false.
  • loading_label (:string) - Defaults to "Loading…".
  • open (:boolean) - Defaults to false.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["form", "required"].