timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Kit

datepicker-ui Kit for Companion Packages

The kit entry of @pglejzer/datepicker-ui, the companion of timepicker-ui, exports the building blocks the picker uses, for packages built on top of it.

What the kit is

#

@pglejzer/datepicker-ui/kit exports the building blocks the picker itself uses, for packages built on top of datepicker-ui. It has named exports only.

index.ts
import {
PopoverHost,
resolveSurfaceMode,
parseDate,
} from "@pglejzer/datepicker-ui/kit";

Load the CSS

The hosts render dp-ui__container elements, so load main.css or index.css next to them.

Surfaces

#
ExportSignaturePurpose
PopoverHostnew PopoverHost(options)Docked surface: a popover placed next to an anchor element.
DialogHostnew DialogHost(options)Modal surface: a native dialog with a backdrop.
InlineHostnew InlineHost({ container, label })Inline surface inside a container element.
waitForExitwaitForExit(element: HTMLElement): Promise<void>Waits for an exit animation to finish.

Each host has root and body elements and open(), close() and destroy() methods.

Surface choice

#
ExportSignaturePurpose
resolveSurfaceModeresolveSurfaceMode(option: "auto" | "docked" | "modal", inlineEnabled: boolean, viewportWidth: number, viewportHeight: number): SurfaceModeReturns "docked", "modal" or "inline". "auto" means modal below 600 px wide or 480 px tall.
isFullscreenRangeisFullscreenRange(mode: CalendarMode, surface: SurfaceMode, viewportWidth: number, fullscreenBelow: number): booleanSays whether a range picker goes full screen.

Color scheme

#
ExportSignaturePurpose
detectColorSchemedetectColorScheme(from: HTMLElement): SchemeReturns "light" or "dark" for an element.
watchColorSchemewatchColorScheme(onChange: () => void): () => voidReports changes and returns a function that stops watching.

Date text

#

A date is { year, month, day }.

ExportSignaturePurpose
resolvePatternresolvePattern(format: FormatOption, locale: string, precision?: Precision): FormatPatternTurns "auto" or a pattern string into a pattern for a locale.
formatDateformatDate(date: PlainDate, pattern: FormatPattern): stringFormats a date as text.
parseDateparseDate(text: string, pattern: FormatPattern): PlainDate | nullParses typed text, or returns null.
maskDateTextmaskDateText(text: string, pattern: FormatPattern): stringFormats typed digits to the pattern.
formatHintformatHint(pattern: FormatPattern): stringReturns a hint for the pattern, such as a placeholder.
index.ts
import { resolvePattern, parseDate, formatDate } from "@pglejzer/datepicker-ui/kit";
const pattern = resolvePattern("dd.MM.yyyy", "de-DE");
const date = parseDate("14.03.2025", pattern);
// { year: 2025, month: 3, day: 14 }
if (date) formatDate(date, pattern);
// "14.03.2025"

Types

#
TypeMeaning
SurfaceHostCommon shape of the three hosts.
SurfaceMode"docked", "modal" or "inline".
Scheme"light" or "dark".
FormatPatternA resolved date pattern.
FormatOptionThe value of ui.format.
DatePartOne part of a pattern: day, month or year.
PlainDate{ year, month, day }.

From a CDN

#

dist/umd/kit.js exposes the exports as the global DatepickerUIKit.

index.html
<script src="https://unpkg.com/@pglejzer/datepicker-ui/dist/umd/kit.js"></script>
<script>
const { resolvePattern, parseDate } = DatepickerUIKit;
</script>
#
Esc