LedgerUI.Components.ColorPicker (LedgerUI v0.2.0)

Copy Markdown View Source

A color picker that outputs hex text: a saturation/brightness area to drag, a hue slider, an optional opacity slider, a hex field and a row of preset swatches.

<.color_picker field={@form[:color]} label="Stage color" />
<.color_picker name="tag" value="#4C3FE0" presets={~w(#EB3B2F #F5A214 #18996E)} />
<.color_picker field={@form[:overlay]} alpha locale="pt_BR" />
<.color_picker name="brand" variant="swatches" hex_field presets={~w(#0D8F91 #2F5FD0 #8A5CD6)} />

The form gets #6366F1 (upper case, #RRGGBB; with alpha a translucent color is #RRGGBBAA) through a hidden input named like the field; every change fires a bubbling input event from it, so phx-change runs. The behaviour lives in the LedgerUI.ColorPicker hook (priv/static/ledger_ui/hooks/color_picker.js), so the picker needs a stable id.

popover draws the picker on a lu-pop pad surface (300px), as in the reference of the design; otherwise the picker has no surface of its own.

Summary

Functions

Renders the color picker.

Functions

color_picker(assigns)

Renders the color picker.

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:string)
  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • default (:string) - Defaults to "#4C3FE0".
  • label (:string) - Defaults to nil.
  • label_class (:any) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • alpha (:boolean) - Defaults to false.
  • presets (:list) - Defaults to ["#4C3FE0", "#2763E6", "#1693CC", "#18996E", "#31A35B", "#F5A214", "#F06B0C", "#EB3B2F", "#DB428F", "#606A78"].
  • swatches (:list) - The same as presets; it wins when given. Defaults to nil.
  • locale (:string) - Defaults to "en". Must be one of "en", or "pt_BR".
  • labels (:map) - Defaults to %{}.
  • variant (:string) - Defaults to "full". Must be one of "full", or "swatches".
  • hex_field (:boolean) - Defaults to false.
  • hex_label (:any) - Defaults to "Hex".
  • swatch_size (:string) - Defaults to nil.Must be one of nil, "", "sm", "md", or "lg".
  • popover (:boolean) - Defaults to false.
  • 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.