@cahyo-dimas/freeday 3.19.1 → 3.20.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/CHANGELOG.md CHANGED
@@ -9,6 +9,54 @@ benar. Perubahan seperti itu ditulis di bawah `### Changed: BREAKING (types)`
9
9
  lama → tipe baru, dan cara menyempitkannya — bukan di bawah `### Added`, betapapun aditifnya dari
10
10
  sisi kit.
11
11
 
12
+ ## [3.20.0] - 2026-11-19
13
+
14
+ **Rentang tanggal dalam satu kolom.** `FdyDateRange` selama ini dua picker bersebelahan: makan dua
15
+ kolom di filter bar, patah jadi dua baris di layar sempit dengan `–` tertinggal di baris pertama, dan
16
+ rentangnya tidak pernah terlihat utuh di satu kalender. Diminta dari app ronda (`CATATAN-FREEDAY.md`
17
+ §28), dengan enam filter bar yang memakainya.
18
+
19
+ ### Added
20
+ - **`layout="single"` di `FdyDateRange`** (`#118`, §28), di Vue, React, Blazor (`Layout =
21
+ FdyDateRangeLayout.Single`) dan jalur mentah (`data-fdy-daterange data-layout="single"` pada `div`
22
+ kosong). Satu pemicu berisi kedua tanggal dan satu kalender. Hari pertama yang dipilih menjadi
23
+ awal dan panel tetap terbuka; hari kedua menjadi akhir dan panel menutup. Hari sebelum awal
24
+ menjadi awal yang baru, tidak ditukar diam-diam. Hari yang di-hover atau difokus keyboard
25
+ menggambar pita pratinjau dengan ujung yang belum terisi, jadi rentangnya terlihat sebelum
26
+ dikomit. Escape dan klik di luar membuang awal yang belum punya akhir.
27
+ - **Nilainya hanya berubah saat rentangnya utuh**, jadi `change` dan `settled` datang bersamaan di
28
+ bentuk ini. Jalur mentah memancarkan `fdy-daterange-settled` saja. `data-value` di akarnya berbentuk
29
+ interval ISO 8601 `"awal/akhir"`, atau kosong selama rentangnya belum utuh, sehingga
30
+ `data-fdy-required` berlaku tanpa aturan baru di `freeday-form.js`.
31
+ - **Prop baru:** `layout`, `placeholder` (bawaan `Select dates`; enhancer `Choose dates`),
32
+ `rangeStartLabel` dan `rangeEndLabel` (bawaan `range start` / `range end`), yang ditambahkan ke nama
33
+ aksesibel hari awal dan akhir supaya kedua ujung tidak dibedakan oleh warna saja. Di jalur mentah
34
+ kuncinya `data-fdy-text-range-start`, `-range-end`, `-label-range` dan `-placeholder-range`.
35
+ `FdyDateRangeLayout` diekspor sebagai tipe dari `/vue` dan `/react`.
36
+ - **`.fdy-datepicker--range`**, `.is-range-start` dan `.is-range-end`. Lebar maksimum pemicu 18rem,
37
+ sebab pasangan tanggal terpanjang yang diukur butuh 14,63rem (`id`) sampai 15,13rem (`en-US`).
38
+
39
+ ### Changed
40
+ - **Pita `.in-range` kini menyambung.** Sel hari berjarak 2px, jadi pita di jalur mentah bentuk
41
+ `split` selama ini bergaris. Tiap sel di pita kini menutup celah di kedua sisinya, dan cincin fokus
42
+ dikembalikan pada sel pita, yang tadinya tertimpa bayangan pita.
43
+
44
+ ### Catatan
45
+ - **Satu kalender per stack, tanpa salinan baru.** `FdyDatepicker` Vue dan React menggambar rentang
46
+ itu sendiri saat `FdyDateRange` menyediakan konteks internal (`provide` di Vue, Context di React).
47
+ Rentang tidak dijadikan prop `FdyDatepicker`, sebab bentuk nilai yang ditentukan prop lain adalah
48
+ cacat yang memensiunkan `mode="month"`. Aturan murninya (ujung mana yang tampil, keadaan tiap sel,
49
+ arti sebuah klik) ada di `adapters/core/date-range.js`; enhancer memegang salinannya sendiri karena
50
+ alasan yang sama dengan `month-grid.js`.
51
+ - **Bentuk `split` di Vue dan React tetap tanpa pewarnaan `.in-range`**, seperti sebelumnya. Tiap
52
+ pickernya berdiri sendiri, dan menambahkannya tidak diminta.
53
+ - **`Layout` di Blazor dibaca sekali**, pada render pertama, seperti setiap seed lain yang komponen
54
+ itu serahkan ke enhancer.
55
+ - Diuji di `browser/daterange-single.mjs`: 13 kasus dengan mouse dan tombol asli di ketiga
56
+ implementasi, termasuk form yang menolak rentang setengah jadi. Tiga mutasi (komit di klik
57
+ pertama, pita pratinjau hilang, setengah rentang bertahan sesudah ditutup) masing-masing membuat 5,
58
+ 4 dan 1 kasus merah. Ditambah 3 uji bUnit dan 5 uji unit untuk `date-range.js`.
59
+
12
60
  ## [3.19.1] - 2026-11-09
13
61
 
14
62
  Hanya dokumen dan uji. Tidak ada perubahan pada CSS, enhancer, atau pembungkus.
package/COMPONENTS.md CHANGED
@@ -1125,18 +1125,31 @@ grid's own title.
1125
1125
  | Prop | Type | What it does |
1126
1126
  |---|---|---|
1127
1127
  | `modelValue` · `value` | `DateRangeValue` = `{ start, end }`, each `string \| null` | Both ends at once, so the pair can never be half-applied. |
1128
+ | `layout?` | `'split' \| 'single'` | `split` (default) is two pickers side by side. `single` is one field holding both dates, with one calendar in which the first day picked is the start and the second is the end. The value changes only once the range is whole, so `change` and `settled` arrive together, and Escape or a click outside drops a start that has no end yet. Blazor takes the enum `FdyDateRangeLayout`. |
1129
+ | `placeholder?` | `string` | The empty field's text under `layout="single"`. Default `Select dates`. |
1130
+ | `rangeStartLabel?` · `rangeEndLabel?` | `string` | Under `layout="single"`, appended to the accessible name of the range's first and last day, so the ends are not told apart by colour alone. Defaults `range start` / `range end`. |
1128
1131
  | `onChange` | `(value: DateRangeValue) => void` | React. Vue emits `update:modelValue` and `change`. Fires on **each** end, which is right for a binding and wrong for a reload. |
1129
1132
  | `onSettled?` | `(value: DateRangeValue) => void` | React. Vue emits `settled`, Blazor `Settled` (`SettledRange(From, To)`), the raw path `fdy-daterange-settled` `{ from, to }` on the group. Fires only when **both ends are chosen or both are empty**, so a list that reloads on it never filters on half a range. |
1130
1133
  | `min?` · `max?` | `string` | ISO bounds for both ends. The end can never precede the start. |
1131
1134
  | `locale?` | `string` | As on the single picker. |
1132
- | `startPlaceholder?` · `endPlaceholder?` | `string` | One per field. |
1135
+ | `startPlaceholder?` · `endPlaceholder?` | `string` | One per field, under `layout="split"`. |
1133
1136
  | `ariaLabel?` · `ariaLabelledby?` · `describedby?` | `string` | Names the group (`role="group"`), or points at the text that does. |
1134
1137
  | `disabled?` · `readonly?` · `invalid?` | `boolean` | Applied to both pickers together. |
1135
1138
  | `required?` | `boolean` | Both ends must be filled for a [`data-fdy-validate`](#form-validation--data-fdy-validate) form to submit. Each picker refuses on its own, and the two share the field's one message slot, which stays up while either end is still empty. Blazor: `Required`. |
1136
1139
  | `prevMonthLabel?` · `nextMonthLabel?` · `prevYearLabel?` · `nextYearLabel?` · `prevYearsLabel?` · `nextYearsLabel?` · `chooseMonthLabel?` · `chooseYearLabel?` | `string` | Forwarded verbatim to **both** pickers. Until 3.11.0 this was the one picker in the kit whose calendar nav could not be named in the page's own language: the single picker took these, the range dropped them. Blazor adds `BackToMonthsLabel`, since the raw seed both pickers are built from has that button. |
1137
1140
 
1138
1141
  Blazor splits the value into two scalars, `From` / `FromChanged` and `To` / `ToChanged`, because a
1139
- C# binding cannot express one object bound in two places, and it adds `Separator`.
1142
+ C# binding cannot express one object bound in two places, and it adds `Separator`. Under
1143
+ `Layout="FdyDateRangeLayout.Single"` both scalars change in the same call, followed by `Settled`, and
1144
+ it takes `Placeholder`, `RangeStartLabel` and `RangeEndLabel`.
1145
+
1146
+ **When to pick `single`.** It takes one field's width instead of two, and the whole range is visible
1147
+ in the calendar while it is being picked. In a `.fdy-filterbar`, give its field `.fdy-field--w-xl`.
1148
+ The widest pair measured, 28 September to 30 December, needs 14.63rem in `id`, 14.94rem in `en-GB`
1149
+ and 15.13rem in `en-US`, so the bar's default 12rem cuts the second date short and `--w-lg` (15rem)
1150
+ still clips it in `en-US`. Keep
1151
+ `split` where each end is its own decision, such as a start date filled in long before the end is
1152
+ known.
1140
1153
 
1141
1154
  Input-styled trigger + calendar popover. Needs `freeday-datepicker.js`. **Author an empty `<div>`**
1142
1155
  The enhancer builds everything.
@@ -1149,6 +1162,15 @@ The enhancer builds everything.
1149
1162
  a start picked past the end clears the end, and that clear fires `fdy-datepicker-change` with
1150
1163
  `value: ''` like a pick. Reload on `fdy-daterange-settled`, not on each change.
1151
1164
  **Typed wrapper: `<FdyDateRange>`** (Vue/React/Blazor). Use it in those stacks.
1165
+ - Range in one field: an **empty** `<div data-fdy-daterange data-layout="single">`, with no class
1166
+ and no children. The enhancer builds one `.fdy-datepicker.fdy-datepicker--range`. `data-value`
1167
+ holds `"start/end"` (the ISO 8601 interval form) or `""`; the root mirrors it live, so
1168
+ `data-fdy-required` works as on any kit control, and half a range reads as empty. `data-label` or
1169
+ `aria-label` names the trigger. `data-min`, `data-max` and `data-placeholder` work as on one
1170
+ picker. It emits only `fdy-daterange-settled` `{ from, to }`, once per whole range. The ends of
1171
+ the band carry `.is-range-start` / `.is-range-end`, the days between `.in-range`, and the two
1172
+ extra strings are `data-fdy-text-range-start` / `data-fdy-text-range-end` (defaults `range start`
1173
+ / `range end`), beside `data-fdy-text-label-range` and `data-fdy-text-placeholder-range`.
1152
1174
  **Getting to a distant date.** The title is a **button**, and it drills up one level each press:
1153
1175
  day grid → 12-cell month grid (`.fdy-cal__grid--months` of `.fdy-cal__month`) → 12-cell year grid
1154
1176
  (`.fdy-cal__grid--years` of `.fdy-cal__year`). The arrows follow the level shown: months, then
@@ -1217,6 +1239,13 @@ it has always been, down to the `YYYY-MM-DD` it reports.
1217
1239
  <span class="fdy-daterange__sep" aria-hidden="true">–</span>
1218
1240
  <div data-fdy-datepicker data-role="to" data-placeholder="To" data-label="End date"></div>
1219
1241
  </div>
1242
+
1243
+ <!-- The same range in one field. Typed stacks: <FdyDateRange layout="single">. -->
1244
+ <div class="fdy-field">
1245
+ <span class="fdy-label">Reporting period</span>
1246
+ <div data-fdy-daterange data-layout="single" data-value="2026-11-01/2026-11-30"
1247
+ data-label="Reporting period"></div>
1248
+ </div>
1220
1249
  ```
1221
1250
 
1222
1251
  ## Time picker — `data-fdy-timepicker`
package/README.id.md CHANGED
@@ -5,7 +5,7 @@
5
5
  > **Lebih banyak _free day_ buat dev. UI kit-nya sudah siap pakai.**
6
6
 
7
7
  [![Live docs](https://img.shields.io/badge/docs-live-2050d8?style=flat-square)](https://cahyo-dimas.github.io/freeday-ui-kit/)
8
- [![Release](https://img.shields.io/badge/release-v3.19.1-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.19.1)
8
+ [![Release](https://img.shields.io/badge/release-v3.20.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.20.0)
9
9
 
10
10
  UI KIT yang token-driven & framework-agnostic. Satu sumber kebenaran untuk warna, tipografi,
11
11
  spasi, dan komponen. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  > **More free days for devs. The UI kit is ready to use.**
6
6
 
7
7
  [![Live docs](https://img.shields.io/badge/docs-live-2050d8?style=flat-square)](https://cahyo-dimas.github.io/freeday-ui-kit/)
8
- [![Release](https://img.shields.io/badge/release-v3.19.1-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.19.1)
8
+ [![Release](https://img.shields.io/badge/release-v3.20.0-0078d4?style=flat-square)](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.20.0)
9
9
 
10
10
  A token-driven, framework-agnostic UI kit. One source of truth for color, typography,
11
11
  spacing, and components. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
@@ -1,14 +1,20 @@
1
1
  @namespace Freeday.Blazor
2
2
  @inherits FreedayComponentBase<FdyDateRange>
3
3
 
4
- @* Two linked seed datepickers (freeday-datepicker.js data-fdy-daterange: the end can't precede
5
- the start). The daterange sits INSIDE Root so initAll(Root) finds and links it as a descendant.
6
- Both children emit fdy-datepicker-change; the bridge's dateRangeOn tags each with its data-role
7
- so From/To bind separately. Enhancer-owned DOM → render once (ShouldRender => false). *@
4
+ @* Split: two linked seed datepickers (freeday-datepicker.js data-fdy-daterange: the end can't
5
+ precede the start). Both children emit fdy-datepicker-change; the bridge's dateRangeOn tags each
6
+ with its data-role so From/To bind separately.
7
+ Single: ONE seed the enhancer turns into a field holding both dates. It answers once, with the
8
+ whole range, through fdy-daterange-settled.
9
+ Either sits INSIDE Root so initAll(Root) finds it as a descendant. Enhancer-owned DOM → render
10
+ once (ShouldRender => false). *@
8
11
  <div @ref="Root">
9
- <div data-fdy-daterange role="group" aria-label="@AriaLabel">
10
- <div @ref="_fromEl" data-fdy-datepicker data-role="from" data-fdy-required="@(Required ? "" : null)"
11
- data-value="@From" data-placeholder="@FromPlaceholder" data-min="@Min" data-max="@Max"
12
+ @if (Layout == FdyDateRangeLayout.Single)
13
+ {
14
+ <div @ref="_singleEl" data-fdy-daterange data-layout="single" data-fdy-required="@(Required ? "" : null)"
15
+ data-value="@SeedInterval" data-label="@AriaLabel" data-placeholder="@Placeholder" data-min="@Min" data-max="@Max"
16
+ data-fdy-text-range-start="@RangeStartLabel"
17
+ data-fdy-text-range-end="@RangeEndLabel"
12
18
  data-fdy-text-prev-month="@PrevMonthLabel"
13
19
  data-fdy-text-next-month="@NextMonthLabel"
14
20
  data-fdy-text-prev-year="@PrevYearLabel"
@@ -18,17 +24,33 @@
18
24
  data-fdy-text-choose-month="@ChooseMonthLabel"
19
25
  data-fdy-text-choose-year="@ChooseYearLabel"
20
26
  data-fdy-text-back-to-months="@BackToMonthsLabel"></div>
21
- <span class="fdy-daterange__sep">@Separator</span>
22
- <div @ref="_toEl" data-fdy-datepicker data-role="to" data-fdy-required="@(Required ? "" : null)"
23
- data-value="@To" data-placeholder="@ToPlaceholder" data-min="@Min" data-max="@Max"
24
- data-fdy-text-prev-month="@PrevMonthLabel"
25
- data-fdy-text-next-month="@NextMonthLabel"
26
- data-fdy-text-prev-year="@PrevYearLabel"
27
- data-fdy-text-next-year="@NextYearLabel"
28
- data-fdy-text-prev-years="@PrevYearsLabel"
29
- data-fdy-text-next-years="@NextYearsLabel"
30
- data-fdy-text-choose-month="@ChooseMonthLabel"
31
- data-fdy-text-choose-year="@ChooseYearLabel"
32
- data-fdy-text-back-to-months="@BackToMonthsLabel"></div>
33
- </div>
27
+ }
28
+ else
29
+ {
30
+ <div data-fdy-daterange role="group" aria-label="@AriaLabel">
31
+ <div @ref="_fromEl" data-fdy-datepicker data-role="from" data-fdy-required="@(Required ? "" : null)"
32
+ data-value="@From" data-placeholder="@FromPlaceholder" data-min="@Min" data-max="@Max"
33
+ data-fdy-text-prev-month="@PrevMonthLabel"
34
+ data-fdy-text-next-month="@NextMonthLabel"
35
+ data-fdy-text-prev-year="@PrevYearLabel"
36
+ data-fdy-text-next-year="@NextYearLabel"
37
+ data-fdy-text-prev-years="@PrevYearsLabel"
38
+ data-fdy-text-next-years="@NextYearsLabel"
39
+ data-fdy-text-choose-month="@ChooseMonthLabel"
40
+ data-fdy-text-choose-year="@ChooseYearLabel"
41
+ data-fdy-text-back-to-months="@BackToMonthsLabel"></div>
42
+ <span class="fdy-daterange__sep">@Separator</span>
43
+ <div @ref="_toEl" data-fdy-datepicker data-role="to" data-fdy-required="@(Required ? "" : null)"
44
+ data-value="@To" data-placeholder="@ToPlaceholder" data-min="@Min" data-max="@Max"
45
+ data-fdy-text-prev-month="@PrevMonthLabel"
46
+ data-fdy-text-next-month="@NextMonthLabel"
47
+ data-fdy-text-prev-year="@PrevYearLabel"
48
+ data-fdy-text-next-year="@NextYearLabel"
49
+ data-fdy-text-prev-years="@PrevYearsLabel"
50
+ data-fdy-text-next-years="@NextYearsLabel"
51
+ data-fdy-text-choose-month="@ChooseMonthLabel"
52
+ data-fdy-text-choose-year="@ChooseYearLabel"
53
+ data-fdy-text-back-to-months="@BackToMonthsLabel"></div>
54
+ </div>
55
+ }
34
56
  </div>
@@ -23,6 +23,22 @@ public partial class FdyDateRange
23
23
  [Parameter] public string? Max { get; set; }
24
24
  [Parameter] public string Separator { get; set; } = "–";
25
25
 
26
+ /// <summary><see cref="FdyDateRangeLayout.Split"/> (default): two pickers.
27
+ /// <see cref="FdyDateRangeLayout.Single"/>: one field holding both dates, whose
28
+ /// <c>From</c>/<c>To</c> change only together, when the range is whole. Read on the first
29
+ /// render, like every other seed this component hands the enhancer.</summary>
30
+ [Parameter] public FdyDateRangeLayout Layout { get; set; }
31
+
32
+ /// <summary>The empty field's text under <see cref="FdyDateRangeLayout.Single"/>. Default
33
+ /// 'Choose dates' (the enhancer's).</summary>
34
+ [Parameter] public string? Placeholder { get; set; }
35
+
36
+ /// <summary>Added to the accessible name of the range's first and last day under
37
+ /// <see cref="FdyDateRangeLayout.Single"/>, so an end is not told by colour alone. Defaults
38
+ /// 'range start' / 'range end'.</summary>
39
+ [Parameter] public string? RangeStartLabel { get; set; }
40
+ [Parameter] public string? RangeEndLabel { get; set; }
41
+
26
42
  /* The calendars' own navigation labels, forwarded verbatim to BOTH pickers. Month and weekday
27
43
  NAMES follow the page's `lang` through Intl and need nothing here; these are the buttons
28
44
  around them. Until now the range was the one picker in the kit whose nav could not be named
@@ -51,18 +67,35 @@ public partial class FdyDateRange
51
67
  private int _token;
52
68
  private ElementReference _fromEl;
53
69
  private ElementReference _toEl;
70
+ private ElementReference _singleEl;
71
+
72
+ /// <summary>"from/to" (ISO 8601 interval), the one <c>data-value</c> the single field reads,
73
+ /// or null while either end is missing: the field never shows half a range.</summary>
74
+ private string? SeedInterval => string.IsNullOrEmpty(From) || string.IsNullOrEmpty(To) ? null : $"{From}/{To}";
54
75
 
55
76
  // initAll(Root) links the daterange (descendant) and inits both child pickers.
56
77
  protected override ValueTask HydrateAsync() => JS.InvokeVoidAsync("FreedayDatepicker.initAll", Root);
57
78
 
58
79
  protected override async ValueTask OnHydratedAsync()
59
- => _token = await JS.InvokeAsync<int>("FreedayBlazor.dateRangeOn", Root, Self, nameof(OnChange));
80
+ {
81
+ if (Layout == FdyDateRangeLayout.Single)
82
+ {
83
+ await SubscribeAsync("fdy-daterange-settled", nameof(OnSettled));
84
+ return;
85
+ }
86
+ _token = await JS.InvokeAsync<int>("FreedayBlazor.dateRangeOn", Root, Self, nameof(OnChange));
87
+ }
60
88
 
61
89
  protected override bool ShouldRender() => !Hydrated;
62
90
 
63
91
  protected override async Task OnParametersSetAsync()
64
92
  {
65
93
  if (!Hydrated) return;
94
+ if (Layout == FdyDateRangeLayout.Single)
95
+ {
96
+ await JS.InvokeVoidAsync("FreedayDatepicker.setState", _singleEl, new { required = Required });
97
+ return;
98
+ }
66
99
  await JS.InvokeVoidAsync("FreedayDatepicker.setState", _fromEl, new { required = Required });
67
100
  await JS.InvokeVoidAsync("FreedayDatepicker.setState", _toEl, new { required = Required });
68
101
  }
@@ -87,6 +120,18 @@ public partial class FdyDateRange
87
120
  }
88
121
  }
89
122
 
123
+ /// <summary>Invoked by the bridge when the single field commits a whole range. Both ends move
124
+ /// together, so <c>Settled</c> follows every call.</summary>
125
+ [JSInvokable]
126
+ public async Task OnSettled(SettledDetail detail)
127
+ {
128
+ From = detail.From;
129
+ To = detail.To;
130
+ await FromChanged.InvokeAsync(detail.From);
131
+ await ToChanged.InvokeAsync(detail.To);
132
+ await Settled.InvokeAsync(new SettledRange(From, To));
133
+ }
134
+
90
135
  protected override async ValueTask CleanupAsync()
91
136
  {
92
137
  if (_token != 0)
@@ -97,6 +142,22 @@ public partial class FdyDateRange
97
142
 
98
143
  public sealed record RangeDetail(string? Value, string? Role);
99
144
 
145
+ /// <summary>The detail of <c>fdy-daterange-settled</c>, <c>{ from, to }</c>.</summary>
146
+ public sealed record SettledDetail(string? From, string? To);
147
+
100
148
  /// <summary>The range as it stands when it settles; both empty means "no period".</summary>
101
149
  public sealed record SettledRange(string? From, string? To);
102
150
  }
151
+
152
+ /// <summary>
153
+ /// How <see cref="FdyDateRange"/> lays the range out. The JS adapters take the same idea as the
154
+ /// string union <c>'split' | 'single'</c>; C# gets an enum, as <see cref="FdyNavMode"/> does.
155
+ /// </summary>
156
+ public enum FdyDateRangeLayout
157
+ {
158
+ /// <summary>Two linked pickers, one per end (the default, and what every earlier range was).</summary>
159
+ Split,
160
+
161
+ /// <summary>One field and one calendar: the first day picked is the start, the second the end.</summary>
162
+ Single,
163
+ }
@@ -0,0 +1,37 @@
1
+ // Types for the single-field date range logic (adapters/core/date-range.js).
2
+ // Shared by the Vue and React FdyDatepicker when FdyDateRange draws its `layout="single"` calendar.
3
+
4
+ /** The committed range, plus a start picked in this opening and the day previewed after it. */
5
+ export interface FdyRangeState {
6
+ start: Date | null;
7
+ end: Date | null;
8
+ /** A start picked and not yet answered by an end. */
9
+ anchor: Date | null;
10
+ /** The day under the pointer or the keyboard while `anchor` waits. */
11
+ preview: Date | null;
12
+ }
13
+
14
+ export interface FdyShownEnds {
15
+ from: Date | null;
16
+ to: Date | null;
17
+ /** True while a start waits for its end. */
18
+ pending: boolean;
19
+ }
20
+
21
+ export interface FdyRangeDayState {
22
+ /** An end that is an answer: drawn like a picked day and `aria-selected`. */
23
+ filled: boolean;
24
+ rangeStart: boolean;
25
+ rangeEnd: boolean;
26
+ inRange: boolean;
27
+ /** What the day's accessible name adds. */
28
+ role: 'start' | 'end' | null;
29
+ }
30
+
31
+ export type FdyRangePick =
32
+ | { kind: 'anchor'; anchor: Date }
33
+ | { kind: 'commit'; start: Date; end: Date };
34
+
35
+ export function shownEnds(range: FdyRangeState): FdyShownEnds;
36
+ export function rangeDayState(day: Date, ends: FdyShownEnds): FdyRangeDayState;
37
+ export function rangeAfterPick(anchor: Date | null, day: Date): FdyRangePick;
@@ -0,0 +1,61 @@
1
+ // Freeday, the date range in one field, framework-agnostic (pure, zero dependencies).
2
+ //
3
+ // What `FdyDateRange layout="single"` decides on top of the ordinary day grid: which two ends the
4
+ // grid shows while a start waits for its end, what state each day cell is in, and what a pick means.
5
+ // Shared by the Vue and React `FdyDatepicker`, which draw the calendar for that layout, so the two
6
+ // read one copy of the rule.
7
+ //
8
+ // The vanilla enhancer (src/freeday-datepicker.js) holds its own copy, for the reason
9
+ // adapters/core/month-grid.js records: dist/freeday.js is an IIFE with no module system.
10
+ // browser/daterange-single.mjs holds all three to the same observable behaviour.
11
+ //
12
+ // Every Date here is a local midnight; callers normalise with startOfDay before passing one in.
13
+
14
+ function same(a, b) {
15
+ return a !== null && b !== null && a.getTime() === b.getTime();
16
+ }
17
+
18
+ /**
19
+ * The ends the grid shows. With no start pending, the committed range. With one pending, the start
20
+ * and the day being previewed, and that day only when it does not precede the start: a day before it
21
+ * becomes the new start on a click, so a band drawn backwards would promise something a click will
22
+ * not do.
23
+ */
24
+ export function shownEnds(range) {
25
+ if (range.anchor !== null) {
26
+ const to = range.preview !== null && range.preview.getTime() >= range.anchor.getTime() ? range.preview : null;
27
+ return { from: range.anchor, to, pending: true };
28
+ }
29
+ return { from: range.start, to: range.end, pending: false };
30
+ }
31
+
32
+ /**
33
+ * One day cell's range state. `filled` is an end that is an answer (a committed end, or the start
34
+ * just picked); a previewed end is not one. `rangeStart`/`rangeEnd` shape the ends of a band of two
35
+ * days or more, and `role` is what the cell's accessible name adds, so an end is not told by colour.
36
+ */
37
+ export function rangeDayState(day, ends) {
38
+ const isFrom = ends.from !== null && same(day, ends.from);
39
+ const isTo = ends.to !== null && same(day, ends.to);
40
+ const span = ends.from !== null && ends.to !== null && !same(ends.from, ends.to);
41
+ const t = day.getTime();
42
+ const between = span && t > ends.from.getTime() && t < ends.to.getTime();
43
+ return {
44
+ filled: isFrom || (isTo && !ends.pending),
45
+ rangeStart: isFrom && span,
46
+ rangeEnd: isTo && span,
47
+ inRange: between || (span && isTo && ends.pending),
48
+ role: isFrom ? 'start' : isTo && !ends.pending ? 'end' : null,
49
+ };
50
+ }
51
+
52
+ /**
53
+ * What picking `day` does. With no start pending, or a day before the pending one, it becomes the
54
+ * start and the panel stays open. Otherwise the range is whole: same day included, a one-day range.
55
+ * A pick before the start is not swapped into the end, which would leave the reader unsure which
56
+ * end they just moved.
57
+ */
58
+ export function rangeAfterPick(anchor, day) {
59
+ if (anchor === null || day.getTime() < anchor.getTime()) return { kind: 'anchor', anchor: day };
60
+ return { kind: 'commit', start: anchor, end: day };
61
+ }
@@ -1,19 +1,37 @@
1
1
  import type { JSX } from 'react';
2
2
  import { FdyDatepicker } from './FdyDatepicker';
3
+ import { FdyRangeField, type FdyRangeFieldContext } from '../rangeField';
3
4
 
4
- // A controlled date range over freeday's `.fdy-daterange` layout (src/components/datepicker.css):
5
- // two linked FdyDatepickers where the end can't precede the start (start.max = end, end.min = start).
6
- // `value` + `onChange` in place of Vue's `v-model`; this composes the single-date picker rather than
7
- // re-implementing the calendar. Note: the vanilla enhancer's cross-calendar `.in-range` day shading
8
- // is not reproduced (each picker is independent), the min/max linkage is what keeps the range valid.
5
+ // A controlled date range, in one of two layouts that share the value and every prop below.
6
+ // `value` + `onChange` in place of Vue's `v-model`.
7
+ //
8
+ // `split` (the default) is freeday's `.fdy-daterange` (src/components/datepicker.css): two linked
9
+ // FdyDatepickers where the end can't precede the start (start.max = end, end.min = start). The
10
+ // vanilla enhancer's cross-calendar `.in-range` shading is not reproduced there (each picker is
11
+ // independent); the min/max linkage is what keeps the range valid.
12
+ //
13
+ // `single` is ONE FdyDatepicker that draws the range itself, told so through the FdyRangeField
14
+ // context rather than a prop of its own. The first day picked is the start, the second the end, and
15
+ // the value changes only when the range is whole, so `onChange` and `onSettled` arrive together.
9
16
 
10
17
  export interface DateRangeValue {
11
18
  start: string | null;
12
19
  end: string | null;
13
20
  }
14
21
 
22
+ /** `split`: two linked pickers. `single`: one field, one calendar, both ends picked in it. */
23
+ export type FdyDateRangeLayout = 'split' | 'single';
24
+
15
25
  export interface FdyDateRangeProps {
16
26
  value: DateRangeValue;
27
+ /** `'split'` (default): two pickers. `'single'`: one field holding both dates. */
28
+ layout?: FdyDateRangeLayout;
29
+ /** The empty field's text under `layout="single"`. Default 'Select dates'. */
30
+ placeholder?: string;
31
+ /** Added to the accessible name of the range's first and last day under `layout="single"`, so
32
+ * an end is not told by colour alone. Defaults 'range start' / 'range end'. */
33
+ rangeStartLabel?: string;
34
+ rangeEndLabel?: string;
17
35
  onChange: (value: DateRangeValue) => void;
18
36
  /** Both ends chosen, or both cleared: the only states worth reloading a list for (#063). */
19
37
  onSettled?: (value: DateRangeValue) => void;
@@ -55,6 +73,44 @@ export function FdyDateRange(props: FdyDateRangeProps): JSX.Element {
55
73
  const onStart = (start: string): void => commit({ start, end: props.value.end });
56
74
  const onEnd = (end: string): void => commit({ start: props.value.start, end });
57
75
 
76
+ if (props.layout === 'single') {
77
+ const field: FdyRangeFieldContext = {
78
+ start: props.value.start,
79
+ end: props.value.end,
80
+ ariaLabel: props.ariaLabel,
81
+ rangeStartLabel: props.rangeStartLabel ?? 'range start',
82
+ rangeEndLabel: props.rangeEndLabel ?? 'range end',
83
+ commit: (start: string, end: string): void => commit({ start, end }),
84
+ };
85
+ return (
86
+ <FdyRangeField.Provider value={field}>
87
+ <FdyDatepicker
88
+ value={props.value.start}
89
+ /* Never called: under the range context the picker commits through `field.commit`. */
90
+ onChange={(): void => undefined}
91
+ min={props.min}
92
+ max={props.max}
93
+ locale={props.locale}
94
+ disabled={props.disabled}
95
+ readonly={props.readonly}
96
+ invalid={props.invalid}
97
+ required={props.required}
98
+ describedby={props.describedby}
99
+ ariaLabelledby={props.ariaLabelledby}
100
+ placeholder={props.placeholder ?? 'Select dates'}
101
+ prevMonthLabel={props.prevMonthLabel}
102
+ nextMonthLabel={props.nextMonthLabel}
103
+ prevYearLabel={props.prevYearLabel}
104
+ nextYearLabel={props.nextYearLabel}
105
+ prevYearsLabel={props.prevYearsLabel}
106
+ nextYearsLabel={props.nextYearsLabel}
107
+ chooseMonthLabel={props.chooseMonthLabel}
108
+ chooseYearLabel={props.chooseYearLabel}
109
+ />
110
+ </FdyRangeField.Provider>
111
+ );
112
+ }
113
+
58
114
  return (
59
115
  <div
60
116
  className="fdy-daterange"