DevactionUI.DatePicker (devaction_ui v0.1.0)

Copy Markdown View Source

A month calendar that picks one day or a range, and the small chip that says how near a deadline is.

date_picker/1 is drawn by a hook, so the months turn without the server. The server gives it only what it alone knows: the day that is today in the workspace's time zone (today), the shortcuts (Today, Friday, +7 days, End of the milestone, each with its ISO date) and the texts. Month and weekday names come from the browser's Intl in the locale given. The choice goes into hidden inputs (name for one day, name_from and name_to for a range), as ISO dates, and the hook fires input so phx-change hears it.

Keys: ← → move a day, ↑ ↓ a week, PageUp and PageDown a month, Home and End the week, Enter or Space picks. Days before min are dimmed and cannot be picked.

due_chip/1 compares a date with today and draws it late (red), due today (amber) or later (neutral).

Summary

Functions

date_picker(assigns)

Attributes

  • id (:string) (required)
  • name (:string) (required)
  • mode (:atom) - Defaults to :single. Must be one of :single, or :range.
  • value (:any) - an ISO date, or {from, to} for a range, or nil. Defaults to nil.
  • today (:string) (required) - today's ISO date in the workspace's time zone.
  • min (:string) - the first ISO date that can be picked. Defaults to nil.
  • locale (:string) - Defaults to "en".
  • week_start (:integer) - 0 for Sunday, 1 for Monday. Defaults to 0.
  • previous_label (:string) (required)
  • next_label (:string) (required)
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • shortcut - Accepts attributes:
    • date (:string) (required) - an ISO date.

due_chip(assigns)

Attributes

  • date (:any) (required) - a Date.
  • today (:any) (required) - a Date: today in the workspace's time zone.
  • text (:string) (required) - what the chip says, already in the person's language.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

state(date, today)

@spec state(Date.t(), Date.t()) :: :late | :today | :later

:late, :today or :later.