@nanahoshi/mona-ui 0.31.0 → 0.32.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/date-range-picker/package.json +4 -0
- package/docs/api/calendar.md +3 -2
- package/docs/api/common.md +1 -1
- package/docs/api/date-input.md +1 -1
- package/docs/api/date-range-picker.md +137 -0
- package/docs/api/i18n.md +53 -0
- package/docs/api/list.md +1 -1
- package/docs/api/locales.md +14 -14
- package/docs/api/popup.md +1 -1
- package/docs/calendar.md +47 -3
- package/docs/date-picker.md +1 -1
- package/docs/date-range-picker.md +420 -0
- package/docs/forms.md +1 -0
- package/docs/label.md +1 -0
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +171 -59
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-date-range-picker.mjs +1331 -0
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-i18n.mjs +7 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +23 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +21 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +21 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +16 -0
- package/i18n/catalogs/en-US.messages.json +16 -0
- package/llms.txt +3 -1
- package/locales/ar-sa/ar-sa.messages.json +16 -0
- package/locales/de-de/de-de.messages.json +16 -0
- package/locales/es-es/es-es.messages.json +16 -0
- package/locales/fr-fr/fr-fr.messages.json +16 -0
- package/locales/id-id/id-id.messages.json +16 -0
- package/locales/it-it/it-it.messages.json +16 -0
- package/locales/ja-jp/ja-jp.messages.json +16 -0
- package/locales/ko-kr/ko-kr.messages.json +16 -0
- package/locales/pl-pl/pl-pl.messages.json +16 -0
- package/locales/pt-br/pt-br.messages.json +16 -0
- package/locales/ru-ru/ru-ru.messages.json +16 -0
- package/locales/tr-tr/tr-tr.messages.json +16 -0
- package/locales/zh-cn/zh-cn.messages.json +16 -0
- package/locales/zh-tw/zh-tw.messages.json +16 -0
- package/package.json +5 -1
- package/types/nanahoshi-mona-ui-calendar.d.ts +66 -8
- package/types/nanahoshi-mona-ui-date-range-picker.d.ts +462 -0
- package/types/nanahoshi-mona-ui-i18n.d.ts +39 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +16 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +16 -0
package/docs/api/popup.md
CHANGED
|
@@ -123,7 +123,7 @@ Class.
|
|
|
123
123
|
| `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
|
|
124
124
|
| `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
|
|
125
125
|
|
|
126
|
-
**Used by:** [`AutoCompleteComponent`](auto-complete.md#autocompletecomponent), [`ComboBoxComponent`](combo-box.md#comboboxcomponent), [`DatePickerComponent`](date-picker.md#datepickercomponent), [`DateTimePickerComponent`](datetime-picker.md#datetimepickercomponent), [`DialogComponent`](dialog.md#dialogcomponent), [`DialogRef`](dialog.md#dialogref), [`DropdownListComponent`](dropdown-list.md#dropdownlistcomponent), [`MultiSelectComponent`](multi-select.md#multiselectcomponent), [`PopupComponent`](popup.md#popupcomponent), [`PopupRef`](popup.md#popupref), [`PopupSettings`](popup.md#popupsettings), [`SheetComponent`](sheet.md#sheetcomponent), [`TimePickerComponent`](time-picker.md#timepickercomponent), [`WindowComponent`](window.md#windowcomponent), [`WindowRef`](window.md#windowref), [`WindowSettings`](window.md#windowsettings)
|
|
126
|
+
**Used by:** [`AutoCompleteComponent`](auto-complete.md#autocompletecomponent), [`ComboBoxComponent`](combo-box.md#comboboxcomponent), [`DatePickerComponent`](date-picker.md#datepickercomponent), [`DateRangePickerComponent`](date-range-picker.md#daterangepickercomponent), [`DateTimePickerComponent`](datetime-picker.md#datetimepickercomponent), [`DialogComponent`](dialog.md#dialogcomponent), [`DialogRef`](dialog.md#dialogref), [`DropdownListComponent`](dropdown-list.md#dropdownlistcomponent), [`MultiSelectComponent`](multi-select.md#multiselectcomponent), [`PopupComponent`](popup.md#popupcomponent), [`PopupRef`](popup.md#popupref), [`PopupSettings`](popup.md#popupsettings), [`SheetComponent`](sheet.md#sheetcomponent), [`TimePickerComponent`](time-picker.md#timepickercomponent), [`WindowComponent`](window.md#windowcomponent), [`WindowRef`](window.md#windowref), [`WindowSettings`](window.md#windowsettings)
|
|
127
127
|
|
|
128
128
|
## `defaultPopupAnimation`
|
|
129
129
|
|
package/docs/calendar.md
CHANGED
|
@@ -142,7 +142,9 @@ All selected dates are emitted as a flat `Date[]`.
|
|
|
142
142
|
|
|
143
143
|
### Range selection
|
|
144
144
|
|
|
145
|
-
Click the start date, then click the end date. The emitted `value` is always `[startDate, endDate]` — a `Date[]` with exactly two elements
|
|
145
|
+
Click the start date, then click the end date. The emitted `value` is always `[startDate, endDate]` — a `Date[]` with exactly two elements, in order whichever end was clicked first. The next click starts a new range.
|
|
146
|
+
|
|
147
|
+
The first and last days are drawn in the primary color, and the days between them in the selected tint. Each selected day has `data-range` set to `start`, `middle` or `end` for styling.
|
|
146
148
|
|
|
147
149
|
`range-example.component.ts`
|
|
148
150
|
|
|
@@ -180,6 +182,46 @@ export class CalendarRangeExampleComponent {
|
|
|
180
182
|
</div>
|
|
181
183
|
```
|
|
182
184
|
|
|
185
|
+
### Several months
|
|
186
|
+
|
|
187
|
+
`months` shows that many months side by side, here three for a quarter. They wrap onto new rows when the calendar is narrow. Each month has a caption, the days of the months around it are left blank so no date shows twice, and the previous and next buttons move the view by one month. The arrow keys move across the months, and the view moves on only past the last one.
|
|
188
|
+
|
|
189
|
+
`months-example.component.ts`
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { DatePipe } from "@angular/common";
|
|
193
|
+
import { Component, computed, signal } from "@angular/core";
|
|
194
|
+
import { CalendarComponent } from "@nanahoshi/mona-ui/calendar";
|
|
195
|
+
|
|
196
|
+
@Component({
|
|
197
|
+
selector: "app-calendar-months-example",
|
|
198
|
+
imports: [CalendarComponent, DatePipe],
|
|
199
|
+
templateUrl: "./months-example.component.html"
|
|
200
|
+
})
|
|
201
|
+
export class CalendarMonthsExampleComponent {
|
|
202
|
+
protected readonly ends = computed(() => {
|
|
203
|
+
const range = this.quarter();
|
|
204
|
+
return Array.isArray(range) && range.length === 2 ? range : null;
|
|
205
|
+
});
|
|
206
|
+
protected readonly quarter = signal<Date | Date[] | null>(null);
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`months-example.component.html`
|
|
211
|
+
|
|
212
|
+
```html
|
|
213
|
+
<div class="flex flex-col items-start gap-2">
|
|
214
|
+
<mona-calendar selection="range" [months]="3" [(value)]="quarter" />
|
|
215
|
+
<span aria-live="polite" class="text-sm">
|
|
216
|
+
@if (ends(); as ends) {
|
|
217
|
+
{{ ends[0] | date }} to {{ ends[1] | date }}
|
|
218
|
+
} @else {
|
|
219
|
+
Choose the first day, then the last.
|
|
220
|
+
}
|
|
221
|
+
</span>
|
|
222
|
+
</div>
|
|
223
|
+
```
|
|
224
|
+
|
|
183
225
|
### Date constraints
|
|
184
226
|
|
|
185
227
|
`minDate` and `maxDate` bound the dates that can be chosen. `disabledDates` takes a predicate, as here to skip weekends, or an array of specific dates.
|
|
@@ -279,7 +321,9 @@ It has no `ControlValueAccessor`, but `[(ngModel)]`, `[formControl]` and `formCo
|
|
|
279
321
|
|
|
280
322
|
**View navigation:** The calendar starts in the month view. Clicking the month/year header button cycles upward: month → year → decade. Clicking a cell in the year or decade view drills down.
|
|
281
323
|
|
|
282
|
-
**Range selection pending state:** After the first click in `selection="range"` mode, the calendar previews that date as the start. The range is committed only after the second click.
|
|
324
|
+
**Range selection pending state:** After the first click in `selection="range"` mode, the calendar previews that date as the start. The range is committed only after the second click. A value with one date, such as `[start]`, is a range's start in the same way: the next day picked ends it.
|
|
325
|
+
|
|
326
|
+
**Several months:** With `months` above 1, the calendar opens on the month of the last selected date, moved back to show the first one too when they fit. Picking a month in the year view puts it first.
|
|
283
327
|
|
|
284
328
|
**Disabled dates and navigation:** When `minDate` or `maxDate` changes so that the currently focused date falls outside the allowed range, the calendar automatically moves focus to the nearest bound.
|
|
285
329
|
|
|
@@ -305,7 +349,7 @@ The `touch` output fires each time the user completes a date selection. `FormFie
|
|
|
305
349
|
|
|
306
350
|
## Accessibility
|
|
307
351
|
|
|
308
|
-
Each view renders a `role="grid"` with rows of `role="gridcell"` cells, labelled by the heading above it. Day cells are named by their full date, and the month grid's column headers carry the full weekday name for screen readers. A polite live region announces the current view and position when it changes, such as "Calendar, June 2025" or "Year view, 2025".
|
|
352
|
+
Each view renders a `role="grid"` with rows of `role="gridcell"` cells, labelled by the heading above it. With several months, each month is a grid labelled by its own caption, and a blank cell stands in for each day of the months around it. Day cells are named by their full date, and the month grid's column headers carry the full weekday name for screen readers. A polite live region announces the current view and position when it changes, such as "Calendar, June 2025" or "Year view, 2025".
|
|
309
353
|
|
|
310
354
|
| Attribute | Where | Value |
|
|
311
355
|
|-----------------|------------------------------------------------|------------------------------------------|
|
package/docs/date-picker.md
CHANGED
|
@@ -12,7 +12,7 @@ Entry point: `@nanahoshi/mona-ui/date-picker`
|
|
|
12
12
|
|
|
13
13
|
Use `DatePickerComponent` for a single date in a form field, where users may type the date or pick it from a calendar. The calendar stays hidden until the user opens it.
|
|
14
14
|
|
|
15
|
-
Use `CalendarComponent`
|
|
15
|
+
Use `DateRangePickerComponent` when users pick a range of days, and `CalendarComponent` when the calendar should always be visible, or when users select several dates. Use `DateTimePickerComponent` when the value also needs a time of day, and `TimePickerComponent` when it is only a time.
|
|
16
16
|
|
|
17
17
|
## Import & Quick Start
|
|
18
18
|
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# Date Range Picker
|
|
2
|
+
|
|
3
|
+
> Two date inputs for a range of days, with a calendar popup that shows two months.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/date-range-picker`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-date-range-picker`
|
|
8
|
+
|
|
9
|
+
`DateRangePickerComponent` picks a range of days. It has an input for the first day and one for the last, typed in the locale's format, and a calendar popup that shows two months at a time.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Use `DateRangePickerComponent` for a span of days in a form, such as a stay, a leave request or a report's period. Users type the first and the last day, pick both from a calendar that shows two months side by side, or pick a quick range such as "Last 7 days".
|
|
14
|
+
|
|
15
|
+
Use `DatePickerComponent` for a single date. Use `CalendarComponent` with `selection="range"` when the calendar should stay visible on the page.
|
|
16
|
+
|
|
17
|
+
## Import & Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { type DateRange, DateRangePickerComponent } from "@nanahoshi/mona-ui/date-range-picker";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<mona-form-field label="Stay">
|
|
25
|
+
<mona-date-range-picker [(value)]="stay"></mona-date-range-picker>
|
|
26
|
+
</mona-form-field>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
protected readonly stay = signal<DateRange | null>(null);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The value is a `DateRange`, `{ start: Date | null; end: Date | null }`, or `null` when both ends are empty.
|
|
34
|
+
|
|
35
|
+
## Anatomy
|
|
36
|
+
|
|
37
|
+
The picker is one control with two inputs, a dash between them, and a calendar button at its end. The button opens a popup that holds a `mona-calendar` in range selection, and the quick ranges given to `presets` beside it.
|
|
38
|
+
|
|
39
|
+
| Template | Imported from | Fills |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `ng-template[monaCalendarMonthCellTemplate]` | `@nanahoshi/mona-ui/calendar` | Each day cell of the popup calendar |
|
|
42
|
+
| `ng-template[monaCalendarYearCellTemplate]` | `@nanahoshi/mona-ui/calendar` | Each month cell of the year view |
|
|
43
|
+
| `ng-template[monaCalendarDecadeCellTemplate]` | `@nanahoshi/mona-ui/calendar` | Each year cell of the decade view |
|
|
44
|
+
|
|
45
|
+
The cell templates receive the same context as on the [Calendar](calendar.md) page.
|
|
46
|
+
|
|
47
|
+
## Examples
|
|
48
|
+
|
|
49
|
+
### A range in a form field
|
|
50
|
+
|
|
51
|
+
The form field names the picker and describes both inputs with its hint. Pick the first day in the calendar, then the last: the range is written once both are picked, and the popup closes.
|
|
52
|
+
|
|
53
|
+
`basic-example.component.ts`
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Component, computed, signal } from "@angular/core";
|
|
57
|
+
import { type DateRange, DateRangePickerComponent } from "@nanahoshi/mona-ui/date-range-picker";
|
|
58
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
59
|
+
|
|
60
|
+
/** Whole days from one date to another, counted on the calendar so a change of clocks doesn't shift it. */
|
|
61
|
+
function daysBetween(start: Date, end: Date): number {
|
|
62
|
+
const day = (date: Date): number => Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
|
|
63
|
+
return Math.round((day(end) - day(start)) / 86_400_000);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Component({
|
|
67
|
+
selector: "app-date-range-picker-basic-example",
|
|
68
|
+
imports: [DateRangePickerComponent, FormFieldComponent],
|
|
69
|
+
templateUrl: "./basic-example.component.html"
|
|
70
|
+
})
|
|
71
|
+
export class DateRangePickerBasicExampleComponent {
|
|
72
|
+
protected readonly nights = computed(() => {
|
|
73
|
+
const stay = this.stay();
|
|
74
|
+
return stay?.start && stay.end ? daysBetween(stay.start, stay.end) : 0;
|
|
75
|
+
});
|
|
76
|
+
protected readonly stay = signal<DateRange | null>(null);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`basic-example.component.html`
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<div class="flex max-w-sm flex-col gap-2">
|
|
84
|
+
<mona-form-field label="Stay" hint="Pick the night you arrive, then the morning you leave.">
|
|
85
|
+
<mona-date-range-picker [(value)]="stay" />
|
|
86
|
+
</mona-form-field>
|
|
87
|
+
<span aria-live="polite" class="text-sm">
|
|
88
|
+
@if (nights(); as count) {
|
|
89
|
+
{{ count }} {{ count === 1 ? "night" : "nights" }}
|
|
90
|
+
} @else {
|
|
91
|
+
No dates yet.
|
|
92
|
+
}
|
|
93
|
+
</span>
|
|
94
|
+
</div>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Validation from a signal form
|
|
98
|
+
|
|
99
|
+
`required` checks for an empty range. A range with only one end isn't empty, so check both ends with `validate` when the form needs them. The form field shows the messages.
|
|
100
|
+
|
|
101
|
+
`signal-forms-example.component.ts`
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { Component, signal } from "@angular/core";
|
|
105
|
+
import { form, FormField, required, submit, validate } from "@angular/forms/signals";
|
|
106
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
107
|
+
import { type DateRange, DateRangePickerComponent } from "@nanahoshi/mona-ui/date-range-picker";
|
|
108
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
109
|
+
|
|
110
|
+
interface LeaveRequest {
|
|
111
|
+
leave: DateRange | null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Whole days from one date to another, counted on the calendar so a change of clocks doesn't shift it. */
|
|
115
|
+
function daysBetween(start: Date, end: Date): number {
|
|
116
|
+
const day = (date: Date): number => Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
|
|
117
|
+
return Math.round((day(end) - day(start)) / 86_400_000);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Component({
|
|
121
|
+
selector: "app-date-range-picker-signal-forms-example",
|
|
122
|
+
imports: [ButtonDirective, DateRangePickerComponent, FormField, FormFieldComponent],
|
|
123
|
+
templateUrl: "./signal-forms-example.component.html"
|
|
124
|
+
})
|
|
125
|
+
export class DateRangePickerSignalFormsExampleComponent {
|
|
126
|
+
readonly #model = signal<LeaveRequest>({ leave: null });
|
|
127
|
+
protected readonly request = form(this.#model, path => {
|
|
128
|
+
required(path.leave);
|
|
129
|
+
// The required rule only checks for an empty range; this checks that both ends are there.
|
|
130
|
+
validate(path.leave, ({ value }) => {
|
|
131
|
+
const leave = value();
|
|
132
|
+
if (!leave) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (!leave.start || !leave.end) {
|
|
136
|
+
return { kind: "incomplete", message: "Enter the first and the last day." };
|
|
137
|
+
}
|
|
138
|
+
return daysBetween(leave.start, leave.end) + 1 > 14
|
|
139
|
+
? { kind: "tooLong", message: "Leave can be up to two weeks." }
|
|
140
|
+
: null;
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
protected readonly sent = signal(false);
|
|
144
|
+
|
|
145
|
+
protected onSubmit(event: Event): void {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
void submit(this.request, async () => {
|
|
148
|
+
this.sent.set(true);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`signal-forms-example.component.html`
|
|
155
|
+
|
|
156
|
+
```html
|
|
157
|
+
<form class="flex max-w-sm flex-col gap-4" novalidate (submit)="onSubmit($event)">
|
|
158
|
+
<mona-form-field label="Leave" hint="Up to two weeks.">
|
|
159
|
+
<mona-date-range-picker [formField]="request.leave" />
|
|
160
|
+
</mona-form-field>
|
|
161
|
+
<div class="flex items-center gap-3">
|
|
162
|
+
<button monaButton look="primary" type="submit">Request leave</button>
|
|
163
|
+
@if (sent()) {
|
|
164
|
+
<span class="text-sm" role="status">Request sent.</span>
|
|
165
|
+
}
|
|
166
|
+
</div>
|
|
167
|
+
</form>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Quick ranges for a report
|
|
171
|
+
|
|
172
|
+
`presets` lists ranges to pick in one click, beside the calendar. Give the key of a built-in range, which the locale's messages name, or a `DateRangePreset` with a label and a function that works out its range from today. Here `maxDate` is today, so "This month" and "This year" end today.
|
|
173
|
+
|
|
174
|
+
`presets-example.component.ts`
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { Component, signal } from "@angular/core";
|
|
178
|
+
import {
|
|
179
|
+
type DateRange,
|
|
180
|
+
DateRangePickerComponent,
|
|
181
|
+
type DateRangePreset,
|
|
182
|
+
type DateRangePresetKey
|
|
183
|
+
} from "@nanahoshi/mona-ui/date-range-picker";
|
|
184
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
185
|
+
|
|
186
|
+
const now = new Date();
|
|
187
|
+
|
|
188
|
+
/** From the first day of the quarter today is in, up to today. */
|
|
189
|
+
const quarterToDate: DateRangePreset = {
|
|
190
|
+
label: "Quarter to date",
|
|
191
|
+
range: today => ({
|
|
192
|
+
end: today,
|
|
193
|
+
start: new Date(today.getFullYear(), Math.floor(today.getMonth() / 3) * 3, 1)
|
|
194
|
+
})
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
@Component({
|
|
198
|
+
selector: "app-date-range-picker-presets-example",
|
|
199
|
+
imports: [DateRangePickerComponent, FormFieldComponent],
|
|
200
|
+
templateUrl: "./presets-example.component.html"
|
|
201
|
+
})
|
|
202
|
+
export class DateRangePickerPresetsExampleComponent {
|
|
203
|
+
protected readonly period = signal<DateRange | null>(null);
|
|
204
|
+
protected readonly presets: readonly (DateRangePreset | DateRangePresetKey)[] = [
|
|
205
|
+
"today",
|
|
206
|
+
"yesterday",
|
|
207
|
+
"last7Days",
|
|
208
|
+
"last30Days",
|
|
209
|
+
"thisMonth",
|
|
210
|
+
"lastMonth",
|
|
211
|
+
quarterToDate,
|
|
212
|
+
"thisYear"
|
|
213
|
+
];
|
|
214
|
+
protected readonly today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`presets-example.component.html`
|
|
219
|
+
|
|
220
|
+
```html
|
|
221
|
+
<mona-form-field label="Report period" hint="Up to today.">
|
|
222
|
+
<mona-date-range-picker [maxDate]="today" [presets]="presets" [(value)]="period" />
|
|
223
|
+
</mona-form-field>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Limits and closed days
|
|
227
|
+
|
|
228
|
+
`minDate` and `maxDate` limit both ends, and `disabledDates` takes days that can't be picked, as a predicate or a list. A range may still span a disabled day, as a stay spans a Monday the office is closed.
|
|
229
|
+
|
|
230
|
+
`limits-example.component.ts`
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { Component, signal } from "@angular/core";
|
|
234
|
+
import { type DateRange, DateRangePickerComponent } from "@nanahoshi/mona-ui/date-range-picker";
|
|
235
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
236
|
+
|
|
237
|
+
const now = new Date();
|
|
238
|
+
|
|
239
|
+
@Component({
|
|
240
|
+
selector: "app-date-range-picker-limits-example",
|
|
241
|
+
imports: [DateRangePickerComponent, FormFieldComponent],
|
|
242
|
+
templateUrl: "./limits-example.component.html"
|
|
243
|
+
})
|
|
244
|
+
export class DateRangePickerLimitsExampleComponent {
|
|
245
|
+
protected readonly booking = signal<DateRange | null>(null);
|
|
246
|
+
protected readonly lastDay = new Date(now.getFullYear() + 1, now.getMonth(), now.getDate());
|
|
247
|
+
protected readonly today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
248
|
+
protected readonly isMonday = (date: Date): boolean => date.getDay() === 1;
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`limits-example.component.html`
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<div class="flex max-w-sm flex-col gap-4">
|
|
256
|
+
<mona-form-field label="Booking" hint="Within the next year. We're closed on Mondays.">
|
|
257
|
+
<mona-date-range-picker
|
|
258
|
+
[disabledDates]="isMonday"
|
|
259
|
+
[maxDate]="lastDay"
|
|
260
|
+
[minDate]="today"
|
|
261
|
+
[(value)]="booking" />
|
|
262
|
+
</mona-form-field>
|
|
263
|
+
</div>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Appearance & Styling
|
|
267
|
+
|
|
268
|
+
### Size and rounding
|
|
269
|
+
|
|
270
|
+
```html
|
|
271
|
+
<mona-date-range-picker [(value)]="stay" size="large" rounded="full"></mona-date-range-picker>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Supported `size` values are `small`, `medium` and `large`. Supported `rounded` values are `none`, `small`, `medium`, `large` and `full`. Both also apply to the popup.
|
|
275
|
+
|
|
276
|
+
`class` adds classes to the control, and `popupClass` to the popup. `popupWidth` and `popupHeight` size the popup; when they are empty, it fits the calendar and the quick ranges.
|
|
277
|
+
|
|
278
|
+
The control is as wide as its contents. Each input fits the longest date in `format`, such as "September 28, 2026" for `MMMM d, yyyy`, or its placeholder when that is longer, and leaves room for the clear button when `showClearButton` is set. Digits are drawn at one width, so the text doesn't shift as it changes. To fill the container, add `class="w-full"`: the calendar button then moves to the end.
|
|
279
|
+
|
|
280
|
+
### Calendar options
|
|
281
|
+
|
|
282
|
+
`months` sets how many months the calendar shows side by side, 2 by default. They wrap onto new rows when the screen is too narrow for them. `firstDay` sets the first day of the week, and `weekNumber` shows week numbers.
|
|
283
|
+
|
|
284
|
+
In the calendar, the first and last days of the range are drawn in the primary color, and the days between them in the selected tint.
|
|
285
|
+
|
|
286
|
+
## Behavior
|
|
287
|
+
|
|
288
|
+
### Typing a range
|
|
289
|
+
|
|
290
|
+
Each input shows its end in `format`, or in the active locale's date format when `format` is `null`. Typed text is also accepted with one-digit days and months and a two-digit year.
|
|
291
|
+
|
|
292
|
+
The text of both inputs is written to `value` on `Enter` and when an input loses focus. Clearing an input, or pressing the clear button shown by `showClearButton`, empties that end at once. The value is `null` when both ends are empty. Either end can be empty while the other is set.
|
|
293
|
+
|
|
294
|
+
When the text can't be written, the range stays as it was, the input shows its error, and the bound form field gets the error:
|
|
295
|
+
|
|
296
|
+
| Error | When |
|
|
297
|
+
|---|---|
|
|
298
|
+
| `parse` | The text isn't a date in the format |
|
|
299
|
+
| `minDate`, `maxDate` | The date is before `minDate` or after `maxDate` |
|
|
300
|
+
| `disabledDate` | The date is in `disabledDates` |
|
|
301
|
+
| `minDate` on the end | The end is before the start |
|
|
302
|
+
| `maxDate` on the start | The start is after the end |
|
|
303
|
+
|
|
304
|
+
An end before the start is reported on the input entered last, with the other end as the limit, so the form field writes "The date must be on or after March 4, 2025."
|
|
305
|
+
|
|
306
|
+
### Picking from the calendar
|
|
307
|
+
|
|
308
|
+
The calendar opens on the months of the range. The first day picked starts a new range, and the calendar previews it as the pointer moves; the second day picked ends it, and the range is written and the popup closes. Picking the end before the start swaps them. When the range has only its start, the first day picked ends it.
|
|
309
|
+
|
|
310
|
+
### Quick ranges
|
|
311
|
+
|
|
312
|
+
Each built-in range is worked out from today when the popup opens. Weeks start on `firstDay`, or on the locale's first day of the week.
|
|
313
|
+
|
|
314
|
+
| Key | Range |
|
|
315
|
+
|---|---|
|
|
316
|
+
| `today`, `yesterday` | That day alone |
|
|
317
|
+
| `last7Days`, `last30Days` | The days up to and including today |
|
|
318
|
+
| `thisWeek`, `thisMonth`, `thisYear` | The whole week, month or year today is in |
|
|
319
|
+
| `lastWeek`, `lastMonth`, `lastYear` | The whole week, month or year before it |
|
|
320
|
+
|
|
321
|
+
A `DateRangePreset` is `{ label, range }`, where `range` takes today's date, at the start of the day, and returns `{ start, end }`. Its ends are put in order.
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const nextTwoWeeks: DateRangePreset = {
|
|
325
|
+
label: "Next 2 weeks",
|
|
326
|
+
range: today => ({ start: today, end: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 13) })
|
|
327
|
+
};
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Picking a quick range writes it and closes the popup. A range is kept within `minDate` and `maxDate`. One with no day left in them, or whose first or last day is in `disabledDates`, is disabled. The quick range that is the value is shown selected.
|
|
331
|
+
|
|
332
|
+
On a phone the quick ranges sit above the calendar, in rows.
|
|
333
|
+
|
|
334
|
+
### Disabled and read-only
|
|
335
|
+
|
|
336
|
+
`disabled` and `readonly` keep the popup from opening. `readonlyInput` blocks typing in both inputs but keeps the calendar button working, so the range can only be picked.
|
|
337
|
+
|
|
338
|
+
### Popup events
|
|
339
|
+
|
|
340
|
+
`open` and `close` fire before the popup opens or closes, and both can be prevented. `opened` and `closed` fire after.
|
|
341
|
+
|
|
342
|
+
## Forms Integration
|
|
343
|
+
|
|
344
|
+
`DateRangePickerComponent` implements `FormValueControl<DateRange | null>` from `@angular/forms/signals`.
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
import { signal } from "@angular/core";
|
|
348
|
+
import { FormField, form, required } from "@angular/forms/signals";
|
|
349
|
+
import type { DateRange } from "@nanahoshi/mona-ui/date-range-picker";
|
|
350
|
+
|
|
351
|
+
protected readonly form = form(signal<{ stay: DateRange | null }>({ stay: null }), schema => {
|
|
352
|
+
required(schema.stay);
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
```html
|
|
357
|
+
<mona-date-range-picker [formField]="form.stay"></mona-date-range-picker>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
The `FormField` directive writes `disabled`, `invalid`, `readonly`, `required` and `touched`. The `touch` output fires when focus leaves the picker and its popup, so moving between the inputs or into the calendar doesn't mark the field touched.
|
|
361
|
+
|
|
362
|
+
The limits are inputs of the picker, `minDate` and `maxDate`, rather than the form's `minDate` and `maxDate` rules, which check a single date. Typing errors are reported to the bound form field, whether it is a signal form, `ngModel` or a reactive form control.
|
|
363
|
+
|
|
364
|
+
## Accessibility
|
|
365
|
+
|
|
366
|
+
The picker is a `role="group"`, named by its label. Each input is a `role="combobox"` named for its end by the `start` and `end` messages ("Start date" and "End date"), with `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls` pointing at the popup. The hint and the errors of a form field, or the picker's `aria-describedby`, describe both inputs.
|
|
367
|
+
|
|
368
|
+
The popup is a `role="dialog"` with `aria-modal="true"`, named by the `dateRangePicker` message ("Date range picker"). It traps focus, and the calendar takes focus when it opens. Each month in it is a grid named by its caption. The quick ranges are buttons in a `role="group"` named by the `presets` message ("Quick ranges"), and the one that is the value has `aria-pressed="true"`.
|
|
369
|
+
|
|
370
|
+
| Attribute | Where | Value |
|
|
371
|
+
|---|---|---|
|
|
372
|
+
| `role` | Host | `"group"` |
|
|
373
|
+
| `aria-label`, `aria-labelledby` | Host | The matching inputs on the picker, or the label of a `mona-label` or `mona-form-field` around it |
|
|
374
|
+
| `aria-disabled` | Host | `"true"` while disabled |
|
|
375
|
+
| `role` | Each input | `"combobox"` |
|
|
376
|
+
| `aria-label` | Each input | The `start` or `end` message |
|
|
377
|
+
| `aria-describedby` | Each input | The picker's `aria-describedby`, and a form field's hint and errors |
|
|
378
|
+
| `aria-invalid` | Each input | `"true"` on that input's typing error, or on both once `touched` and either `invalid`, or `required` with an empty range |
|
|
379
|
+
| `aria-haspopup` | Each input | `"dialog"` |
|
|
380
|
+
| `aria-expanded` | Each input and the calendar button | `"true"` while the popup is open, otherwise `"false"` |
|
|
381
|
+
| `aria-label` | Calendar button | The `openCalendar` message ("Open calendar") |
|
|
382
|
+
| `role` | Popup | `"dialog"`, with `aria-modal="true"` |
|
|
383
|
+
| `role`, `aria-label` | Quick ranges | `"group"`, named by the `presets` message |
|
|
384
|
+
| `aria-pressed` | Each quick range | `"true"` on the one that is the value, otherwise `"false"` |
|
|
385
|
+
|
|
386
|
+
The calendar button has `tabindex="-1"`, so the picker is two Tab stops, one for each input. Keyboard users open the popup with `Alt+ArrowDown`.
|
|
387
|
+
|
|
388
|
+
**Consumer responsibilities**
|
|
389
|
+
|
|
390
|
+
- Label the picker. Put it in a `mona-form-field` or a `<mona-label text="...">`, or set `aria-labelledby` or `aria-label`. The placeholders are not labels.
|
|
391
|
+
|
|
392
|
+
### Keyboard Interaction
|
|
393
|
+
|
|
394
|
+
| Key | Where | Action |
|
|
395
|
+
|---|---|---|
|
|
396
|
+
| `Alt+ArrowDown` | Either input | Opens the popup |
|
|
397
|
+
| `Alt+ArrowUp` / `Escape` | Either input, the calendar or a quick range | Closes the popup |
|
|
398
|
+
| `Enter` | Either input | Writes the typed text to `value` |
|
|
399
|
+
|
|
400
|
+
Inside the popup, the calendar's keyboard map applies, and the arrow keys move between its months. `Tab` moves between the quick ranges and the calendar. Closing the popup returns focus to the input that had it, or to the end input once a range is picked, unless the user moved focus elsewhere.
|
|
401
|
+
|
|
402
|
+
## API
|
|
403
|
+
|
|
404
|
+
Everything below is imported from `@nanahoshi/mona-ui/date-range-picker`. Each name links to its reference page, with every input, output, property and method.
|
|
405
|
+
|
|
406
|
+
| Name | Kind | Description |
|
|
407
|
+
| --- | --- | --- |
|
|
408
|
+
| [`DateRangePickerComponent`](api/date-range-picker.md#daterangepickercomponent) | Component | Picks a range of days: two inputs for its first and last day, typed in the locale's format, and a calendar popup that shows two months at a time. |
|
|
409
|
+
|
|
410
|
+
### Types
|
|
411
|
+
|
|
412
|
+
| Type | Kind | Description |
|
|
413
|
+
| --- | --- | --- |
|
|
414
|
+
| [`DATE_RANGE_PICKER_DEFAULT_MESSAGES`](api/date-range-picker.md#date-range-picker-default-messages) | Constant | |
|
|
415
|
+
| [`DateRange`](api/date-range-picker.md#daterange) | Interface | A span of days, from `start` to `end`, both included. |
|
|
416
|
+
| [`DateRangePreset`](api/date-range-picker.md#daterangepreset) | Interface | A quick range of your own, shown beside the calendar. |
|
|
417
|
+
| [`DateRangePresetRange`](api/date-range-picker.md#daterangepresetrange) | Interface | The range a preset picks. |
|
|
418
|
+
| [`DateRangePresetKey`](api/date-range-picker.md#daterangepresetkey) | Type alias | A built-in quick range, named by the locale's messages. |
|
|
419
|
+
|
|
420
|
+
**Related types:** [`DateDisabledType`](api/date-input.md#datedisabledtype), [`FirstDayOfWeek`](api/calendar.md#firstdayofweek), [`ListSizeInputType`](api/list.md#listsizeinputtype), [`ListSizeType`](api/list.md#listsizetype), [`MonaDateRangePickerMessages`](api/i18n.md#monadaterangepickermessages), [`PopupCloseEvent`](api/popup.md#popupcloseevent), [`PreventableEvent`](api/common.md#preventableevent)
|
package/docs/forms.md
CHANGED
|
@@ -101,6 +101,7 @@ If more than one applies, an explicit `aria-labelledby` wins, and then `aria-lab
|
|
|
101
101
|
| `mona-color-gradient` | Yes | Yes | Yes | No | No |
|
|
102
102
|
| `mona-numeric-text-box`, `mona-decimal-text-box` | Yes | Focus only | Yes | Yes | No |
|
|
103
103
|
| `mona-date-picker` | Yes | Focus only | Yes | Yes | No |
|
|
104
|
+
| `mona-date-range-picker` | Yes, as a group | Focus only | Yes, on the group | No | No |
|
|
104
105
|
| `mona-dropdown-list` | Yes | Focus only | Yes | No | No |
|
|
105
106
|
|
|
106
107
|
A check box and a radio button render their own `<label>`, and its text has to stay their name, so a wrapping `mona-label` doesn't name them. Use their `label` input, or `[for]` from outside.
|
package/docs/label.md
CHANGED
|
@@ -261,6 +261,7 @@ A string `for` can't work on a component's host element, because a host such as
|
|
|
261
261
|
| `mona-slider`, `mona-range-slider`, `mona-rating`, `mona-segmented`, `mona-radio-group`, `mona-button-group`, `mona-color-palette`, `mona-color-picker`, `mona-color-gradient` | Named. A click focuses. | Named. A click focuses. | No, warns in development |
|
|
262
262
|
| `mona-numeric-text-box`, `mona-decimal-text-box`, `mona-date-picker`, `mona-time-picker`, `mona-datetime-picker`, `mona-combo-box`, `mona-auto-complete` | Named. A click focuses. | Focus only, not named | Yes, on `inputId` |
|
|
263
263
|
| `mona-dropdown-list`, `mona-multi-select`, `mona-editor` | Named. A click focuses. | Focus only, not named | No: they have no native input |
|
|
264
|
+
| `mona-date-range-picker` | Its group is named. A click focuses the start. | Focus only, not named | No: it has two inputs |
|
|
264
265
|
| Other controls | Not connected, unless they hold a native input | Focus only, not named | Only on a native input's `id` |
|
|
265
266
|
|
|
266
267
|
A control that is focus only with `[for]` still needs a name. Give it `aria-labelledby` pointing at the label's `id`, as the dropdown list examples do, or use `inputId` where the control has one:
|