Litopis GitHub

API reference

Public APIs for @litopis/core and @litopis/dom.

DateValue

Litopis represents a calendar date without a time or time zone. Months and days are one-based. Supported years are 1 through 9999.

ts
interface DateValue {
  readonly day: number;
  readonly month: number;
  readonly year: number;
}

DateValue is the default public value. Use valueAs: "date" when the application works with native Date instances.

A valid value has year: 1…9999, month: 1…12 and a day valid for that month. For example { year: 2026, month: 7, day: 29 }.

ts
interface DateRange {
  readonly start: DateValue | null;
  readonly end: DateValue | null;
}

Value output

The calendar keeps date-only values internally. The controller can expose the same selection in the form that fits the consuming code.

ts
const picker = createDatePicker(root, {
  format: "dd.mm.yyyy",
  valueAs: "date",
});

picker.getValue();          // Date | null
picker.getInputValue();     // "29.02.2024"
picker.getISOValue();       // "2024-02-29"

getInputValue() is the exact value shown in the field, including the range separator. getISOValue() is always an ISO value for forms and storage. With valueAs: "date", selected, range, setDate() and setRange() also accept local Date instances. Litopis reads their local year, month and day and returns local-noon Date instances so a calendar day is not shifted at a daylight-saving transition.

selection and valueAs determine the return type together. Pass literals directly or preserve them with satisfies when options are stored first.

ts
import {
  createDatePicker,
  type DatePickerOptions,
  type DatePickerRange,
  type DateValue,
} from "@litopis/dom";

const dateValuePicker = createDatePicker(root);
const dateValue: DateValue | null = dateValuePicker.getValue();

const nativeDatePicker = createDatePicker(root, { valueAs: "date" });
const nativeDate: Date | null = nativeDatePicker.getValue();

const rangeOptions = {
  selection: "range",
  valueAs: "date",
} satisfies DatePickerOptions<"date", "range">;

const rangePicker = createDatePicker(root, rangeOptions);
const range: DatePickerRange<"date"> = rangePicker.getValue();
Options getValue()
Default DateValue | null
valueAs: "date" Date | null
selection: "range" { start: DateValue | null; end: DateValue | null }
selection: "range", valueAs: "date" { start: Date | null; end: Date | null }

Period boundaries

Month and year selections represent complete periods in values sent to an application or a form. Field text remains at the selected precision.

Granularity Single value / range start Range end Field text
"day" The selected day The selected day Configured date format
"month" First day of the month Last day of the month. February 2024 ends on 2024-02-29 YYYY-MM or MM.YYYY
"year" January 1 December 31 YYYY

For example, selecting February through March 2024 yields 2024-02-01/2024-03-31 from getISOValue(), while a field with format: "dd.mm.yyyy" displays 02.2024 – 03.2024.

createDatePicker

Mounts a date field and calendar into an existing element.

ts
function createDatePicker(
  root: HTMLElement,
  options?: DatePickerOptions,
): DatePickerController;

DatePickerOptions

Literal unions below are the complete set of accepted variants. Text options accept user-facing text. Locale accepts a supported BCP 47 tag such as "uk-UA".

Option Type Default Description
mode "inline" | "popover" "inline" "inline" stays in document flow. "popover" opens from the field.
selection "single" | "range" "single" "single" chooses one period. "range" chooses a start date then an end date.
granularity "day" | "month" | "year" "day" Chooses days, months or years. Period output uses real calendar boundaries. Field text remains at the selected precision.
range { start: DateValue | Date | null; end: DateValue | Date | null } { start: null, end: null } Initial range for selection: "range". A partial range may have only start. Endpoints are ordered chronologically.
layout "single" | "split" "split" for range "single" uses one start – end field. "split" uses From and To fields. It applies only to ranges.
panels 1 | 2 | "auto" "auto" for range 1 shows one month; 2 shows adjacent months; 2 stacks them vertically when the available calendar width is too narrow; "auto" shows two side by side only when both grids fit. Popovers use the calendar width and clamp it to the viewport, independent of the input width. Inline calendars fill their container.
closeOnSelect boolean true true closes a popover after selection. false leaves it open. Inline calendars stay open.
clearButton boolean false true adds a Clear footer action. false omits it.
clearLabel string "Clear" Any visible text for Clear, such as "Reset dates".
firstDayOfWeek 0 | 1 | 2 | 3 | 4 | 5 | 6 Locale-derived Overrides the locale. 0 means Sunday and 6 means Saturday. For example, 1 starts weeks on Monday.
format "yyyy-mm-dd" | "dd.mm.yyyy" | "mm/dd/yyyy" "yyyy-mm-dd" Visible mask and parsing. For example, "yyyy-mm-dd" uses 2026-07-29, "dd.mm.yyyy" uses 29.07.2026 and "mm/dd/yyyy" uses 07/29/2026.
label string | { start: string; end: string }. For example, "Travel date" "Date" for one field or "Start" / "End" for split fields Visible label and accessible name. A range object labels split fields. For example, { start: "Departure", end: "Return" }.
locale Supported BCP 47 tag, such as "uk-UA" Browser locale Omit it for the browser language. "uk-UA" localizes labels. Invalid tags fall back to "en-US".
min DateValue Not set Inclusive earliest selectable date. For example { year: 2026, month: 7, day: 1 }.
max DateValue Not set Inclusive latest selectable date. For example { year: 2026, month: 7, day: 31 }.
disabledDates readonly DateValue[] [] Explicit unavailable calendar days. A complete range cannot include an unavailable day. Replace the list through setOptions when it changes.
isDateDisabled (date: DateValue) => boolean Not set A synchronous predicate for unavailable dates, combined with bounds and the explicit list.
onValueChange (value: DateValue | Date | null) => void Not set Called after a single value changes. Its value follows valueAs. Use it to synchronize application state.
valueAs "date-value" | "date" "date-value" Chooses the representation returned by selection APIs and change callbacks: a DateValue object or a local native Date.
selected DateValue | Date | null null Initial single value. Use null for no date. Use range for range mode.
onRangeChange (range) => void Not set Called after either endpoint changes. The endpoint type follows valueAs. The completed end is expanded to the final day of a selected month or year.
onVisibleMonthChange (month: DateValue) => void Not set Called whenever the visible month changes, with its first day. It does not fire on initial render.
name string | { start: string; end: string }. For example, "period" Not set Native FormData name. A split range named "stay" submits stay[start] and stay[end]. Pass an object only when the endpoints need different names. A one-field range serializes full ISO boundaries, for example 2024-02-01/2024-03-31.
outsideDays boolean true true shows subdued adjacent-month dates. false leaves their cells empty.
season boolean false true adds a localized season beside the caption. false omits it.
todayButton boolean false true adds a Today footer action. false omits it.
size "compact" | "comfortable" "compact" "compact" uses 40px controls. "comfortable" uses at least 44px controls.
today DateValue Local current date Overrides the local current date. For example, { year: 2026, month: 7, day: 29 } for deterministic tests.
todayLabel string "Today" Any visible text for Today, such as "Jump to today".

DatePickerController

Method Result Description
open() void Opens a popover calendar.
close() void Closes a popover calendar and restores its closed state.
toggle() void Toggles popover visibility.
getValue() DateValue | Date | null or { start, end } for range Returns the selected value. Its shape follows selection. Its endpoint type follows valueAs.
getInputValue() string Returns the formatted field text. A range uses start – end.
getISOValue() string Returns ISO YYYY-MM-DD, a complete range as start/end with complete period boundaries or an empty string.
setDate(value) void Sets or clears selection and updates the input.
setRange(range) void Sets or clears range endpoints and synchronizes the fields and native form values.
setVisibleMonth(value) void Changes the month currently displayed.
setOptions(options) void Replaces options without remounting. Selection is preserved unless supplied.
goToToday() void Focuses and reveals today within configured bounds.
destroy() void Removes listeners, generated DOM and Litopis state attributes.

createDateField

Mounts only the masked text field. It is useful when the application provides its own calendar surface or needs typed date entry without a picker.

ts
const field = createDateField(root, {
  format: "dd.mm.yyyy",
  label: "Invoice date",
  min: { day: 1, month: 1, year: 2026 },
});

field.getDate();
field.getISOValue();
field.isValid();
field.setDate({ day: 16, month: 7, year: 2026 });
field.destroy();

DateFieldOptions

Option Accepted value Default Effect
format "yyyy-mm-dd" | "dd.mm.yyyy" | "mm/dd/yyyy" "yyyy-mm-dd" Input mask and parser. For example, "dd.mm.yyyy" accepts 29.07.2026.
label Visible text, such as "Invoice date" "Date" Visible label and accessible name.
min DateValue Not set Inclusive lower bound. Dates before it are invalid.
max DateValue Not set Inclusive upper bound. Dates after it are invalid.
value DateValue | null null Initial value. null starts with an empty field.

Core exports

@litopis/core has no DOM dependency and can be used for custom renderers, server-side validation and deterministic calendar calculations.

Date math

addDays, addMonths, addYears, startOfMonth, endOfMonth, getDaysInMonth

Comparison and validation

compareDates, clampDate, isSameDate, isValidDateValue, isDateDisabled

Formatting

formatDate, toIsoDate, toLocalDate, getToday

Calendar state

createCalendarState, createCalendarGrid, moveFocus, focusDate, selectDate, selectFocusedDate