LedgerUI.Components.DatePicker (LedgerUI v0.2.0)

Copy Markdown View Source

Date picker: one date, several dates or a range, with limits, disabled days, a custom text format and presets. The calendar pops under the input or stays inline.

<.date_picker field={@form[:due_on]} placeholder="Choose date..." />
<.date_picker name="trip" mode="range" value={{~D[2026-10-10], ~D[2026-10-20]}} />
<.date_picker name="days" mode="multiple" disabled_weekdays={[0, 6]} week_start={1} />
<.date_picker start_field={@form[:from]} end_field={@form[:to]} locale="pt_BR"
  presets={[{"Este mês", "this_month"}, {"Mês passado", "last_month"}]} />

The input shows the date in display_format (flatpickr tokens Y y m n d j F M l D); the form gets ISO text through hidden inputs named like the field (name for one date, name[] for multiple and range, with an empty name[] first). A pick fires a bubbling input event, so phx-change runs.

The behaviour lives in the LedgerUI.DatePicker hook (priv/static/ledger_ui/hooks/date_picker.js). The popup is an overlay: LedgerUI.open/close/toggle("id-pop") is not needed, the hook opens it; date_picker_clear/1 empties the picker.

date_picker_panel/1 renders just the calendar surface (lu-pop > lu-cal), the markup the popup is made of.

Summary

Functions

Renders a date input with its calendar.

The lu-cal month: title, arrows, weekday letters and day buttons.

A Phoenix.LiveView.JS command that empties the date picker id (the one given to id).

The calendar surface of the picker: month title with arrows, weekday letters and the days, optionally with a column of presets on the left.

Functions

date_picker(assigns)

Renders a date input with its calendar.

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:any)
  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • placeholder (:string) - Defaults to nil.
  • mode (:string) - Defaults to "single". Must be one of "single", "multiple", or "range".
  • range (:boolean) - The same as mode="range". Defaults to false.
  • start_field (Phoenix.HTML.FormField) - Defaults to nil.
  • end_field (Phoenix.HTML.FormField) - Defaults to nil.
  • start_name (:string) - Defaults to nil.
  • end_name (:string) - Defaults to nil.
  • presets (:list) - Defaults to [].
  • locale (:string) - Defaults to "en". Must be one of "en", or "pt_BR".
  • range_separator (:string) - Defaults to nil.
  • labels (:map) - Defaults to %{}.
  • min (:any) - Defaults to nil.
  • max (:any) - Defaults to nil.
  • disabled_dates (:list) - Defaults to [].
  • disabled_weekdays (:list) - Defaults to [].
  • week_start (:integer) - Defaults to 0.
  • display_format (:string) - Defaults to nil.
  • months (:list) - Defaults to nil.
  • weekdays (:list) - Defaults to nil.
  • today (:any) - Defaults to nil.
  • inline (:boolean) - Defaults to false.
  • show_icon (:boolean) - Defaults to true.
  • skin (:string) - Defaults to nil.Must be one of nil, "", or "linea".
  • size (:string) - Defaults to "md". Must be one of "sm", "md", or "lg".
  • disabled (:boolean) - Defaults to false.
  • on_change (:string) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • icon - Replaces the calendar icon.
  • trailing - Buttons joined to the right of the input.

date_picker_calendar(assigns)

The lu-cal month: title, arrows, weekday letters and day buttons.

Attributes

  • month (:any) - Defaults to nil.
  • selected (:any) - Defaults to nil.
  • range (:any) - Defaults to nil.
  • today (:any) - Defaults to nil.
  • min (:any) - Defaults to nil.
  • max (:any) - Defaults to nil.
  • disabled_dates (:list) - Defaults to [].
  • disabled_weekdays (:list) - Defaults to [].
  • week_start (:integer) - Defaults to 0.
  • locale (:string) - Defaults to "en".
  • months (:list) - Defaults to nil.
  • weekdays (:list) - Defaults to nil.
  • labels (:map) - Defaults to %{}.
  • Global attributes are accepted.

date_picker_clear(id)

A Phoenix.LiveView.JS command that empties the date picker id (the one given to id).

<button phx-click={date_picker_clear("due")}>×</button>

date_picker_clear(js, id)

date_picker_panel(assigns)

The calendar surface of the picker: month title with arrows, weekday letters and the days, optionally with a column of presets on the left.

Attributes

  • month (:any) - A Date of the month to show (today's month by default). Defaults to nil.
  • selected (:any) - A date or a list of dates drawn as selected. Defaults to nil.
  • range (:any) - {from, to}: painted as a continuous band. Defaults to nil.
  • today (:any) - Defaults to nil.
  • min (:any) - Defaults to nil.
  • max (:any) - Defaults to nil.
  • disabled_dates (:list) - Defaults to [].
  • disabled_weekdays (:list) - Defaults to [].
  • week_start (:integer) - Defaults to 0.
  • locale (:string) - Defaults to "en".
  • months (:list) - Defaults to nil.
  • weekdays (:list) - Defaults to nil.
  • labels (:map) - Defaults to %{}.
  • presets (:list) - Defaults to [].
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.