@momentra/angular 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/fesm2022/momentra-angular-date-fns.mjs +101 -0
- package/fesm2022/momentra-angular-date-fns.mjs.map +1 -0
- package/fesm2022/momentra-angular-luxon.mjs +89 -0
- package/fesm2022/momentra-angular-luxon.mjs.map +1 -0
- package/fesm2022/momentra-angular.mjs +6969 -0
- package/fesm2022/momentra-angular.mjs.map +1 -0
- package/llms-full.txt +937 -0
- package/llms.txt +42 -0
- package/package.json +67 -4
- package/types/momentra-angular-date-fns.d.ts +47 -0
- package/types/momentra-angular-luxon.d.ts +48 -0
- package/types/momentra-angular.d.ts +2128 -0
package/llms-full.txt
ADDED
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
<!-- source: README.md -->
|
|
2
|
+
|
|
3
|
+
# Momentra — The Angular Date & Time Toolkit
|
|
4
|
+
|
|
5
|
+
[](https://github.com/oscarandrespabonestrella/momentra/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@momentra/angular)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
Momentra is a modern, extensible Angular date and time component library providing beautiful, accessible, and highly configurable date pickers, calendars, time pickers, date-time pickers, and date range components.
|
|
10
|
+
|
|
11
|
+
- **Package:** `@momentra/angular` · **Selector prefix:** `mtr` · **Angular:** 22 (standalone components, signals, OnPush)
|
|
12
|
+
- **No UI framework dependency.** Momentra owns its components and styling. It needs only Angular and the Angular CDK (overlay and a11y utilities).
|
|
13
|
+
- **Bring your own date library.** The core talks to a `DateAdapter<TDate>`; native `Date` is the default, with optional date-fns and Luxon adapters in separate entry points.
|
|
14
|
+
|
|
15
|
+
> **Status: 0.1.0-alpha.0, pre-release** (published to the `next` dist-tag: `npm i @momentra/angular@next`). The library is feature-complete for the scope listed below, is covered by an automated test suite, and builds and installs from the packed tarball. It has been tested in jsdom, not yet in real browsers or with real screen readers — see [Known limitations](#known-limitations) before using it in production.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
| Component | Selector | What it does |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `DateInputComponent` | `<mtr-date-input>` | Text input: configurable format, parsing, validation, clear button, arrow-key stepping |
|
|
22
|
+
| `DatePickerComponent` | `<mtr-date-picker>` | Date input + calendar popup, min/max, disabled dates, Today/Clear, custom day templates |
|
|
23
|
+
| `TimePickerComponent` | `<mtr-time-picker>` | Hour/minute/(second)/AM-PM lists, 12/24-hour clock, intervals, min/max time |
|
|
24
|
+
| `DateTimePickerComponent` | `<mtr-datetime-picker>` | Calendar and time lists in one popup, separate date/time formats |
|
|
25
|
+
| `CalendarComponent` | `<mtr-calendar>` | Day, month, year and decade views, keyboard navigation, custom cell templates |
|
|
26
|
+
| `MonthPickerComponent` | `<mtr-month-picker>` | Select a month |
|
|
27
|
+
| `YearPickerComponent` | `<mtr-year-picker>` | Select a year |
|
|
28
|
+
| `DecadePickerComponent` | `<mtr-decade-picker>` | Select a decade |
|
|
29
|
+
| `DateRangePickerComponent` | `<mtr-date-range-picker>` | Start/end with live highlighting, presets, min/max length, incomplete ranges |
|
|
30
|
+
|
|
31
|
+
Across the library:
|
|
32
|
+
|
|
33
|
+
- **Angular Forms**: every input is a `ControlValueAccessor` *and* a `Validator`; works with `formControl`, `formControlName` and `ngModel`; honours disabled/touched/dirty state.
|
|
34
|
+
- **Validation**: `MomentraValidators` (`minDate`, `maxDate`, `dateRange`, `minTime`, `minRangeLength`, …) plus rules the components apply on their own, with localizable messages.
|
|
35
|
+
- **Localization**: locales for any `Intl` tag, a built-in English and Spanish locale, custom locale objects, per-component overrides.
|
|
36
|
+
- **Theming**: light, dark and `auto` themes driven by documented `--mtr-*` CSS custom properties.
|
|
37
|
+
- **Accessibility**: ARIA grid/listbox/combobox/dialog patterns, roving tabindex, focus trap and focus return, live regions, checked with axe-core in the test suite.
|
|
38
|
+
- **Time-zone safe**: calendar dates never pass through UTC; see [Dates and time zones](docs/dates-and-time-zones.md).
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @momentra/angular @angular/cdk
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Peer dependencies: `@angular/core`, `@angular/common`, `@angular/forms` and `@angular/cdk` (all `^22.3.0`). `date-fns` and `luxon` are **optional** peers, needed only if you import `@momentra/angular/date-fns` or `@momentra/angular/luxon`.
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { Component } from '@angular/core';
|
|
52
|
+
import { FormsModule } from '@angular/forms';
|
|
53
|
+
import { DatePickerComponent } from '@momentra/angular';
|
|
54
|
+
|
|
55
|
+
@Component({
|
|
56
|
+
selector: 'app-basic-date-picker',
|
|
57
|
+
imports: [FormsModule, DatePickerComponent],
|
|
58
|
+
template: `
|
|
59
|
+
<mtr-date-picker [(ngModel)]="selectedDate" placeholder="Choose a date" ariaLabel="Delivery date" />
|
|
60
|
+
<p>Selected: {{ selectedDate?.toDateString() ?? 'nothing' }}</p>
|
|
61
|
+
`,
|
|
62
|
+
})
|
|
63
|
+
export class BasicDatePickerExample {
|
|
64
|
+
selectedDate: Date | null = null;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Reactive forms, with validators (`examples/reactive-form.ts`):
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
readonly form = new FormGroup({
|
|
72
|
+
birthday: new FormControl<Date | null>(null, [Validators.required, MomentraValidators.maxDate(() => new Date())]),
|
|
73
|
+
dueDate: new FormControl<Date | null>(null, MomentraValidators.minDate(() => new Date())),
|
|
74
|
+
startTime: new FormControl<Date | null>(null),
|
|
75
|
+
appointment: new FormControl<Date | null>(null, Validators.required),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<mtr-date-input inputId="birthday" formControlName="birthday" format="dd/MM/yyyy" />
|
|
81
|
+
<mtr-date-picker ariaLabel="Due date" formControlName="dueDate" [min]="today" />
|
|
82
|
+
<mtr-time-picker ariaLabel="Start time" formControlName="startTime" [hourFormat]="24" [minuteStep]="15" />
|
|
83
|
+
<mtr-datetime-picker ariaLabel="Appointment" formControlName="appointment" [minuteStep]="30" />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A date range with presets (`examples/date-range-with-presets.ts`):
|
|
87
|
+
|
|
88
|
+
```html
|
|
89
|
+
<mtr-date-range-picker ariaLabel="Stay" [formControl]="stay" [presets]="presets"
|
|
90
|
+
[minRangeLength]="2" [maxRangeLength]="30" [min]="today" />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> Give every control an accessible name: either a visible `<label for>` pointing at `inputId`, or `ariaLabel` / `ariaLabelledby`.
|
|
94
|
+
|
|
95
|
+
All examples in [`examples/`](examples) are compiled with the Angular compiler in strict mode (`npm run examples:check`).
|
|
96
|
+
|
|
97
|
+
## Configuration
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { provideMomentra } from '@momentra/angular';
|
|
101
|
+
|
|
102
|
+
bootstrapApplication(App, {
|
|
103
|
+
providers: [
|
|
104
|
+
provideMomentra({
|
|
105
|
+
locale: 'es-ES', // any Intl tag, 'en-US' (default), 'es-ES', or a registered/custom locale
|
|
106
|
+
firstDayOfWeek: 1, // 0 = Sunday … 6 = Saturday; defaults to the locale's
|
|
107
|
+
theme: 'auto', // 'light' | 'dark' | 'auto'
|
|
108
|
+
dateFormat: 'dd/MM/yyyy',
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Every option, and how components override them, is in [Component APIs](docs/components.md#global-configuration). Configuration is immutable and provided through Angular DI; there is no global mutable state.
|
|
115
|
+
|
|
116
|
+
## Theming
|
|
117
|
+
|
|
118
|
+
Components read `--mtr-*` CSS custom properties with light/dark defaults:
|
|
119
|
+
|
|
120
|
+
```css
|
|
121
|
+
:root {
|
|
122
|
+
--mtr-primary: #0f766e;
|
|
123
|
+
--mtr-radius: 12px;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Set theme variables on `:root` (or `body`), because popups render in the CDK overlay container. See [Styling and themes](docs/styling-and-themes.md).
|
|
128
|
+
|
|
129
|
+
## Date adapters
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { provideMomentraLuxon } from '@momentra/angular/luxon';
|
|
133
|
+
|
|
134
|
+
providers: [provideMomentraLuxon({ locale: 'es-ES' }, { zone: 'Europe/Madrid' })];
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
See [Date adapters](docs/date-adapters.md) for the native, date-fns and Luxon adapters and for writing your own.
|
|
138
|
+
|
|
139
|
+
## Documentation
|
|
140
|
+
|
|
141
|
+
- [Architecture](docs/architecture.md)
|
|
142
|
+
- [Date adapters](docs/date-adapters.md)
|
|
143
|
+
- [Dates and time zones](docs/dates-and-time-zones.md)
|
|
144
|
+
- [Component APIs](docs/components.md) — inputs, outputs, methods
|
|
145
|
+
- [Validation](docs/validation.md)
|
|
146
|
+
- [Localization](docs/localization.md)
|
|
147
|
+
- [Styling and themes](docs/styling-and-themes.md)
|
|
148
|
+
- [Accessibility](docs/accessibility.md)
|
|
149
|
+
- [Contributing](CONTRIBUTING.md) · [Release and publishing](docs/release-and-publishing.md) · [Changelog](CHANGELOG.md)
|
|
150
|
+
|
|
151
|
+
## Browser compatibility
|
|
152
|
+
|
|
153
|
+
Momentra targets the evergreen browsers supported by Angular 22 (current Chrome, Edge, Firefox and Safari). Its styles use CSS custom properties, `:focus-visible`, `color-mix()`, `prefers-color-scheme` and `forced-colors` media queries. The test suite runs in jsdom; real-browser verification is listed under [Known limitations](#known-limitations).
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npm install
|
|
159
|
+
npm test # unit tests (Vitest, jsdom)
|
|
160
|
+
npm run test:tz # unit tests in 8 time zones
|
|
161
|
+
npm run examples:check # compile the examples with the Angular compiler (strict templates)
|
|
162
|
+
npm run build # production library build -> dist/momentra
|
|
163
|
+
npm run verify:package # build, npm pack, install into a fresh Angular app, build that app
|
|
164
|
+
npm run check # tests + examples + build
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Workspace layout:
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
projects/momentra/src/lib/ core/ inputs/ calendar/ ranges/ formatting/ localization/ theming/ testing/
|
|
171
|
+
projects/momentra/date-fns/ optional date-fns entry point (momentra/date-fns)
|
|
172
|
+
projects/momentra/luxon/ optional Luxon entry point (momentra/luxon)
|
|
173
|
+
docs/ examples/ scripts/
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Release
|
|
177
|
+
|
|
178
|
+
1. Bump `version` in `projects/momentra/package.json` and update [CHANGELOG.md](CHANGELOG.md).
|
|
179
|
+
2. Merge to `main`, then tag it: `git tag vX.Y.Z && git push origin vX.Y.Z`.
|
|
180
|
+
3. Run the **Release** workflow from the tag: `gh workflow run release.yml --ref vX.Y.Z`.
|
|
181
|
+
|
|
182
|
+
The workflow publishes with npm [trusted publishing](https://docs.npmjs.com/trusted-publishers) and provenance, no token needed. Versions with a pre-release suffix (`-alpha.1`) go to the `next` dist-tag; the rest go to `latest`. See [Release and publishing](docs/release-and-publishing.md), including the one-time first publish.
|
|
183
|
+
|
|
184
|
+
## Known limitations
|
|
185
|
+
|
|
186
|
+
- **Not yet verified in real browsers or with screen readers.** Automated checks (axe-core, keyboard and ARIA assertions) run in jsdom, which has no layout or colour engine: colour contrast, popup positioning and responsive CSS have not been visually verified, and no assistive technology has been tried.
|
|
187
|
+
- The range picker shows one month at a time (no side-by-side months).
|
|
188
|
+
- While the end of a range is being chosen, days that would break `minRangeLength`/`maxRangeLength` are disabled; to restart with a later day, clear the range or edit the start input.
|
|
189
|
+
- Popups render in the CDK overlay container, so theme variables must be set on `:root`/`body`, not on an arbitrary ancestor.
|
|
190
|
+
- The future-ready features (fiscal/holiday calendars, week and multiple-date selection, recurring selections, business-day calculations) are **not implemented**; see [Architecture](docs/architecture.md#extension-points) for what the design already supports.
|
|
191
|
+
- Locale-aware parsing works through the locale's patterns and names; it does not guess formats and does not parse free-form text ("next friday").
|
|
192
|
+
- Right-to-left layouts are not specially handled.
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT — see [LICENSE](LICENSE).
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
<!-- source: docs/components.md -->
|
|
202
|
+
|
|
203
|
+
# Component APIs
|
|
204
|
+
|
|
205
|
+
All components are standalone, `OnPush`, generic over the date type (`<TDate = Date>`), and use signal `input()`/`model()`/`output()`. Import them from `@momentra/angular`.
|
|
206
|
+
|
|
207
|
+
Two-way bindable members are `model()`s: `[(value)]`, `[(open)]`, `[(view)]`.
|
|
208
|
+
|
|
209
|
+
## Inputs shared by every control
|
|
210
|
+
|
|
211
|
+
Available on `mtr-date-input`, `mtr-date-picker`, `mtr-time-picker`, `mtr-datetime-picker`, `mtr-date-range-picker`, `mtr-calendar`, `mtr-month-picker`, `mtr-year-picker` and `mtr-decade-picker`.
|
|
212
|
+
|
|
213
|
+
| Input | Type | Default | Description |
|
|
214
|
+
| --- | --- | --- | --- |
|
|
215
|
+
| `disabled` | `boolean` | `false` | Disables the control (also set by `control.disable()`). |
|
|
216
|
+
| `readonly` | `boolean` | `false` | Shows the value, blocks editing and opening popups. |
|
|
217
|
+
| `required` | `boolean` | `false` | An empty value reports `required`. |
|
|
218
|
+
| `locale` | `string \| MomentraLocale` | global | Locale code or object. |
|
|
219
|
+
| `firstDayOfWeek` | `number` | locale's | 0 = Sunday … 6 = Saturday. |
|
|
220
|
+
| `errorMessages` | `Partial<MomentraValidationMessages>` | — | Per-control message templates. |
|
|
221
|
+
| `showErrors` | `boolean` | `true` | Show validation messages once touched. |
|
|
222
|
+
| `ariaLabel` | `string` | — | Accessible name. |
|
|
223
|
+
| `ariaLabelledby` | `string` | — | Id(s) of labelling elements. |
|
|
224
|
+
| `inputId` | `string` | generated | Id of the inner `<input>` so `<label for>` works. |
|
|
225
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | global | Per-component theme. |
|
|
226
|
+
|
|
227
|
+
## `mtr-date-input`
|
|
228
|
+
|
|
229
|
+
A text input for a calendar date. Value: `TDate | null` (local start of day).
|
|
230
|
+
|
|
231
|
+
| Input | Type | Description |
|
|
232
|
+
| --- | --- | --- |
|
|
233
|
+
| `value` (model) | `TDate \| null` | The date. |
|
|
234
|
+
| `format` | `string` | Pattern, default the locale's date format. |
|
|
235
|
+
| `min`, `max` | `TDate` | Bounds (whole days). |
|
|
236
|
+
| `disabledDates` | `(date) => boolean \| TDate[]` | Dates that cannot be entered. |
|
|
237
|
+
| `placeholder` | `string` | Default: global placeholder, else the pattern (`mm/dd/yyyy`). |
|
|
238
|
+
| `showClear` | `boolean` | Clear button; default global (`true`). |
|
|
239
|
+
|
|
240
|
+
Keyboard: `↑`/`↓` step the day (`Shift` month, `Ctrl` year); `Enter` normalizes the text. Typing an unparsable or impossible date sets `mtrInvalidDate` and emits `null`; the text is kept for correction.
|
|
241
|
+
|
|
242
|
+
## `mtr-date-picker`
|
|
243
|
+
|
|
244
|
+
`mtr-date-input` plus a calendar popup. In addition:
|
|
245
|
+
|
|
246
|
+
| Input / Output | Type | Description |
|
|
247
|
+
| --- | --- | --- |
|
|
248
|
+
| `cellTemplate` | `TemplateRef<MtrCellContext<TDate>>` | Custom day content. |
|
|
249
|
+
| `showToday` | `boolean` | *Today* button (default global `true`). |
|
|
250
|
+
| `initialDate` | `TDate` | Month to show when there is no value. |
|
|
251
|
+
| `closeOnSelect` | `boolean` | Close after picking (default global `true`). |
|
|
252
|
+
| `open` (model) | `boolean` | Popup state. |
|
|
253
|
+
| `opened`, `closed` | `void` | Popup events. |
|
|
254
|
+
| `openPopup()`, `closePopup(restoreFocus?)`, `focusInput()` | methods | Programmatic control. |
|
|
255
|
+
|
|
256
|
+
Keyboard: `Alt+↓` opens; `Escape` closes and returns focus to the input; arrow keys, `PageUp`/`PageDown`, `Home`/`End` navigate the calendar; `Enter`/`Space` select.
|
|
257
|
+
|
|
258
|
+
## `mtr-time-picker`
|
|
259
|
+
|
|
260
|
+
Value: a `TDate` whose **time of day** is the time. Its date part is the previous value's date, or `baseDate`.
|
|
261
|
+
|
|
262
|
+
| Input | Type | Description |
|
|
263
|
+
| --- | --- | --- |
|
|
264
|
+
| `format` | `string` | Explicit time pattern (`'HH:mm'`, `'h:mm a'`); wins over the two inputs below. |
|
|
265
|
+
| `hourFormat` | `12 \| 24` | Default: the locale's clock. |
|
|
266
|
+
| `showSeconds` | `boolean` | Default: what the pattern shows. |
|
|
267
|
+
| `hourStep`, `minuteStep`, `secondStep` | `number` | Intervals in the lists (default 1; invalid values fall back to 1). |
|
|
268
|
+
| `min`, `max` | `TDate` | Time-of-day limits (the date part is ignored). |
|
|
269
|
+
| `baseDate` | `TDate` | Date for values created from scratch (default today). |
|
|
270
|
+
|
|
271
|
+
The popup has `listbox` columns; `↑`/`↓`/`Home`/`End` change *and* select, `←`/`→` move between columns. *Now* snaps the current time to the steps; *Done* closes. Keyboard stepping in the text input moves minutes (`Shift` hours, `Ctrl` seconds). Inherits `open`, `opened`, `closed`, `placeholder`, `showClear`, `openPopup()`, `closePopup()`.
|
|
272
|
+
|
|
273
|
+
## `mtr-datetime-picker`
|
|
274
|
+
|
|
275
|
+
Calendar and time lists in one popup. Value: local date-time.
|
|
276
|
+
|
|
277
|
+
| Input | Type | Description |
|
|
278
|
+
| --- | --- | --- |
|
|
279
|
+
| `format` | `string` | Full date-time pattern; overrides everything below. |
|
|
280
|
+
| `dateFormat`, `timeFormat` | `string` | Parts of the pattern. |
|
|
281
|
+
| `hourFormat`, `showSeconds`, `hourStep`, `minuteStep`, `secondStep` | | As in the time picker. |
|
|
282
|
+
| `min`, `max` | `TDate` | Exact date-times. Time lists restrict the time of day only on the boundary days. |
|
|
283
|
+
| `disabledDates`, `cellTemplate`, `showToday`, `initialDate` | | As in the date picker. |
|
|
284
|
+
|
|
285
|
+
Picking a day keeps the current time; changing the time keeps the day. The popup stays open until *Done*, `Escape` or an outside click (`closeOnSelect` does not apply).
|
|
286
|
+
|
|
287
|
+
## `mtr-calendar`
|
|
288
|
+
|
|
289
|
+
| Input / Output | Type | Description |
|
|
290
|
+
| --- | --- | --- |
|
|
291
|
+
| `value` (model) | `TDate \| null` | Selected day. |
|
|
292
|
+
| `view` (model) | `'day' \| 'month' \| 'year' \| 'decade'` | Displayed view. |
|
|
293
|
+
| `selectionView` | same | View in which a click *selects*; coarser views drill down. Default `'day'`. |
|
|
294
|
+
| `min`, `max` | `TDate` | Bounds; navigation arrows disable at the edges. |
|
|
295
|
+
| `disabledDates` | `(date) => boolean \| TDate[]` | Unselectable days. |
|
|
296
|
+
| `range` | `{ start: TDate \| null; end: TDate \| null }` | Highlighted range (partial ranges allowed). |
|
|
297
|
+
| `cellTemplate` | `TemplateRef<MtrCellContext<TDate>>` | Context: `$implicit: CalendarCell`, `view`. |
|
|
298
|
+
| `initialDate` | `TDate` | Date shown when there is no value. |
|
|
299
|
+
| `showToday`, `fixedWeeks` | `boolean` | Defaults from global config. |
|
|
300
|
+
| `dateSelect` | `TDate` | A date was picked in the selection view. |
|
|
301
|
+
| `dateHover` | `TDate \| null` | Day under pointer/focus (day view), `null` on leave. |
|
|
302
|
+
| `activeDateChange` | `TDate` | Keyboard focus moved. |
|
|
303
|
+
| `focusActiveCell()` | method | Move DOM focus into the grid. |
|
|
304
|
+
|
|
305
|
+
Keyboard (day view): `←→↑↓` day/week, `PageUp`/`PageDown` month (`Shift` year), `Home`/`End` start/end of week, `Ctrl+↑` coarser view, `Enter`/`Space` select. Month view moves by month and 3 months, year view by year and 4 years, decade view by 10 and 40 years.
|
|
306
|
+
|
|
307
|
+
`CalendarCell`: `date`, `label`, `ariaLabel`, `disabled`, `selected`, `active`, `today`, `outside`, `inRange`, `rangeStart`, `rangeEnd`, `key`.
|
|
308
|
+
|
|
309
|
+
## `mtr-month-picker`, `mtr-year-picker`, `mtr-decade-picker`
|
|
310
|
+
|
|
311
|
+
A calendar locked to `selectionView` `'month'`, `'year'` or `'decade'`. Value: the **first day of the selected period** (first of the month; 1 January; 1 January of the decade's first year). Inputs: `value` (model), `min`, `max`, `showToday`, plus the shared inputs. A period is disabled when it lies entirely outside `min`/`max`.
|
|
312
|
+
|
|
313
|
+
## `mtr-date-range-picker`
|
|
314
|
+
|
|
315
|
+
Value: `DateRange<TDate>` = `{ start: TDate | null; end: TDate | null }` (both local start of day). `null` written by a form becomes an empty range.
|
|
316
|
+
|
|
317
|
+
| Input / Output | Type | Description |
|
|
318
|
+
| --- | --- | --- |
|
|
319
|
+
| `value` (model) | `DateRange<TDate>` | The range; may be incomplete. |
|
|
320
|
+
| `min`, `max` | `TDate` | Bounds for both ends. |
|
|
321
|
+
| `minRangeLength`, `maxRangeLength` | `number` | Days spanned, inclusive (a one-day range is 1). |
|
|
322
|
+
| `disabledDates` | `(date) => boolean \| TDate[]` | Days that cannot be part of a range. |
|
|
323
|
+
| `presets` | `DateRangePreset<TDate>[]` | `{ label, range }`; `range` may be a function evaluated on use. Presets that violate the constraints are disabled. |
|
|
324
|
+
| `format`, `placeholder` | `string` | For both inputs. |
|
|
325
|
+
| `cellTemplate`, `showToday`, `showClear`, `closeOnSelect`, `initialDate` | | As elsewhere. |
|
|
326
|
+
| `open` (model), `opened`, `closed` | | Popup state and events. |
|
|
327
|
+
| `openPopup()`, `closePopup(restoreFocus?)`, `focusStart()` | methods | |
|
|
328
|
+
|
|
329
|
+
Selecting: the first click sets `start` (the value becomes an **incomplete range**, reported as `mtrRangeIncomplete`); the second click on or after `start` completes it; a click before `start` restarts it; a click after a complete range starts a new one. Hovering or keyboard-focusing days previews the range. While the end is chosen, days that would break the length limits are disabled.
|
|
330
|
+
|
|
331
|
+
Helpers: `pickRangeDate`, `isSameRange`, `createPreset`, `lastDaysRange(adapter, n)`, `thisWeekRange(adapter, firstDayOfWeek)`, `thisMonthRange`, `lastMonthRange`, `resolvePreset`, `emptyRange`, `isCompleteRange`.
|
|
332
|
+
|
|
333
|
+
## Global configuration
|
|
334
|
+
|
|
335
|
+
`provideMomentra(config)` — all options are optional.
|
|
336
|
+
|
|
337
|
+
| Option | Type | Default | |
|
|
338
|
+
| --- | --- | --- | --- |
|
|
339
|
+
| `locale` | `string \| MomentraLocale` | `'en-US'` | Code (built-in, registered or `Intl`) or object. |
|
|
340
|
+
| `locales` | `MomentraLocale[]` | `[]` | Registers locales addressable by code. |
|
|
341
|
+
| `dateFormat`, `timeFormat`, `dateTimeFormat` | `string` | locale's | Override the locale's patterns. |
|
|
342
|
+
| `firstDayOfWeek` | `number` | locale's | |
|
|
343
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | |
|
|
344
|
+
| `placeholder` | `string` | pattern | Placeholder for text inputs. |
|
|
345
|
+
| `dateAdapter` | `Type<DateAdapter<unknown>>` | `NativeDateAdapter` | |
|
|
346
|
+
| `showTodayButton` | `boolean` | `true` | |
|
|
347
|
+
| `showClearButton` | `boolean` | `true` | |
|
|
348
|
+
| `closeOnSelect` | `boolean` | `true` | Date picker and range picker. |
|
|
349
|
+
| `fixedWeeks` | `boolean` | `false` | Always six weeks in the day view. |
|
|
350
|
+
| `validationMessages` | `Partial<MomentraValidationMessages>` | — | Message templates. |
|
|
351
|
+
|
|
352
|
+
Precedence for the effective locale of a component: component inputs → global config → locale object.
|
|
353
|
+
|
|
354
|
+
## Events and outputs summary
|
|
355
|
+
|
|
356
|
+
| Output | Components |
|
|
357
|
+
| --- | --- |
|
|
358
|
+
| `valueChange` | every control with a `value` model (`[(value)]`) |
|
|
359
|
+
| `viewChange` | `mtr-calendar` (`[(view)]`) |
|
|
360
|
+
| `openChange` | pickers with a popup (`[(open)]`) |
|
|
361
|
+
| `opened`, `closed` | pickers with a popup |
|
|
362
|
+
| `dateSelect`, `dateHover`, `activeDateChange` | `mtr-calendar` |
|
|
363
|
+
|
|
364
|
+
Changes to a control's value are also delivered through Angular Forms (`valueChanges`, `ngModelChange`).
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
<!-- source: docs/styling-and-themes.md -->
|
|
370
|
+
|
|
371
|
+
# Styling and themes
|
|
372
|
+
|
|
373
|
+
Momentra ships its own design system: no global stylesheet to import, no framework CSS. Component styles are encapsulated, and every colour, radius, size and shadow is a CSS custom property you can override.
|
|
374
|
+
|
|
375
|
+
## Themes
|
|
376
|
+
|
|
377
|
+
`light` (default), `dark`, and `auto` (follows `prefers-color-scheme`).
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
provideMomentra({ theme: 'auto' }); // global
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
```html
|
|
384
|
+
<mtr-date-picker theme="dark" /> <!-- per component -->
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
The effective theme is written to the host as `data-mtr-theme="light|dark|auto"`; popups carry the same attribute.
|
|
388
|
+
|
|
389
|
+
## Custom properties
|
|
390
|
+
|
|
391
|
+
Override any of these on `:root` (or `body`):
|
|
392
|
+
|
|
393
|
+
| Property | Light default | Dark default | Used for |
|
|
394
|
+
| --- | --- | --- | --- |
|
|
395
|
+
| `--mtr-primary` | `#4c5bd4` | `#7f8cff` | Selected day, primary buttons, accents |
|
|
396
|
+
| `--mtr-primary-contrast` | `#ffffff` | `#0b0d12` | Text on `--mtr-primary` |
|
|
397
|
+
| `--mtr-primary-soft` | `#eceefd` | `#252a4a` | Active preset, selected time, soft fills |
|
|
398
|
+
| `--mtr-primary-text` | `#3542ae` | `#c3c9ff` | Text on `--mtr-primary-soft` |
|
|
399
|
+
| `--mtr-surface` | `#ffffff` | `#151821` | Field and popup background |
|
|
400
|
+
| `--mtr-surface-alt` | `#f7f8fa` | `#1b1f2a` | Disabled / read-only fields, side rails |
|
|
401
|
+
| `--mtr-surface-hover` | `#eef0f5` | `#232836` | Hover background |
|
|
402
|
+
| `--mtr-text` | `#151922` | `#e9ebf1` | Text |
|
|
403
|
+
| `--mtr-text-muted` | `#555d6e` | `#a1a8b8` | Placeholders, secondary text |
|
|
404
|
+
| `--mtr-text-subtle` | `#6f7685` | `#8e95a6` | Weekday headers, captions |
|
|
405
|
+
| `--mtr-text-disabled` | `#a6acb8` | `#565d6e` | Disabled text |
|
|
406
|
+
| `--mtr-border` | `#d5d9e1` | `#2c3242` | Dividers |
|
|
407
|
+
| `--mtr-border-strong` | `#b4bac7` | `#454d62` | Field border |
|
|
408
|
+
| `--mtr-danger` | `#c2342b` | `#f2766b` | Invalid state and error messages |
|
|
409
|
+
| `--mtr-today` | `#b45309` | `#f2b544` | Today marker |
|
|
410
|
+
| `--mtr-range` | `#e6e9fc` | `#21264a` | Days inside a selected range |
|
|
411
|
+
| `--mtr-range-text` | `#232a6b` | `#d6daff` | Text on `--mtr-range` |
|
|
412
|
+
| `--mtr-ring` | `rgba(76,91,212,.32)` | `rgba(127,140,255,.4)` | Focus halo |
|
|
413
|
+
| `--mtr-focus-ring` | `#4c5bd4` | `#7f8cff` | Keyboard focus outline |
|
|
414
|
+
| `--mtr-shadow` | soft two-layer shadow | stronger | Popup elevation |
|
|
415
|
+
| `--mtr-shadow-sm` | `0 1px 2px …` | stronger | Field elevation |
|
|
416
|
+
| `--mtr-radius` | `8px` | | Fields and popups |
|
|
417
|
+
| `--mtr-radius-sm` | `6px` | | Cells and buttons |
|
|
418
|
+
| `--mtr-font-family` | `Inter, system-ui, …` | | |
|
|
419
|
+
| `--mtr-font-size` | `14px` | | |
|
|
420
|
+
| `--mtr-spacing` | `12px` | | Calendar padding unit |
|
|
421
|
+
| `--mtr-cell-size` | `38px` | | Calendar column width |
|
|
422
|
+
| `--mtr-cell-height` | `34px` | | Calendar cell height |
|
|
423
|
+
| `--mtr-field-width` | `14rem` (time `12rem`, date-time `18rem`, range `22rem`) | | Width of the input fields (all are `inline-block`, capped at 100% of the container). Set `width: 100%` on a field's host element to make it fill its container. |
|
|
424
|
+
| `--mtr-spinner-width` | `26px` | | Up/down spinner buttons |
|
|
425
|
+
| `--mtr-infinite-width` / `--mtr-infinite-height` / `--mtr-infinite-rail-width` | `auto` / `300px` / `76px` | | `mtr-infinite-calendar` sizing |
|
|
426
|
+
| `--mtr-multiview-gap` | `34px` | | Gap between months in `mtr-multiview-calendar` |
|
|
427
|
+
|
|
428
|
+
A value you set applies to **both** light and dark; scope it yourself if you want different values:
|
|
429
|
+
|
|
430
|
+
```css
|
|
431
|
+
:root {
|
|
432
|
+
--mtr-primary: #0f766e;
|
|
433
|
+
--mtr-radius: 12px;
|
|
434
|
+
}
|
|
435
|
+
@media (prefers-color-scheme: dark) {
|
|
436
|
+
:root { --mtr-primary: #5eead4; }
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
> **Set variables on `:root` or `body`.** Popups render in the CDK overlay container, which is a sibling of your app root, so variables set on an arbitrary ancestor of the picker do not reach the popup. Variables on the host element itself (or `:root`) always reach the input.
|
|
441
|
+
|
|
442
|
+
## How it works
|
|
443
|
+
|
|
444
|
+
`theming/_tokens.scss` defines, per component host, private `--_mtr-*` aliases that each fall back from the public property to a theme default (`--_mtr-primary: var(--mtr-primary, #3b5bdb)`), plus dark defaults under `[data-mtr-theme='dark']` and `@media (prefers-color-scheme: dark)` for `auto`. Because the public property is read with a fallback, your override wins in either theme.
|
|
445
|
+
|
|
446
|
+
## States
|
|
447
|
+
|
|
448
|
+
Every interactive element has hover, `:focus-visible`, selected, disabled and invalid styling:
|
|
449
|
+
|
|
450
|
+
- Calendar cells: `.mtr-selected`, `.mtr-today`, `.mtr-outside`, `.mtr-disabled`, `.mtr-in-range`, `.mtr-range-start`, `.mtr-range-end`.
|
|
451
|
+
- Fields: invalid (red border, `aria-invalid`), disabled, read-only.
|
|
452
|
+
- High-contrast: selected cells and fields get a system `Highlight` outline under `forced-colors: active`.
|
|
453
|
+
|
|
454
|
+
Internal class names are not a stable API — customise through the custom properties and the `cellTemplate` inputs rather than by targeting `.mtr-*` classes.
|
|
455
|
+
|
|
456
|
+
## Responsive behaviour
|
|
457
|
+
|
|
458
|
+
Popups are limited to the viewport (`max-width: calc(100vw - 16px)`), repositioned/flipped by the CDK, and on narrow screens (≤ 420px, ≤ 560px for the wider popups) the calendar uses larger cells, the date-time popup stacks the time lists under the calendar, and range presets wrap above the calendar.
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
<!-- source: docs/localization.md -->
|
|
464
|
+
|
|
465
|
+
# Localization
|
|
466
|
+
|
|
467
|
+
Nothing user-visible is hard-coded in components: month and weekday names, default formats, the first day of the week, the AM/PM labels, every button label and ARIA label, and validation messages all come from a `MomentraLocale`.
|
|
468
|
+
|
|
469
|
+
## Choosing a locale
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
provideMomentra({ locale: 'es-ES' }); // global
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
```html
|
|
476
|
+
<mtr-date-picker locale="de-DE" /> <!-- per component -->
|
|
477
|
+
<mtr-date-picker [locale]="myLocale" /> <!-- or a locale object -->
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
A locale code is resolved in this order: locales registered with `provideMomentra({ locales })` → built-in `en-US` and `es-ES` → derived from `Intl` for any other tag.
|
|
481
|
+
|
|
482
|
+
### What `Intl`-derived locales provide
|
|
483
|
+
|
|
484
|
+
`createLocale('de-DE')` builds, from the platform's `Intl` implementation: month names (long/short), weekday names (long/short/narrow), the meridiem labels, the first day of the week, a numeric **date pattern** (`dd.MM.yyyy`) and whether the locale uses a 12- or 24-hour clock (`HH:mm` / `hh:mm a`). UI labels and validation messages are **English** unless you supply translations. Because this relies on the runtime's `Intl`, names can differ slightly between engines; use a fixed locale object where you need exact output (the built-in `en-US` is static for that reason).
|
|
485
|
+
|
|
486
|
+
## Defining a locale
|
|
487
|
+
|
|
488
|
+
```ts
|
|
489
|
+
import { EN_LABELS, createLocale, provideMomentra } from '@momentra/angular';
|
|
490
|
+
|
|
491
|
+
export const PORTUGUESE = createLocale('pt-BR', {
|
|
492
|
+
firstDayOfWeek: 0,
|
|
493
|
+
labels: { ...EN_LABELS, today: 'Hoje', clear: 'Limpar', done: 'Concluir' },
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
provideMomentra({ locale: 'pt-BR', locales: [PORTUGUESE] });
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
`createLocale(code, overrides)` returns a complete `MomentraLocale`; you can also write the object by hand. Fields:
|
|
500
|
+
|
|
501
|
+
| Field | Description |
|
|
502
|
+
| --- | --- |
|
|
503
|
+
| `code` | BCP-47 tag |
|
|
504
|
+
| `monthNames`, `monthNamesShort` | 12 names, January first |
|
|
505
|
+
| `weekdayNames`, `weekdayNamesShort`, `weekdayNamesNarrow` | 7 names, **Sunday first** |
|
|
506
|
+
| `meridiem` | `{ am, pm }` |
|
|
507
|
+
| `firstDayOfWeek` | 0–6 |
|
|
508
|
+
| `dateFormat`, `timeFormat`, `dateTimeFormat` | default [patterns](date-adapters.md#format-patterns) |
|
|
509
|
+
| `monthYearFormat` | calendar header, default `MMMM yyyy` |
|
|
510
|
+
| `longDateFormat` | text announced for each day cell, e.g. `EEEE, MMMM d, yyyy` |
|
|
511
|
+
| `labels` | `MomentraLabels`: `today`, `clear`, `done`, `now`, `openCalendar`, `previousMonth`, `hours`, … |
|
|
512
|
+
| `validationMessages` | `MomentraValidationMessages` templates |
|
|
513
|
+
|
|
514
|
+
`ES_ES_LOCALE` (with Spanish labels and messages, Monday-first) is exported as a complete reference. With date-fns, `momentraLocaleFromDateFns(code, dateFnsLocale)` builds names and formats from a date-fns locale.
|
|
515
|
+
|
|
516
|
+
## Overriding formats and week start
|
|
517
|
+
|
|
518
|
+
Precedence (highest first): component input (`format`, `dateFormat`, `timeFormat`, `firstDayOfWeek`, `locale`) → global `provideMomentra` option → locale. A global or component `dateFormat` also feeds the date-time pattern (`<dateFormat> <timeFormat>`) unless `dateTimeFormat`/`format` is set explicitly.
|
|
519
|
+
|
|
520
|
+
```html
|
|
521
|
+
<mtr-date-picker format="dd 'de' MMMM 'de' yyyy" locale="es-ES" />
|
|
522
|
+
<mtr-datetime-picker dateFormat="yyyy-MM-dd" hourFormat="24" />
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
## Parsing
|
|
526
|
+
|
|
527
|
+
Parsing is **pattern-based and locale-aware**: month/weekday names are matched case-insensitively in the locale's language, numeric fields are range-checked, and the text must match the whole pattern. It does not try several formats or understand free text. To accept more than one format, listen to the text yourself or normalise before writing the value.
|
|
528
|
+
|
|
529
|
+
## Not covered
|
|
530
|
+
|
|
531
|
+
Right-to-left layout, non-Gregorian calendars, and non-Latin numerals in typed input (digits must be ASCII `0–9`; patterns derived from `Intl` use `latn` numerals).
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
<!-- source: docs/dates-and-time-zones.md -->
|
|
537
|
+
|
|
538
|
+
# Dates and time zones
|
|
539
|
+
|
|
540
|
+
A JavaScript `Date` is an **absolute instant** (milliseconds since the UTC epoch). It has no "date only" type, and its default serialization (`toISOString()`) converts to UTC. That is how a birthday of 15 March silently becomes 14 March for users west of Greenwich. Momentra makes the distinction explicit.
|
|
541
|
+
|
|
542
|
+
## Four kinds of value
|
|
543
|
+
|
|
544
|
+
| Kind | Example | Meaning | Momentra representation |
|
|
545
|
+
| --- | --- | --- | --- |
|
|
546
|
+
| `calendar-date` | birthday, due date | a day on the calendar, no time, no zone | `CalendarDate` (`{ year, month, day }`) or ISO `yyyy-MM-dd` |
|
|
547
|
+
| `local-datetime` | "appointment at 09:30" | wall-clock fields, interpreted in the viewer's/adapter's zone | `Date`/`DateTime` created from local fields |
|
|
548
|
+
| `instant` | "event happened at …" | a point in time | `Date.getTime()`, ISO string with offset |
|
|
549
|
+
| `zoned-datetime` | "09:30 in Madrid" | instant + IANA zone | Luxon `DateTime` via `LuxonDateAdapter({ zone })` |
|
|
550
|
+
|
|
551
|
+
The type `MomentraValueKind` and the functions in `core/models/calendar-date.ts` document and support this.
|
|
552
|
+
|
|
553
|
+
## How the components behave
|
|
554
|
+
|
|
555
|
+
- **Date-only controls** (`mtr-date-input`, `mtr-date-picker`, `mtr-calendar`, `mtr-month/year/decade-picker`, the range picker) emit the **local start of the selected day** — a `Date` at 00:00:00.000 in the local zone — and read only the local calendar fields (`getFullYear()`, `getMonth()`, `getDate()`). They never convert through UTC, so the selected day cannot shift because of a time-zone offset, in any zone (the test suite runs in eight zones, including +14:00 and −11:00).
|
|
556
|
+
- **Date-time controls** (`mtr-datetime-picker`, `mtr-time-picker`) emit **local date-time** values: the wall-clock fields you see are the fields of the value. `mtr-time-picker` keeps the date of the previous value (or `baseDate`, default today) and changes only the time of day.
|
|
557
|
+
- **Writing values in.** Controls accept adapter dates, epoch milliseconds and ISO strings. A **bare `yyyy-MM-dd` string is read as that calendar day** (local midnight), not as UTC midnight — `new Date('2026-03-15')` would be UTC midnight and would show 14 March in the Americas; Momentra does not do that. Impossible dates (`'2026-02-30'`) become `null`. Strings with a time and offset (`2026-03-15T10:00:00Z`) are instants and are converted to the local zone.
|
|
558
|
+
- **Comparisons.** `min`/`max` on date-only controls compare **whole days** (a `min` of 10 Nov 15:00 still allows any time on 10 Nov). `mtr-datetime-picker` compares exact date-times. `mtr-time-picker` compares time of day only.
|
|
559
|
+
- **Daylight saving time.** `addDays` keeps the wall-clock time (`Date#setDate`), and day differences are computed from calendar fields, so a "day" is always one calendar day even when it is 23 or 25 hours long. A wall-clock time that does not exist (the hour skipped at the start of DST) is shifted by the platform, as `Date` always does.
|
|
560
|
+
|
|
561
|
+
## Persisting calendar dates
|
|
562
|
+
|
|
563
|
+
Do **not** serialize a date-only `Date` with `toISOString()` or `JSON.stringify`, which convert to UTC:
|
|
564
|
+
|
|
565
|
+
```ts
|
|
566
|
+
import { formatIsoDate, parseIsoDate, type CalendarDate } from '@momentra/angular';
|
|
567
|
+
|
|
568
|
+
// out: Date (local midnight) → 'yyyy-MM-dd'
|
|
569
|
+
const day: CalendarDate = { year: d.getFullYear(), month: d.getMonth(), day: d.getDate() };
|
|
570
|
+
const text = formatIsoDate(day); // '2026-03-15'
|
|
571
|
+
|
|
572
|
+
// in: 'yyyy-MM-dd' → a control (or adapter.deserialize(text))
|
|
573
|
+
control.setValue(text as never); // controls accept ISO date strings
|
|
574
|
+
const parsed = parseIsoDate(text); // CalendarDate | null
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
(`CalendarDate.month` is zero-based, like `Date`.)
|
|
578
|
+
|
|
579
|
+
## Zone-aware workflows
|
|
580
|
+
|
|
581
|
+
Use `LuxonDateAdapter({ zone })` (see [Date adapters](date-adapters.md)). Calendar fields are then the fields in that zone regardless of the user's system zone, and `DateTime` values keep their zone. The native adapter always works in the system zone; Momentra does not emulate other zones on top of `Date`.
|
|
582
|
+
|
|
583
|
+
## Testing across zones
|
|
584
|
+
|
|
585
|
+
```bash
|
|
586
|
+
npm run test:tz # eight zones
|
|
587
|
+
npm run test:tz -- UTC Asia/Tokyo # chosen zones
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
`core/adapters/timezone.spec.ts` sweeps two years of days for DST-safe stepping, every month's calendar weeks, and ISO round-trips; the adapter contract suite runs for Luxon in UTC and `Pacific/Auckland`.
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
<!-- source: docs/date-adapters.md -->
|
|
596
|
+
|
|
597
|
+
# Date adapters
|
|
598
|
+
|
|
599
|
+
Momentra never touches a concrete date type. Every component injects `MOMENTRA_DATE_ADAPTER` (a `DateAdapter<TDate>`) and the value type of the controls is that adapter's `TDate`.
|
|
600
|
+
|
|
601
|
+
| Adapter | Import | `TDate` | Notes |
|
|
602
|
+
| --- | --- | --- | --- |
|
|
603
|
+
| `NativeDateAdapter` | `@momentra/angular` | `Date` | **Default.** Local time zone. |
|
|
604
|
+
| `DateFnsDateAdapter` | `@momentra/angular/date-fns` | `Date` | Arithmetic, boundaries and comparisons via date-fns; strings parsed with `parseISO`. Requires `date-fns@^4`. |
|
|
605
|
+
| `LuxonDateAdapter` | `@momentra/angular/luxon` | `DateTime` | Optional fixed IANA zone. Requires `luxon@^3`. |
|
|
606
|
+
|
|
607
|
+
`date-fns` and `luxon` are *optional peer dependencies*: you only need them if you import those entry points.
|
|
608
|
+
|
|
609
|
+
## Choosing an adapter
|
|
610
|
+
|
|
611
|
+
```ts
|
|
612
|
+
// native Date (default): nothing to configure
|
|
613
|
+
provideMomentra({ locale: 'en-US' });
|
|
614
|
+
|
|
615
|
+
// date-fns
|
|
616
|
+
import { provideMomentraDateFns } from '@momentra/angular/date-fns';
|
|
617
|
+
provideMomentraDateFns({ locale: 'en-GB' });
|
|
618
|
+
|
|
619
|
+
// Luxon, in a fixed zone
|
|
620
|
+
import { provideMomentraLuxon } from '@momentra/angular/luxon';
|
|
621
|
+
provideMomentraLuxon({ locale: 'es-ES' }, { zone: 'Europe/Madrid' });
|
|
622
|
+
|
|
623
|
+
// any adapter class
|
|
624
|
+
provideMomentra({ dateAdapter: MyAdapter });
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
Components are generic over the date type (`DatePickerComponent<TDate = Date>`), so with Luxon `FormControl<DateTime | null>` type-checks (see `examples/luxon-adapter.ts`).
|
|
628
|
+
|
|
629
|
+
### date-fns locales
|
|
630
|
+
|
|
631
|
+
```ts
|
|
632
|
+
import { momentraLocaleFromDateFns, provideMomentraDateFns } from '@momentra/angular/date-fns';
|
|
633
|
+
import { fr } from 'date-fns/locale';
|
|
634
|
+
|
|
635
|
+
const french = momentraLocaleFromDateFns('fr-FR', fr);
|
|
636
|
+
provideMomentraDateFns({ locale: french, locales: [french] });
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
`momentraLocaleFromDateFns` takes month/weekday names, the first day of the week and the short date/time formats from the date-fns locale; UI strings stay English unless you pass `labels` in the third argument.
|
|
640
|
+
|
|
641
|
+
### Luxon zones
|
|
642
|
+
|
|
643
|
+
With `{ zone }`, dates are created and read in that zone: the calendar shows the *zone's* calendar fields whatever the user's system zone is, a bare ISO date (`'2026-03-15'`) is that day in the zone, and instants (`Date`, epoch milliseconds, ISO strings with offsets) are converted into the zone when written to a control. Without `zone`, the system zone is used.
|
|
644
|
+
|
|
645
|
+
## The adapter API
|
|
646
|
+
|
|
647
|
+
Months are **zero-based** (0 = January) and weekdays are 0 = Sunday … 6 = Saturday, like `Date`. Adapter values are treated as immutable.
|
|
648
|
+
|
|
649
|
+
| Group | Members |
|
|
650
|
+
| --- | --- |
|
|
651
|
+
| Creation | `now()`, `today()`, `create(y, m, d, h?, mi?, s?, ms?)`, `clone`, `invalid()`, `isValid`, `deserialize(value)` |
|
|
652
|
+
| Reading | `getYear`, `getMonth`, `getDate`, `getDayOfWeek`, `getHours`, `getMinutes`, `getSeconds`, `getMilliseconds`, `toTimestamp`, `toParts` |
|
|
653
|
+
| Arithmetic | `addDays`/`subtractDays`, `addMonths`/`subtractMonths`, `addYears`/`subtractYears` |
|
|
654
|
+
| Comparison | `compare`, `isEqual`, `isSameDay`, `isSameMonth`, `isSameYear`, `isBefore`, `isAfter`, `isBetween`, `clamp`, `differenceInDays` |
|
|
655
|
+
| Boundaries | `startOfDay`, `endOfDay`, `startOfMonth`, `endOfMonth`, `startOfYear`, `endOfYear`, `startOfWeek`, `endOfWeek` |
|
|
656
|
+
| Calendar | `getDaysInMonth`, `getFirstDayOfMonth`, `getLastDayOfMonth`, `getFirstDayOfWeek`, `getCalendarWeeks(date, firstDayOfWeek, fixedWeeks?)` |
|
|
657
|
+
| Time | `setHours`, `setMinutes`, `setSeconds`, `withTime`, `combine(day, time)`, `secondsOfDay` |
|
|
658
|
+
| Formatting | `format(date, pattern, locale)`, `formatDate`, `formatTime`, `formatDateTime`, `formatMonthYear`, `formatWeekday` |
|
|
659
|
+
| Parsing | `parse(text, pattern, locale, base?)` |
|
|
660
|
+
|
|
661
|
+
Semantics worth knowing:
|
|
662
|
+
|
|
663
|
+
- `create` **never rolls over**: `create(2026, 1, 30)` (30 February) or hour 24 returns an *invalid* date (`isValid` is `false`).
|
|
664
|
+
- `addMonths`/`addYears` **clamp**: 31 Jan + 1 month = 28/29 Feb.
|
|
665
|
+
- `deserialize` interprets a bare `yyyy-MM-dd` string as that **calendar day in the adapter's zone**, never as a UTC instant, and returns `null` for impossible dates such as `2026-02-30`.
|
|
666
|
+
- `parse` is strict: the text must match the pattern entirely, fields must be in range, and the date must exist. Missing date fields come from `base` (today if omitted); missing time fields are zero.
|
|
667
|
+
|
|
668
|
+
### Format patterns
|
|
669
|
+
|
|
670
|
+
Patterns are the same for every adapter and use date-fns-style letters:
|
|
671
|
+
|
|
672
|
+
| Token | Meaning | Example |
|
|
673
|
+
| --- | --- | --- |
|
|
674
|
+
| `yyyy`, `yy`, `y` | year | `2026`, `26`, `2026` |
|
|
675
|
+
| `MMMM`, `MMM`, `MM`, `M` | month (name, short name, padded, plain) | `November`, `Nov`, `11`, `11` |
|
|
676
|
+
| `dd`, `d` | day of month | `05`, `5` |
|
|
677
|
+
| `EEEE`, `EEE` | weekday (formatting and parsing) | `Monday`, `Mon` |
|
|
678
|
+
| `HH`, `H` | hour, 24-hour | `15` |
|
|
679
|
+
| `hh`, `h` | hour, 12-hour | `03` |
|
|
680
|
+
| `mm`, `m`, `ss`, `s`, `SSS` | minutes, seconds, milliseconds | `05` |
|
|
681
|
+
| `a` | AM/PM (locale's `meridiem`) | `PM` |
|
|
682
|
+
| `'text'` | literal (`''` is a quote) | `'at'` |
|
|
683
|
+
|
|
684
|
+
Other letters throw a `MomentraPatternError`. When parsing, `yyyy` requires four digits, `yy` expands with a 70-year pivot (`70`–`99` → 19xx, `00`–`69` → 20xx), single-letter numeric tokens accept one or two digits, and adjacent numeric tokens (`yyyyMMdd`) use fixed widths.
|
|
685
|
+
|
|
686
|
+
## Writing your own adapter
|
|
687
|
+
|
|
688
|
+
Extend `DateAdapter<TDate>` and implement the abstract members:
|
|
689
|
+
|
|
690
|
+
```ts
|
|
691
|
+
import { DateAdapter } from '@momentra/angular';
|
|
692
|
+
|
|
693
|
+
export class MyAdapter extends DateAdapter<MyDate> {
|
|
694
|
+
now() { … }
|
|
695
|
+
create(year, month, day, hours = 0, minutes = 0, seconds = 0, milliseconds = 0) { … } // invalid when out of range
|
|
696
|
+
clone(date) { … }
|
|
697
|
+
invalid() { … }
|
|
698
|
+
isValid(date): date is MyDate { … }
|
|
699
|
+
deserialize(value: unknown) { … }
|
|
700
|
+
getYear(date) { … } getMonth(date) { … } getDate(date) { … } getDayOfWeek(date) { … }
|
|
701
|
+
getHours(date) { … } getMinutes(date) { … } getSeconds(date) { … } getMilliseconds(date) { … }
|
|
702
|
+
toTimestamp(date) { … }
|
|
703
|
+
addDays(date, amount) { … }
|
|
704
|
+
}
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
Override derived methods only where your library does them better (as `DateFnsDateAdapter` does for boundaries). To prove compatibility, run the shared contract against it in your own tests — it is `describeAdapterContract(name, () => new MyAdapter())` in `projects/momentra/src/lib/testing/adapter-contract.ts` (it is not part of the published package; copy it into your tests).
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
---
|
|
711
|
+
|
|
712
|
+
<!-- source: docs/validation.md -->
|
|
713
|
+
|
|
714
|
+
# Validation
|
|
715
|
+
|
|
716
|
+
Validation has three layers that share one set of rules (`core/validators/validation.ts`):
|
|
717
|
+
|
|
718
|
+
1. **Pure rules** — `validateDate`, `validateTime`, `validateRange`: `(adapter, value, rules) => ValidationErrors | null`. No Angular, no UI.
|
|
719
|
+
2. **Angular validators** — `MomentraValidators.*` wrap the rules as `ValidatorFn`s for your own `FormControl`s.
|
|
720
|
+
3. **Built-in component validation** — every control validates itself with the same rules (from `min`, `max`, `disabledDates`, `minRangeLength`, `required`, …) and *also* acts as an Angular `Validator`, so the errors appear on the `FormControl` (`control.errors`, `control.invalid`) without you adding anything.
|
|
721
|
+
|
|
722
|
+
## Error keys
|
|
723
|
+
|
|
724
|
+
| Key | Payload | Raised when |
|
|
725
|
+
| --- | --- | --- |
|
|
726
|
+
| `required` | `true` | Empty and `required` (or `Validators.required` / `MomentraValidators.required`). |
|
|
727
|
+
| `mtrInvalidDate` | `{ value }` | Text cannot be parsed, the date does not exist (30 Feb), or the value is an invalid date object. |
|
|
728
|
+
| `mtrMinDate` | `{ min, actual }` | Before `min` (whole days; exact for the date-time picker). |
|
|
729
|
+
| `mtrMaxDate` | `{ max, actual }` | After `max`. |
|
|
730
|
+
| `mtrDisabledDate` | `{ actual }` | The date is excluded by `disabledDates`. |
|
|
731
|
+
| `mtrInvalidTime` | `{ value }` | Unparsable or invalid time. |
|
|
732
|
+
| `mtrMinTime` | `{ min, actual }` | Time of day before `min`'s time of day. |
|
|
733
|
+
| `mtrMaxTime` | `{ max, actual }` | Time of day after `max`'s time of day. |
|
|
734
|
+
| `mtrRangeIncomplete` | `{ start, end }` | Exactly one end of a range is set. |
|
|
735
|
+
| `mtrRangeOrder` | `{ start, end }` | `end` is before `start`. |
|
|
736
|
+
| `mtrMinRangeLength` | `{ min, actual }` | Range spans fewer than `min` days (inclusive count). |
|
|
737
|
+
| `mtrMaxRangeLength` | `{ max, actual }` | Range spans more than `max` days. |
|
|
738
|
+
|
|
739
|
+
An empty value is valid unless `required`.
|
|
740
|
+
|
|
741
|
+
## Using the validators
|
|
742
|
+
|
|
743
|
+
```ts
|
|
744
|
+
import { MomentraValidators } from '@momentra/angular';
|
|
745
|
+
|
|
746
|
+
new FormControl<Date | null>(null, [
|
|
747
|
+
MomentraValidators.required(),
|
|
748
|
+
MomentraValidators.minDate(() => new Date()), // bound may be a value or a function evaluated on each validation
|
|
749
|
+
MomentraValidators.disabledDates((d) => d.getDay() === 0),
|
|
750
|
+
]);
|
|
751
|
+
|
|
752
|
+
new FormControl<DateRange<Date> | null>(null, [
|
|
753
|
+
MomentraValidators.dateRange({ required: true, minLength: 2, maxLength: 14 }),
|
|
754
|
+
]);
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
Available: `required`, `validDate`, `minDate`, `maxDate`, `disabledDates`, `validTime`, `minTime`, `maxTime`, `dateRange`, `minRangeLength`, `maxRangeLength`. Each accepts a `DateAdapter` as its last argument for non-native dates (`MomentraValidators.minDate(min, new LuxonDateAdapter())`); the default is the native adapter. Each returns only *its own* error key, so they compose.
|
|
758
|
+
|
|
759
|
+
## Messages
|
|
760
|
+
|
|
761
|
+
Components show messages below the field, in a `role="alert"` region referenced by `aria-describedby`, **after the control was touched** and when `showErrors` is true. Messages come from the active locale's `validationMessages` with these precedence rules: component `errorMessages` → global `validationMessages` → locale.
|
|
762
|
+
|
|
763
|
+
Templates are strings with `{placeholder}`s filled from the error payload; dates are formatted with the control's pattern:
|
|
764
|
+
|
|
765
|
+
```html
|
|
766
|
+
<mtr-date-picker [min]="today" [errorMessages]="{ mtrMinDate: 'Pick {min} or later.' }" />
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
```ts
|
|
770
|
+
provideMomentra({ validationMessages: { required: 'Please choose a date.' } });
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
To build your own message UI, use `getErrorMessages(errors, templates, formatValue)`.
|
|
774
|
+
|
|
775
|
+
## Notes and limits
|
|
776
|
+
|
|
777
|
+
- The component displays messages for **its own** rules. A validator you attach only to the `FormControl` (for example `Validators.required` without the `required` input) still invalidates the control but its message is not displayed by the component; show it in your template from `control.errors`.
|
|
778
|
+
- Typing something unparsable emits `null` to the form *and* sets `mtrInvalidDate`; the user's text stays in the input until they fix or clear it.
|
|
779
|
+
- Rules re-run when `min`, `max`, `disabledDates`, range lengths or `required` change.
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
---
|
|
783
|
+
|
|
784
|
+
<!-- source: docs/accessibility.md -->
|
|
785
|
+
|
|
786
|
+
# Accessibility
|
|
787
|
+
|
|
788
|
+
Accessibility is built into the components rather than added on top. This page lists what is implemented and what has and has not been verified.
|
|
789
|
+
|
|
790
|
+
## Verification status
|
|
791
|
+
|
|
792
|
+
- **Automated**: the test suite runs [axe-core](https://github.com/dequelabs/axe-core) over every component at rest, with validation errors, with each popup open, and in the month/year/decade views, and asserts keyboard and focus behaviour (`projects/momentra/src/lib/testing/a11y.spec.ts` and the per-component specs). axe found and we fixed one real problem during development (`role="alert"` on a list).
|
|
793
|
+
- **Contrast of the default palette**: `npm run check:contrast` computes WCAG 2.x ratios for the default light and dark colour pairs (text ≥ 4.5:1, input borders, focus ring and today ring ≥ 3:1). All pass; the script found three failures during development (input borders in both themes, the active preset in dark) that were fixed. This checks the *token values*, not rendered pixels, and custom palettes are yours to check.
|
|
794
|
+
- **Not verified**: axe's `color-contrast` rule is disabled in the tests (jsdom has no rendering), and **no testing with real screen readers** (NVDA, JAWS, VoiceOver, TalkBack) or in real browsers has been done yet. Treat the markup as following the WAI-ARIA Authoring Practices patterns, not as certified.
|
|
795
|
+
|
|
796
|
+
## Labelling
|
|
797
|
+
|
|
798
|
+
Every control needs an accessible name. Use one of:
|
|
799
|
+
|
|
800
|
+
```html
|
|
801
|
+
<label for="due">Due date</label>
|
|
802
|
+
<mtr-date-picker inputId="due" />
|
|
803
|
+
|
|
804
|
+
<mtr-date-picker ariaLabel="Due date" />
|
|
805
|
+
<mtr-date-picker ariaLabelledby="heading-id" />
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
The range picker exposes a `group` named "Date range" (or your `ariaLabel`) containing inputs named "Start date" and "End date" (localized).
|
|
809
|
+
|
|
810
|
+
## Patterns used
|
|
811
|
+
|
|
812
|
+
| Piece | Semantics |
|
|
813
|
+
| --- | --- |
|
|
814
|
+
| Text input of a picker | `role="combobox"`, `aria-haspopup="dialog"`, `aria-expanded`, `aria-controls` (only while open), `aria-autocomplete="none"`, `aria-invalid`, `aria-describedby` → error region |
|
|
815
|
+
| Toggle button | `<button>` with a localized label, `aria-haspopup`, `aria-expanded`, `aria-controls` |
|
|
816
|
+
| Popup | `role="dialog"`, `aria-modal="true"`, labelled; `cdkTrapFocus` keeps Tab inside |
|
|
817
|
+
| Calendar grid | `<table role="grid">` named by its title; `<th scope="col" abbr>` weekday headers with the full name as label; `role="gridcell"` with `aria-selected`; each day is a `<button>` with a full-date label ("Monday, November 23, 2026"), `aria-current="date"` for today, `aria-disabled` for unavailable days |
|
|
818
|
+
| Calendar header | Previous/next buttons with specific labels ("Previous month", "Next decade", …); the title is a button announcing the view change (`aria-live="polite"`) |
|
|
819
|
+
| Time lists | `role="listbox"` per column (named Hours, Minutes, …) with `role="option"`, `aria-selected`, `aria-disabled`; roving `tabindex` |
|
|
820
|
+
| Validation messages | `role="alert"` region linked with `aria-describedby`, shown after the control is touched |
|
|
821
|
+
| Range hint | `aria-live="polite"` region announcing "Select the end date" |
|
|
822
|
+
|
|
823
|
+
## Keyboard
|
|
824
|
+
|
|
825
|
+
| Where | Keys |
|
|
826
|
+
| --- | --- |
|
|
827
|
+
| Field | `Alt+↓` opens the popup · `Esc` closes it · `↑`/`↓` step the value · `Enter` normalizes the text · `Tab` moves on |
|
|
828
|
+
| Calendar | `←` `→` previous/next day · `↑` `↓` previous/next week · `PageUp`/`PageDown` previous/next month (`Shift`: year) · `Home`/`End` start/end of the week · `Enter`/`Space` select · `Ctrl+↑` coarser view |
|
|
829
|
+
| Month / year / decade views | arrows move by 1 and by a row, `PageUp`/`PageDown` by the next unit, `Home`/`End` start/end of the period |
|
|
830
|
+
| Time lists | `↑` `↓` change and select · `Home`/`End` first/last · `←` `→` between lists · `Tab` leaves the lists |
|
|
831
|
+
| Popup | `Esc` closes and returns focus to the input; `Tab`/`Shift+Tab` cycle inside |
|
|
832
|
+
|
|
833
|
+
## Focus management
|
|
834
|
+
|
|
835
|
+
- Opening the popup moves focus to the active day (or the first time list); the calendar has exactly one tab stop.
|
|
836
|
+
- Closing with `Esc` or after a selection returns focus to the input.
|
|
837
|
+
- Closing by clicking elsewhere does **not** move focus back (the user chose to go elsewhere).
|
|
838
|
+
- The control is marked touched when the popup closes or the field blurs without a popup open, so focus moving *into* the popup does not trigger validation messages.
|
|
839
|
+
- Focus rings use `:focus-visible` with a configurable colour and a forced-colors fallback.
|
|
840
|
+
|
|
841
|
+
## Known gaps
|
|
842
|
+
|
|
843
|
+
No screen-reader testing; rendered contrast not verified; no right-to-left support; the calendar does not announce selection changes beyond the native button semantics and the grid's `aria-selected`; the AM/PM and hour lists are `listbox`es whose selection follows focus, which some screen readers announce verbosely.
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
---
|
|
847
|
+
|
|
848
|
+
<!-- source: docs/architecture.md -->
|
|
849
|
+
|
|
850
|
+
# Architecture
|
|
851
|
+
|
|
852
|
+
Momentra separates **what a date is and how it behaves** (the core) from **how it is presented** (Angular components).
|
|
853
|
+
|
|
854
|
+
```text
|
|
855
|
+
projects/momentra/src/lib/
|
|
856
|
+
├── core/
|
|
857
|
+
│ ├── adapters/ DateAdapter<TDate> (abstract) and NativeDateAdapter
|
|
858
|
+
│ ├── models/ CalendarDate, DateRange, value-kind documentation
|
|
859
|
+
│ ├── config/ MomentraConfig, provideMomentra()
|
|
860
|
+
│ ├── tokens/ MOMENTRA_CONFIG, MOMENTRA_DATE_ADAPTER, MOMENTRA_LOCALES
|
|
861
|
+
│ ├── services/ MomentraSettings (resolved config + locale lookup)
|
|
862
|
+
│ ├── validators/ validation rules (pure) + MomentraValidators (Angular ValidatorFn)
|
|
863
|
+
│ ├── utils/ calendar-engine, time-engine, range-utils, disabled-dates (pure, no Angular)
|
|
864
|
+
│ └── forms/ MomentraFormControl: ControlValueAccessor + Validator plumbing
|
|
865
|
+
├── formatting/ format-pattern: the pattern formatter/parser shared by all adapters
|
|
866
|
+
├── localization/ MomentraLocale, EN/ES locales, createLocale()
|
|
867
|
+
├── theming/ design tokens (SCSS), MtrThemeDirective
|
|
868
|
+
├── calendar/ CalendarComponent, MonthPicker, YearPicker, DecadePicker
|
|
869
|
+
├── inputs/ DateInput, DatePicker, TimePicker, DateTimePicker + shared building blocks
|
|
870
|
+
└── ranges/ DateRangePicker
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
`projects/momentra/date-fns` and `projects/momentra/luxon` are secondary entry points. They import the primary package; the primary package never imports them, so `date-fns` and `luxon` stay optional.
|
|
874
|
+
|
|
875
|
+
## Layers and dependency direction
|
|
876
|
+
|
|
877
|
+
```text
|
|
878
|
+
components → core/forms, core/utils, core/validators → core/adapters → formatting, localization
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
- **Pure core.** `calendar-engine`, `time-engine`, `range-utils`, `validation` and `format-pattern` do not import Angular (validation imports only the *type* `ValidationErrors`). They are tested without a `TestBed`.
|
|
882
|
+
- **No date logic in components.** Components never call `Date` methods. Every operation goes through the injected `DateAdapter`.
|
|
883
|
+
- **No circular dependencies.** Types flow downward; `tokens.ts` imports configuration *types* only.
|
|
884
|
+
|
|
885
|
+
## The date adapter
|
|
886
|
+
|
|
887
|
+
`DateAdapter<TDate>` is an abstract class with a **small set of primitives** (create, read fields, `addDays`, `toTimestamp`, `deserialize`, validity) and a large set of **derived operations** implemented once on top of them: month/year arithmetic with clamping, comparisons, boundaries, calendar weeks, time setters, and — importantly — **formatting and parsing**. Because formatting/parsing live in the base class (`formatting/format-pattern.ts`), the three adapters produce identical text and accept identical input. Adapter authors implement ~20 primitives; see [Date adapters](date-adapters.md).
|
|
888
|
+
|
|
889
|
+
A shared contract suite (`testing/adapter-contract.ts`) runs against every adapter, which is how adapters are kept behaviourally identical.
|
|
890
|
+
|
|
891
|
+
## Calendar engine
|
|
892
|
+
|
|
893
|
+
`calendar-engine.ts` turns *(adapter, locale, rules, selected/active/range)* into a plain view model:
|
|
894
|
+
|
|
895
|
+
- `buildDayView`, `buildMonthView`, `buildYearView`, `buildDecadeView` → rows of `CalendarCell`s (`selected`, `active`, `today`, `outside`, `disabled`, `inRange`, `rangeStart`, `rangeEnd`, labels).
|
|
896
|
+
- `moveFocus` maps a navigation key to the next date for each view; `shiftView` pages; `drillUpView`/`drillDownView` change granularity.
|
|
897
|
+
|
|
898
|
+
`CalendarComponent` is a thin shell around this: it holds the active date and view as signals, renders the view model, and handles input events. The month, year and decade pickers are `CalendarComponent` locked to a `selectionView`, so all four share one implementation. The range picker feeds the calendar a highlighted range and reacts to its `dateSelect` and `dateHover` outputs.
|
|
899
|
+
|
|
900
|
+
## Forms integration
|
|
901
|
+
|
|
902
|
+
`MomentraFormControl<TDate, TValue>` (an abstract `@Directive()`) is the single implementation of:
|
|
903
|
+
|
|
904
|
+
- `ControlValueAccessor` (`writeValue`, `registerOnChange/Touched`, `setDisabledState`),
|
|
905
|
+
- `Validator` (including re-validation when rule inputs such as `min` change),
|
|
906
|
+
- the shared inputs (`disabled`, `readonly`, `required`, `locale`, `firstDayOfWeek`, `errorMessages`, `showErrors`, `ariaLabel`, `ariaLabelledby`, `inputId`) and visible error messages.
|
|
907
|
+
|
|
908
|
+
On top of it, `MomentraTextControl` adds text ⇄ value synchronisation, and `MomentraPopupControl` adds the overlay popup. Components register themselves with `provideMomentraControl(() => Component)`, which provides both `NG_VALUE_ACCESSOR` and `NG_VALIDATORS`.
|
|
909
|
+
|
|
910
|
+
Decision: the components **provide validators themselves** rather than injecting `NgControl`. Injecting `NgControl` into a value accessor is circular with `NG_VALIDATORS`; providing the validator avoids it, and means validation works identically for `formControl`, `formControlName` and `ngModel`. The trade-off is that a component cannot see validators attached to the *control* (for example `Validators.required` on the `FormControl`) when deciding whether to display an error message; it shows messages for its own rules (`required` input, `min`, `max`, …). Use the `required` input when you want the message displayed.
|
|
911
|
+
|
|
912
|
+
## Configuration and state
|
|
913
|
+
|
|
914
|
+
`provideMomentra()` returns `EnvironmentProviders` with a frozen config object. `MomentraSettings` resolves it, and resolves locales (registered → built-in → `Intl`-derived). Components override any setting through inputs (`locale`, `format`, `firstDayOfWeek`, `theme`, …). All reactive state inside components is signals; there are no module-level mutable singletons (the only module-level state is a monotonically increasing id counter and a pattern-tokenizer cache).
|
|
915
|
+
|
|
916
|
+
## Popups
|
|
917
|
+
|
|
918
|
+
Popups use the Angular CDK `CdkConnectedOverlay`, anchored to the field (`<mtr-field>`), with four fallback positions and viewport push. Focus management is explicit: focus moves into the popup (the active day or the first list) when it attaches, `CdkTrapFocus` keeps Tab inside, and Escape or a selection closes it and returns focus to the input. An outside click closes it *without* stealing focus.
|
|
919
|
+
|
|
920
|
+
## Styling
|
|
921
|
+
|
|
922
|
+
Each component has its own SCSS (view encapsulation). Design tokens live in `theming/_tokens.scss` as `--_mtr-*` private custom properties that fall back from public `--mtr-*` properties, with separate light and dark defaults. See [Styling and themes](styling-and-themes.md).
|
|
923
|
+
|
|
924
|
+
## Extension points
|
|
925
|
+
|
|
926
|
+
Implemented hooks that future features build on:
|
|
927
|
+
|
|
928
|
+
| Future feature | Hook that exists today |
|
|
929
|
+
| --- | --- |
|
|
930
|
+
| Other calendar systems, timezone-aware workflows | `DateAdapter<TDate>` is generic over the date type; `LuxonDateAdapter({ zone })` is zone-aware |
|
|
931
|
+
| Holiday calendars, date exclusions, business-day restrictions | `disabledDates` (predicate or list) on every date control; `isDisabled` in the validation rules |
|
|
932
|
+
| Custom date templates | `cellTemplate` input on the calendar and pickers (context: `MtrCellContext`) |
|
|
933
|
+
| Presets / shortcuts | `presets` on the range picker, `createPreset`, `lastDaysRange`, … |
|
|
934
|
+
| Custom restrictions | custom `ValidatorFn`s compose with the built-in ones |
|
|
935
|
+
| Custom locale / formatting | `MomentraLocale` objects, `createLocale()`, per-component `format` |
|
|
936
|
+
|
|
937
|
+
**Not implemented:** fiscal calendars, built-in holiday data, week selection, multiple-date selection, recurring selections, business-day arithmetic and custom calendar headers. Adding them would mostly mean new view builders in `calendar-engine.ts` and a new selection model, without changing the adapter or the forms plumbing.
|