LineOne's date pickers (flatpickr's calendar in LineOne's skin): one date, several dates or a range, with limits, disabled days, a custom text format, a time row, and a calendar that 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} />
<.datetime_picker field={@form[:starts_at]} min_time="16:00" max_time="22:00" />
<.date_picker name="due" display_format="M j, Y" show_icon={false} placeholder="Due date" />The input shows the date in display_format (flatpickr tokens: Y-m-d, F j, Y, H:i...);
the form gets ISO text through hidden inputs named like the field: 2026-10-23 (one date),
2026-10-23 16:30 (date and time), and name[] per date for multiple and range (with an
empty name[] first so an empty choice still reaches the server). A pick fires a bubbling
input event, so phx-change runs; the server re-rendering the same value changes nothing,
a different value replaces the one in the browser.
The calendar is an overlay: LineaUI.open/close/toggle("id") work on it, and
date_picker_clear/1 empties it.
A range in two fields
A range can submit its two ends as two fields instead of name[]: give start_field and
end_field (or start_name and end_name) and the form gets start=2026-10-01 and
end=2026-10-31 (empty text for an end not picked yet). presets adds quick choices under
the calendar, computed on the server from today:
<.date_picker
start_field={@form[:from]}
end_field={@form[:to]}
locale="pt_BR"
week_start={1}
placeholder="Período"
presets={[
{"Hoje", "today"},
{"Últimos 7 dias", "last_7_days"},
{"Este mês", "this_month"},
{"Mês passado", "last_month"}
]}
/>locale="pt_BR" names the months and weekdays in Portuguese, shows dd/mm/aaaa and joins
a range with "até"; months, weekdays, display_format and range_separator still
override it one by one.
Summary
Functions
Renders a date input with its calendar.
A %JS{} that empties the picker with id, for a clear button.
The {first, last} days of a named period around today, the way date_picker/1's
presets compute them. week_start is the first day of a week, 0 = Sunday. The this_*
and last_* periods are whole weeks, months and years; last_7_days and last_30_days
end today.
Renders a date and time input: the calendar with flatpickr's hour and minute row.
Functions
Renders a date input with its calendar.
<.date_picker id="due" name="due" label="Due" min={Date.utc_today()} />
<.date_picker id="when" name="when" placeholder="Choose date">
<:trailing>
<.button phx-click={LineaUI.toggle("when")}>…</.button>
<.button phx-click={date_picker_clear("when")}>×</.button>
</:trailing>
</.date_picker>Events: on_change is pushed with %{"id" => id, "value" => value} after each pick, where
value is the ISO text (or a list of them for multiple and range), to target or to the
LiveView/LiveComponent the picker is in.
A preset is {label, key} with a key of date_range_preset/3 ("today", "yesterday",
"last_7_days", "last_30_days", "this_week", "last_week", "this_month",
"last_month", "this_year", "last_year"), {label, {from, to}} or
%{label: label, from: from, to: to} with Dates or ISO text. Picking one sets the range
(or, in single mode, its first day), fires phx-change and on_change, and closes the
calendar; the preset matching the current choice is highlighted.
Attributes
id(:string) - Defaults to the field id, or a generated one.name(:string) - Defaults to the field name.value(:any) - ADate, ISO text, a list of them,{from, to}or aDate.Range.field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].placeholder(:string) - Defaults tonil.mode(:string) - Set torangebystart_field/end_fieldandstart_name/end_name. Defaults to"single". Must be one of"single","multiple", or"range".start_field(Phoenix.HTML.FormField) - The field the first day of a range goes to; withend_field. Defaults tonil.end_field(Phoenix.HTML.FormField) - The field the last day of a range goes to; withstart_field. Defaults tonil.start_name(:string) - The input name of the first day of a range (without fields); withend_name. Defaults tonil.end_name(:string) - The input name of the last day of a range. Defaults tonil.presets(:list) - Quick choices under the calendar:{label, key},{label, {from, to}}or%{label:, from:, to:}. Defaults to[].locale(:string) - Month and weekday names, the defaultdisplay_formatand the range separator. Defaults to"en". Must be one of"en", or"pt_BR".range_separator(:string) - The text between the two days of a range; " to " (en) or " até " (pt_BR). Defaults tonil.min(:any) - The first day that can be picked (Dateor ISO text). Defaults tonil.max(:any) - The last day that can be picked. Defaults tonil.disabled_dates(:list) - Days that cannot be picked. Defaults to[].disabled_weekdays(:list) - Weekdays that cannot be picked, 0 = Sunday. Defaults to[].week_start(:integer) - The first column of the calendar, 0 = Sunday. Defaults to0.display_format(:string) - The text of the input in flatpickr tokens;Y-m-dby default.M j, YreadsOct 23, 2026,D, M jreadsFri, Oct 23,F j, YreadsOctober 23, 2026. Only the shown text changes: the form still gets ISO. Defaults tonil.months(:list) - The twelve month names, for another language. Defaults tonil.weekdays(:list) - The seven weekday names from Sunday; the calendar shows their first three letters. Defaults tonil.today(:any) - The day marked as today; the server's UTC day by default. Defaults tonil.inline(:boolean) - The calendar always shows, under the input. Defaults tofalse.show_icon(:boolean) - The calendar icon inside the input;falseleaves a bare input (and drops the left padding). Defaults totrue.disabled(:boolean) - Defaults tofalse.on_change(:string) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Classes of the input. Defaults tonil.- Global attributes are accepted.
Slots
icon- Replaces the calendar icon.trailing- Buttons joined to the right of the input (LineOne's External Elements); the icon is then left out.
@spec date_picker_clear(Phoenix.LiveView.JS.t(), String.t()) :: Phoenix.LiveView.JS.t()
A %JS{} that empties the picker with id, for a clear button.
<.button phx-click={date_picker_clear("when")}>Clear</.button>
The {first, last} days of a named period around today, the way date_picker/1's
presets compute them. week_start is the first day of a week, 0 = Sunday. The this_*
and last_* periods are whole weeks, months and years; last_7_days and last_30_days
end today.
iex> LineaUI.Components.DatePicker.date_range_preset("last_month", ~D[2026-10-24])
{~D[2026-09-01], ~D[2026-09-30]}
iex> LineaUI.Components.DatePicker.date_range_preset("this_week", ~D[2026-10-24], 1)
{~D[2026-10-19], ~D[2026-10-25]}
Renders a date and time input: the calendar with flatpickr's hour and minute row.
<.datetime_picker name="meeting" placeholder="Choose datetime..." min_time="16:00" max_time="22:00" />Takes every attr of date_picker/1 (in single mode) and the time attrs below. The form
gets 2026-10-23 16:30.
Attributes
id(:string) - Defaults to the field id, or a generated one.name(:string) - Defaults to the field name.value(:any) - ANaiveDateTime,DateTimeor"2026-10-23 16:30".field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].placeholder(:string) - Defaults tonil.min(:any) - Defaults tonil.max(:any) - Defaults tonil.disabled_dates(:list) - Defaults to[].disabled_weekdays(:list) - Defaults to[].week_start(:integer) - Defaults to0.display_format(:string) -Y-m-d H:iby default. Defaults tonil.locale(:string) - Month and weekday names and the defaultdisplay_format(d/m/Y H:iin pt_BR). Defaults to"en". Must be one of"en", or"pt_BR".months(:list) - Defaults tonil.weekdays(:list) - Defaults tonil.today(:any) - Defaults tonil.inline(:boolean) - Defaults tofalse.show_icon(:boolean) - Defaults totrue.time_24hr(:boolean) - Hours 0-23 instead of 1-12 with AM/PM. Defaults tofalse.min_time(:string) - The earliest time,"HH:MM". Defaults tonil.max_time(:string) - The latest time,"HH:MM". Defaults tonil.minute_step(:integer) - Defaults to5.hour_step(:integer) - Defaults to1.default_hour(:integer) - The hour a first pick starts at. Defaults to12.disabled(:boolean) - Defaults tofalse.on_change(:string) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
icontrailing