DevactionUI.Calendar (devaction_ui v0.1.0)

Copy Markdown View Source

A month or a week of days with their events, as an agenda of deliveries: each event is a coloured chip by kind (risk, warning, ok, info, neutral). It is a grid (role="grid", rows, column headers, cells) with one cell in the tab order and the arrows, Home, End and Page keys moving between days (DevactionUI.Calendar hook); pressing a day, or Enter on it, sends select_event with phx-value-date, and the previous and next buttons send prev_event and next_event.

The server owns the dates: month_weeks/3 and week_days/2 give the days to draw, so the grid is the same in the browser and in a test. The names of the months and of the days come from the caller (the library holds no language).

Summary

Functions

The weeks of a month, each a list of seven dates, from the week that holds the 1st to the one that holds the last day.

The first day of the month before and after the month of date.

2026-10 for a month and 2026-10-11 – 2026-10-17 for a week, the neutral form a caller can replace with its own words.

The seven dates of the week date is in.

Types

event()

@type event() :: %{
  id: String.t(),
  date: Date.t(),
  label: String.t(),
  kind: DevactionUI.Tone.t()
}

Functions

calendar(assigns)

Attributes

  • id (:string) (required)
  • label (:string) (required) - the name of the grid, e.g. Deliveries in October 2026.
  • title (:string) (required) - the month or the week, as written for the person.
  • date (:any) (required) - a date of the month (or of the week) shown.
  • view (:atom) - Defaults to :month. Must be one of :month, or :week.
  • week_start (:atom) - Defaults to :sunday. Must be one of :sunday, or :monday.
  • today (:any) (required) - a Date: today in the workspace's time zone.
  • selected (:any) - Defaults to nil.
  • events (:list) - %{id, date, label, kind} each. Defaults to [].
  • weekdays (:list) (required) - seven short names, in the order of the week start.
  • more_label (:string) (required) - +%{count} more, with the count placed by the caller.
  • prev_label (:string) (required)
  • next_label (:string) (required)
  • select_event (:string) (required)
  • prev_event (:string) (required)
  • next_event (:string) (required)
  • class (:any) - Defaults to nil.
  • target (:any) - a phx-target (a @myself) when used inside a LiveComponent. Defaults to nil.
  • Global attributes are accepted.

Slots

  • prev_icon
  • next_icon
  • actions - controls beside the arrows, such as a month and week switch.

month_weeks(year, month, week_start \\ :sunday)

@spec month_weeks(pos_integer(), 1..12, :sunday | :monday) :: [[Date.t()]]

The weeks of a month, each a list of seven dates, from the week that holds the 1st to the one that holds the last day.

shift_month(date, delta)

@spec shift_month(Date.t(), -1 | 1) :: Date.t()

The first day of the month before and after the month of date.

title(date, view, week_start \\ :sunday)

@spec title(Date.t(), :month | :week, :sunday | :monday) :: String.t()

2026-10 for a month and 2026-10-11 – 2026-10-17 for a week, the neutral form a caller can replace with its own words.

week_days(date, week_start \\ :sunday)

@spec week_days(Date.t(), :sunday | :monday) :: [Date.t()]

The seven dates of the week date is in.