@finstack-com-public/design 0.8.0 → 0.9.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.
@@ -1,6 +1,7 @@
1
1
  // Calendar: year, month and day views (spec 02 B, 03 §3.2, 06 §4; D42). The second helper that
2
2
  // builds its own markup, after the toaster: the cells change with every view and page. Dates are
3
- // ISO strings (`calendar-dates.ts`); every name and word is passed in.
3
+ // ISO strings (`calendar-dates.ts`); every name and word is passed in. `mode: 'range'` picks a start
4
+ // and an end with the same grid (T85), and `months: 2` shows two pages of the lowest view side by side.
4
5
  import { createIcon } from "../icons/index.js";
5
6
  import { addDays, addMonths, addYears, clampIso, daysInMonth, formatDay, formatMonth, localToday, monthGrid, parseDay, parseMonth, weekday, yearPage, } from "./calendar-dates.js";
6
7
  const VIEWS = {
@@ -11,18 +12,30 @@ const VIEWS = {
11
12
  const WIDTH = { day: 10, month: 7, year: 4 };
12
13
  const mod = (a, b) => ((a % b) + b) % b;
13
14
  let seq = 0;
14
- /** `root` is an empty `.fs-calendar` element; the helper renders the header and the grid into it. */
15
15
  export function createCalendar(root, options) {
16
16
  const doc = root.ownerDocument;
17
- const headingId = root.id ? `${root.id}-heading` : `fs-calendar-${++seq}-heading`;
17
+ const idBase = root.id || `fs-calendar-${++seq}`;
18
+ const headingId = `${idBase}-heading`;
19
+ const captionId = `${idBase}-caption`;
20
+ const isRange = options.mode === 'range';
18
21
  let opts = check({ granularity: 'day', weekStart: 1, ...options });
22
+ /** Single mode's value. */
19
23
  let value = null;
24
+ /** Range mode's ends; `end` is null while the second pick is pending. */
25
+ let start = null;
26
+ let end = null;
27
+ /** The lowest-view cell under the pointer, for the range preview. */
28
+ let hoverIso = null;
29
+ /** Whether a cell has focus, for the range preview. */
30
+ let gridFocused = false;
20
31
  let min;
21
32
  let max;
22
33
  let today = '';
23
34
  let view = opts.granularity ?? 'day';
24
35
  /** The cell with the tab stop, always at the granularity, whatever the view. */
25
36
  let focusIso = '';
37
+ /** A value on the first page shown; the others follow it. Empty: the focus's page. */
38
+ let pageStart = '';
26
39
  let lastHeading = '';
27
40
  let cellValues = new Map();
28
41
  const lowest = () => opts.granularity;
@@ -42,18 +55,37 @@ export function createCalendar(root, options) {
42
55
  return undefined;
43
56
  return formatDay(m.year, m.month, edge === 'first' ? 1 : daysInMonth(m.year, m.month));
44
57
  }
58
+ /** A range's ends at the granularity, in order; no start, no range. */
59
+ function readRange(v) {
60
+ const r = v && typeof v === 'object' ? v : null;
61
+ const s = read(r?.start, 'first') ?? null;
62
+ const e = read(r?.end, 'last') ?? null;
63
+ if (s === null)
64
+ return [null, null];
65
+ return e !== null && e < s ? [e, s] : [s, e];
66
+ }
45
67
  function readAll(next, first) {
46
68
  const granularityChanged = !first && next.granularity !== undefined && next.granularity !== lowest();
47
69
  opts = check({ ...opts, ...next });
70
+ if (isRange && !(opts.labels.rangeStart && opts.labels.rangeEnd)) {
71
+ throw new TypeError('[fs] createCalendar: a range needs labels.rangeStart and labels.rangeEnd');
72
+ }
48
73
  min = read(opts.min, 'first');
49
74
  max = read(opts.max, 'last');
50
75
  today = read(opts.today) ?? localToday(lowest());
51
- if (first || granularityChanged || 'value' in next)
52
- value = read(opts.value) ?? null;
76
+ if (first || granularityChanged || 'value' in next) {
77
+ if (isRange)
78
+ [start, end] = readRange(opts.value);
79
+ else
80
+ value = read(opts.value) ?? null;
81
+ hoverIso = null;
82
+ }
53
83
  if (first || granularityChanged)
54
84
  view = lowest();
55
- if (first || granularityChanged || 'value' in next || !focusIso)
56
- focusIso = clampIso(value ?? today, min, max);
85
+ if (first || granularityChanged || 'value' in next || !focusIso) {
86
+ focusIso = clampIso((isRange ? start : value) ?? today, min, max);
87
+ pageStart = '';
88
+ }
57
89
  }
58
90
  // The header, built once: its buttons keep focus across pages.
59
91
  const header = doc.createElement('div');
@@ -69,13 +101,24 @@ export function createCalendar(root, options) {
69
101
  const next = button('fs-icon-button fs-calendar__next');
70
102
  next.append(createIcon('chevron-right', { size: 16, document: doc }));
71
103
  header.append(viewButton, prev, next);
72
- const grid = doc.createElement('div');
73
- grid.setAttribute('role', 'grid');
104
+ /** The second page's heading, over its grid (two months, lowest view only). Not a control. */
105
+ const caption = doc.createElement('span');
106
+ caption.className = 'fs-calendar__caption';
107
+ caption.id = captionId;
108
+ const makeGrid = (labelledBy) => {
109
+ const g = doc.createElement('div');
110
+ g.setAttribute('role', 'grid');
111
+ g.setAttribute('aria-labelledby', labelledBy);
112
+ return g;
113
+ };
114
+ const grids = [makeGrid(headingId), makeGrid(captionId)];
115
+ /** Holds the grids when `months: 2`, so the calendar keeps its width in every view. */
116
+ const monthsEl = doc.createElement('div');
117
+ monthsEl.className = 'fs-calendar__months';
74
118
  /** The fallback live region, when the host passes no `announcer` (spec 06 §5). */
75
119
  const live = doc.createElement('span');
76
120
  live.className = 'fs-visually-hidden fs-calendar__live';
77
121
  live.setAttribute('aria-live', 'polite');
78
- grid.setAttribute('aria-labelledby', headingId);
79
122
  function button(className) {
80
123
  const b = doc.createElement('button');
81
124
  b.type = 'button';
@@ -119,17 +162,68 @@ export function createCalendar(root, options) {
119
162
  function settle(iso) {
120
163
  return pageOpen(pageOf(view, iso)) ? iso : clampIso(iso, min, max);
121
164
  }
122
- /** A cell button; only a day cell gets an aria-label (its full date), the others their text. */
165
+ /** How many pages the current view shows. */
166
+ const pages = () => (view === lowest() && opts.months === 2 ? 2 : 1);
167
+ /** Keeps the focus on a page shown: pages forward or back only when it leaves them. */
168
+ function follow() {
169
+ const n = pages();
170
+ if (n === 1 || !pageStart) {
171
+ pageStart = focusIso;
172
+ return;
173
+ }
174
+ const key = (iso) => pageRange(pageOf(view, iso))[0];
175
+ const f = key(focusIso);
176
+ if (f < key(pageStart))
177
+ pageStart = focusIso;
178
+ else if (f > key(page(view, pageStart, n - 1)))
179
+ pageStart = page(view, focusIso, 1 - n);
180
+ }
181
+ /** A cell's place in the range, compared on the cell's own width. */
182
+ function rangeRole(n, iso) {
183
+ if (!isRange || start === null)
184
+ return undefined;
185
+ const s = start.slice(0, n);
186
+ const e = (end ?? start).slice(0, n);
187
+ if (iso < s || iso > e)
188
+ return undefined;
189
+ if (s === e)
190
+ return end === null ? 'start' : 'both';
191
+ return iso === s ? 'start' : iso === e ? 'end' : 'inside';
192
+ }
193
+ /**
194
+ * A cell button; only a day cell gets an aria-label (its full date), the others are named by their
195
+ * text. In range mode the start and end words (`labels.rangeStart`, `rangeEnd`) follow the name: in
196
+ * a day's aria-label, else in a visually hidden span after the visible text, so the name always
197
+ * holds the text (WCAG 2.5.3) and a range is never colour alone.
198
+ */
123
199
  function makeCell(v, iso, text, label) {
124
200
  const el = button('fs-calendar__cell');
125
201
  el.setAttribute('role', 'gridcell');
126
202
  el.textContent = text;
127
- if (label !== undefined)
128
- el.setAttribute('aria-label', label);
129
203
  const n = WIDTH[v];
204
+ const role = rangeRole(n, iso);
205
+ const { rangeStart, rangeEnd } = opts.labels;
206
+ const said = role === 'start' ? [rangeStart] : role === 'end' ? [rangeEnd] : role === 'both' ? [rangeStart, rangeEnd] : [];
207
+ const suffix = said.map((w) => `, ${w}`).join('');
208
+ if (label !== undefined)
209
+ el.setAttribute('aria-label', label + suffix);
210
+ else if (suffix) {
211
+ const hidden = doc.createElement('span');
212
+ hidden.className = 'fs-visually-hidden';
213
+ hidden.textContent = suffix;
214
+ el.append(hidden);
215
+ }
130
216
  el.tabIndex = focusIso.slice(0, n) === iso ? 0 : -1;
131
- if (value !== null && value.slice(0, n) === iso)
217
+ if (isRange ? role !== undefined : value !== null && value.slice(0, n) === iso) {
132
218
  el.setAttribute('aria-selected', 'true');
219
+ }
220
+ // The band's shape: square where a cell meets the next one in the range.
221
+ if (role === 'inside')
222
+ el.classList.add('fs-calendar__cell--range');
223
+ else if (role === 'start' && end !== null)
224
+ el.classList.add('fs-calendar__cell--range-start');
225
+ else if (role === 'end')
226
+ el.classList.add('fs-calendar__cell--range-end');
133
227
  if (today.slice(0, n) === iso)
134
228
  el.setAttribute('aria-current', 'date');
135
229
  if (!enabled(v, iso))
@@ -150,11 +244,9 @@ export function createCalendar(root, options) {
150
244
  el.append(...children);
151
245
  return el;
152
246
  }
153
- function render(focusGrid = false) {
154
- const hadFocus = focusGrid || grid.contains(rootNode().activeElement);
155
- const current = pageOf(view, focusIso);
247
+ /** The rows of one page. */
248
+ function rowsOf(current) {
156
249
  const rows = [];
157
- cellValues = new Map();
158
250
  if (current.view === 'day') {
159
251
  const { year, month } = current;
160
252
  const ws = opts.weekStart;
@@ -190,15 +282,52 @@ export function createCalendar(root, options) {
190
282
  for (let i = 0; i < 12; i += 3)
191
283
  rows.push(row(units.slice(i, i + 3)));
192
284
  }
193
- grid.className = `fs-calendar__grid fs-calendar__grid--${view}`;
194
- grid.replaceChildren(...rows);
195
- const text = opts.heading(current);
196
- heading.textContent = text;
285
+ return rows;
286
+ }
287
+ /** Puts `children` into `parent` in order, touching nothing already in place. */
288
+ function place(parent, children) {
289
+ if (children.length !== parent.children.length || children.some((c, i) => parent.children[i] !== c)) {
290
+ parent.replaceChildren(...children);
291
+ }
292
+ }
293
+ function render(focusGrid = false) {
294
+ const hadFocus = focusGrid || grids.some((g) => g.contains(rootNode().activeElement));
295
+ follow();
296
+ const n = pages();
297
+ const shown = Array.from({ length: n }, (_, i) => pageOf(view, page(view, pageStart, i)));
298
+ cellValues = new Map();
299
+ shown.forEach((current, i) => {
300
+ grids[i].className = `fs-calendar__grid fs-calendar__grid--${view}`;
301
+ grids[i].replaceChildren(...rowsOf(current));
302
+ });
303
+ // One page: the grid straight after the header. Two: both in __months, which stays in every view.
304
+ if (opts.months === 2) {
305
+ grids[0].remove();
306
+ place(monthsEl, grids.slice(0, n));
307
+ if (header.nextElementSibling !== monthsEl)
308
+ header.after(monthsEl);
309
+ }
310
+ else {
311
+ monthsEl.remove();
312
+ if (header.nextElementSibling !== grids[0])
313
+ header.after(grids[0]);
314
+ }
315
+ if (n < 2)
316
+ grids[1].remove();
317
+ const texts = shown.map((p) => opts.heading(p));
318
+ heading.textContent = texts[0];
319
+ if (n === 2) {
320
+ caption.textContent = texts[1];
321
+ if (viewButton.nextElementSibling !== caption)
322
+ viewButton.after(caption);
323
+ }
324
+ else
325
+ caption.remove();
197
326
  const views = VIEWS[lowest()];
198
327
  const top = view === views[0];
199
328
  const up = view === 'year' ? undefined : opts.labels.up?.[view];
200
329
  if (up)
201
- viewButton.setAttribute('aria-label', `${text}, ${up}`);
330
+ viewButton.setAttribute('aria-label', `${texts[0]}, ${up}`);
202
331
  else
203
332
  viewButton.removeAttribute('aria-label');
204
333
  toggle(viewButton, 'aria-disabled', top);
@@ -208,10 +337,12 @@ export function createCalendar(root, options) {
208
337
  viewButton.append(viewIcon);
209
338
  prev.setAttribute('aria-label', opts.labels.prev[view]);
210
339
  next.setAttribute('aria-label', opts.labels.next[view]);
211
- toggle(prev, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, -1))) || isEdge(-1));
212
- toggle(next, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, 1))) || isEdge(1));
340
+ const last = page(view, pageStart, n - 1);
341
+ toggle(prev, 'aria-disabled', !pageOpen(pageOf(view, page(view, pageStart, -1))) || isEdge(pageStart, -1));
342
+ toggle(next, 'aria-disabled', !pageOpen(pageOf(view, page(view, last, 1))) || isEdge(last, 1));
213
343
  // Announce a new heading (paging, stepping), never the first one. Not from inside the view button:
214
344
  // a live region in a focused button whose name changes is read twice.
345
+ const text = texts.join(' – ');
215
346
  const out = opts.announcer ?? live;
216
347
  if (opts.announcer)
217
348
  live.remove();
@@ -220,12 +351,35 @@ export function createCalendar(root, options) {
220
351
  if (lastHeading && text !== lastHeading)
221
352
  out.textContent = text;
222
353
  lastHeading = text;
223
- if (hadFocus)
354
+ if (hadFocus) {
355
+ gridFocused = true;
224
356
  stopCell()?.focus();
357
+ }
358
+ paintPreview();
359
+ }
360
+ /**
361
+ * The range preview: while only the start is picked, the cells from it to the hovered cell (else
362
+ * the focused one, while the grid has focus) take `__cell--preview`. Classes only, no re-render.
363
+ */
364
+ function paintPreview() {
365
+ if (!isRange)
366
+ return;
367
+ let target = start !== null && end === null && view === lowest() ? (hoverIso ?? (gridFocused ? focusIso : null)) : null;
368
+ if (target !== null && !enabled(view, target))
369
+ target = null;
370
+ const [lo, hi] = target === null ? ['', ''] : target < start ? [target, start] : [start, target];
371
+ for (const [el, iso] of cellValues) {
372
+ el.classList.toggle('fs-calendar__cell--preview', target !== null && iso !== start && iso >= lo && iso <= hi);
373
+ }
225
374
  }
226
375
  /** At year 1 or 9999 paging goes nowhere. */
227
- function isEdge(dir) {
228
- return JSON.stringify(pageOf(view, page(view, focusIso, dir))) === JSON.stringify(pageOf(view, focusIso));
376
+ function isEdge(iso, dir) {
377
+ return JSON.stringify(pageOf(view, page(view, iso, dir))) === JSON.stringify(pageOf(view, iso));
378
+ }
379
+ /** Changes the view; the pages start again from the focus. */
380
+ function setViewTo(v) {
381
+ view = v;
382
+ pageStart = '';
229
383
  }
230
384
  function toggle(el, attr, on) {
231
385
  if (on)
@@ -246,8 +400,12 @@ export function createCalendar(root, options) {
246
400
  }
247
401
  return iso;
248
402
  }
249
- function moveTo(iso) {
403
+ /** Moves the focus; `pageTo` pages the pages shown too, so a pair pages together. */
404
+ function moveTo(iso, pageTo) {
250
405
  focusIso = settle(iso);
406
+ if (pageTo && pageStart)
407
+ pageStart = pageTo;
408
+ hoverIso = null; // the keyboard leads the preview now
251
409
  render(true);
252
410
  }
253
411
  function onKeydown(e) {
@@ -270,6 +428,7 @@ export function createCalendar(root, options) {
270
428
  return { back: index % 3, ahead: 2 - (index % 3) };
271
429
  };
272
430
  let to;
431
+ let pageTo;
273
432
  switch (e.key) {
274
433
  case 'ArrowRight':
275
434
  to = step(rtl ? -1 : 1);
@@ -292,14 +451,17 @@ export function createCalendar(root, options) {
292
451
  case 'PageUp':
293
452
  case 'PageDown': {
294
453
  const dir = e.key === 'PageUp' ? -1 : 1;
295
- to = e.shiftKey && view === 'day' ? addYears(focusIso, dir) : page(view, focusIso, dir);
454
+ const shift = (iso) => (e.shiftKey && view === 'day' ? addYears(iso, dir) : page(view, iso, dir));
455
+ to = shift(focusIso);
456
+ if (pageStart)
457
+ pageTo = shift(pageStart);
296
458
  break;
297
459
  }
298
460
  }
299
461
  if (to === undefined)
300
462
  return;
301
463
  e.preventDefault();
302
- moveTo(to);
464
+ moveTo(to, pageTo);
303
465
  }
304
466
  function onClick(e) {
305
467
  const target = e.target;
@@ -307,7 +469,7 @@ export function createCalendar(root, options) {
307
469
  const views = VIEWS[lowest()];
308
470
  const i = views.indexOf(view);
309
471
  if (i > 0) {
310
- view = views[i - 1];
472
+ setViewTo(views[i - 1]);
311
473
  render();
312
474
  }
313
475
  return;
@@ -319,6 +481,8 @@ export function createCalendar(root, options) {
319
481
  if (b.contains(target)) {
320
482
  if (b.getAttribute('aria-disabled') !== 'true') {
321
483
  focusIso = settle(page(view, focusIso, dir));
484
+ if (pageStart)
485
+ pageStart = page(view, pageStart, dir);
322
486
  render();
323
487
  }
324
488
  return;
@@ -328,6 +492,21 @@ export function createCalendar(root, options) {
328
492
  const iso = cell && cellValues.get(cell);
329
493
  if (!cell || !iso || cell.getAttribute('aria-disabled') === 'true')
330
494
  return;
495
+ if (view === lowest() && isRange) {
496
+ focusIso = iso;
497
+ // The first pick (or one after a complete range) is the start; the second the end, in order.
498
+ const completes = start !== null && end === null;
499
+ if (completes)
500
+ [start, end] = iso < start ? [iso, start] : [start, iso];
501
+ else
502
+ [start, end] = [iso, null];
503
+ render(true);
504
+ if (completes) {
505
+ const detail = { start: start, end: end };
506
+ root.dispatchEvent(new CustomEvent('fs-change', { bubbles: true, detail }));
507
+ }
508
+ return;
509
+ }
331
510
  if (view === lowest()) {
332
511
  value = iso;
333
512
  focusIso = iso;
@@ -337,24 +516,56 @@ export function createCalendar(root, options) {
337
516
  }
338
517
  focusIso = clampIso(onto(view, iso), min, max);
339
518
  const views = VIEWS[lowest()];
340
- view = views[views.indexOf(view) + 1];
519
+ setViewTo(views[views.indexOf(view) + 1]);
341
520
  render(true);
342
521
  }
343
522
  function onFocusin(e) {
344
523
  const iso = cellValues.get(e.target);
345
- if (iso === undefined || iso === focusIso.slice(0, WIDTH[view]))
524
+ if (iso === undefined)
525
+ return;
526
+ gridFocused = true;
527
+ if (iso !== focusIso.slice(0, WIDTH[view])) {
528
+ focusIso = onto(view, iso);
529
+ for (const el of cellValues.keys())
530
+ el.tabIndex = el === e.target ? 0 : -1;
531
+ }
532
+ paintPreview();
533
+ }
534
+ function onFocusout(e) {
535
+ if (!cellValues.has(e.target) || cellValues.has(e.relatedTarget))
536
+ return;
537
+ gridFocused = false;
538
+ paintPreview();
539
+ }
540
+ function onMouseover(e) {
541
+ const cell = e.target.closest?.('.fs-calendar__cell');
542
+ const iso = cell ? cellValues.get(cell) : undefined;
543
+ const over = iso !== undefined && view === lowest() ? iso : null;
544
+ if (over === hoverIso)
545
+ return;
546
+ hoverIso = over;
547
+ paintPreview();
548
+ }
549
+ function onMouseleave() {
550
+ if (hoverIso === null)
346
551
  return;
347
- focusIso = onto(view, iso);
348
- for (const el of cellValues.keys())
349
- el.tabIndex = el === e.target ? 0 : -1;
552
+ hoverIso = null;
553
+ paintPreview();
350
554
  }
555
+ const listeners = [
556
+ ['keydown', onKeydown],
557
+ ['click', onClick],
558
+ ['focusin', onFocusin],
559
+ ['focusout', onFocusout],
560
+ ['mouseover', onMouseover],
561
+ ['mouseleave', onMouseleave],
562
+ ];
351
563
  readAll(options, true);
352
- root.replaceChildren(header, grid);
564
+ root.replaceChildren(header);
353
565
  render();
354
- root.addEventListener('keydown', onKeydown);
355
- root.addEventListener('click', onClick);
356
- root.addEventListener('focusin', onFocusin);
357
- return {
566
+ for (const [type, fn] of listeners)
567
+ root.addEventListener(type, fn);
568
+ const controller = {
358
569
  get value() {
359
570
  return value;
360
571
  },
@@ -368,7 +579,7 @@ export function createCalendar(root, options) {
368
579
  setView(next) {
369
580
  if (!VIEWS[lowest()].includes(next))
370
581
  return;
371
- view = next;
582
+ setViewTo(next);
372
583
  render();
373
584
  },
374
585
  focus() {
@@ -379,13 +590,18 @@ export function createCalendar(root, options) {
379
590
  render();
380
591
  },
381
592
  destroy() {
382
- root.removeEventListener('keydown', onKeydown);
383
- root.removeEventListener('click', onClick);
384
- root.removeEventListener('focusin', onFocusin);
593
+ for (const [type, fn] of listeners)
594
+ root.removeEventListener(type, fn);
385
595
  root.replaceChildren();
386
596
  cellValues = new Map();
387
597
  },
388
598
  };
599
+ if (!isRange)
600
+ return controller;
601
+ // Range mode: the same controller, with the range as its value.
602
+ return Object.defineProperty(controller, 'value', {
603
+ get: () => (start === null ? null : { start, end }),
604
+ });
389
605
  }
390
606
  function check(o) {
391
607
  if (o.monthNames?.length !== 12)
@@ -1,4 +1,4 @@
1
- export { type Calendar, type CalendarChangeDetail, type CalendarDay, type CalendarLabels, type CalendarOptions, type CalendarPage, type CalendarView, createCalendar, type Granularity, } from './calendar.ts';
1
+ export { type Calendar, type CalendarChangeDetail, type CalendarDay, type CalendarLabels, type CalendarOptions, type CalendarPage, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels, type CalendarView, createCalendar, type Granularity, type RangeCalendar, type RangeCalendarOptions, } from './calendar.ts';
2
2
  export { createDialog, createSheet, type Dialog, type DialogCloseDetail, type DialogOptions } from './dialog.ts';
3
3
  export { createListbox, type Listbox, type ListboxOptions, type ListboxSelectDetail } from './listbox.ts';
4
4
  export { createLoader, type Loader, type LoaderOptions } from './loader.ts';
package/dist/kit.css CHANGED
@@ -1372,12 +1372,15 @@
1372
1372
  }
1373
1373
  }
1374
1374
 
1375
- /* Calendar (spec 02 B): year, month and day views. Usage: calendar.md. Behaviour: createCalendar,
1376
- which renders the header and the grid into an empty .fs-calendar (D42). */
1375
+ /* Calendar (spec 02 B): year, month and day views; one value or a range (T85), one page or two.
1376
+ Usage: calendar.md. Behaviour: createCalendar, which renders the header and the grid into an empty
1377
+ .fs-calendar (D42). */
1377
1378
  @layer fs.components {
1378
1379
  .fs-calendar {
1379
1380
  /* One cell's width: seven make the calendar, so it follows the density. */
1380
1381
  --fs-calendar-cell: var(--fs-control-h);
1382
+ /* Between two pages side by side (months: 2). */
1383
+ --fs-calendar-gap: var(--fs-space-4);
1381
1384
  display: inline-flex;
1382
1385
  flex-direction: column;
1383
1386
  gap: var(--fs-space-1);
@@ -1390,12 +1393,39 @@
1390
1393
  }
1391
1394
 
1392
1395
  .fs-calendar__header {
1396
+ position: relative;
1393
1397
  display: flex;
1394
1398
  align-items: center;
1395
1399
  gap: var(--fs-space-1);
1396
1400
  height: var(--fs-control-h);
1397
1401
  }
1398
1402
 
1403
+ /* Two pages side by side (months: 2): twice as wide in every view, so a popover never resizes. The
1404
+ higher views' one grid spans both columns. */
1405
+ .fs-calendar:has(> .fs-calendar__months) {
1406
+ width: calc(14 * var(--fs-calendar-cell) + var(--fs-calendar-gap));
1407
+ }
1408
+ .fs-calendar__months {
1409
+ display: grid;
1410
+ grid-template-columns: repeat(2, 1fr);
1411
+ column-gap: var(--fs-calendar-gap);
1412
+ }
1413
+ .fs-calendar__months > .fs-calendar__grid:only-child {
1414
+ grid-column: 1 / -1;
1415
+ }
1416
+
1417
+ /* The second page's heading, over its grid; the view button names the first. Not a control. */
1418
+ .fs-calendar__caption {
1419
+ position: absolute;
1420
+ inset-block: 0;
1421
+ inset-inline-start: calc(7 * var(--fs-calendar-cell) + var(--fs-calendar-gap));
1422
+ display: flex;
1423
+ align-items: center;
1424
+ padding: 0 var(--fs-pad-x);
1425
+ font-weight: var(--fs-weight-semibold);
1426
+ white-space: nowrap;
1427
+ }
1428
+
1399
1429
  /* Shows the page's heading; steps up a view. In the top view it is the heading alone. */
1400
1430
  .fs-calendar__view {
1401
1431
  display: inline-flex;
@@ -1475,6 +1505,9 @@
1475
1505
  .fs-calendar__cell[aria-selected='true']:not([aria-disabled='true']):hover {
1476
1506
  background-color: var(--fs-primary-bg-hover);
1477
1507
  }
1508
+ .fs-calendar__cell--range[aria-selected='true']:not([aria-disabled='true']):hover {
1509
+ background-color: var(--fs-bg-hover);
1510
+ }
1478
1511
  }
1479
1512
  .fs-calendar__view:not([aria-disabled='true']):active,
1480
1513
  .fs-calendar__cell:active {
@@ -1501,6 +1534,37 @@
1501
1534
  border-color: var(--fs-primary-ink);
1502
1535
  }
1503
1536
 
1537
+ /* A range (T85): start and end are filled as selected; the cells between are a band on the accent
1538
+ wash. Each end squares off where it meets the band, and the band's cells are square, so the band
1539
+ runs unbroken across a row. Start and end are also in the cells' names (cellLabel's range role). */
1540
+ .fs-calendar__cell--range-start {
1541
+ border-start-end-radius: 0;
1542
+ border-end-end-radius: 0;
1543
+ }
1544
+ .fs-calendar__cell--range-end {
1545
+ border-start-start-radius: 0;
1546
+ border-end-start-radius: 0;
1547
+ }
1548
+ .fs-calendar__cell--range[aria-selected='true'] {
1549
+ font-weight: inherit;
1550
+ color: var(--fs-ink);
1551
+ background-color: var(--fs-accent-wash);
1552
+ border-radius: 0;
1553
+ }
1554
+ .fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {
1555
+ border-color: var(--fs-accent);
1556
+ }
1557
+
1558
+ /* The preview, while only the start is picked: from the start to the hovered or focused cell, a
1559
+ dashed edge above and below, joined across the row. Not a fill: nothing is picked yet. */
1560
+ .fs-calendar__cell--preview::before {
1561
+ content: '';
1562
+ position: absolute;
1563
+ inset: 3px 0;
1564
+ border-block: var(--fs-line-width) dashed var(--fs-accent);
1565
+ pointer-events: none;
1566
+ }
1567
+
1504
1568
  /* The ring recipe (D15). The header's own button rings outside; cells touch, so theirs is inside. */
1505
1569
  .fs-calendar__view:focus-visible {
1506
1570
  outline: var(--fs-ring-width) solid var(--fs-ring);
@@ -1526,22 +1590,52 @@
1526
1590
  cursor: not-allowed;
1527
1591
  }
1528
1592
 
1529
- /* Forced colours: washes and fills are erased, so the selected cell takes the Highlight pair, today
1530
- keeps its edge (borders survive, in the system's colour) and disabled is GrayText. */
1593
+ /* Forced colours: washes and fills are erased, so the selected cell keeps CanvasText on Canvas (Firefox
1594
+ and WebKit repaint the background but keep the ink, so a Highlight pair fails contrast: I15) and is
1595
+ marked by a 2px Highlight edge inside the cell, as the segmented control does. Today keeps its edge
1596
+ (borders survive, in the system's colour), inset further when the cell is selected too. Disabled is
1597
+ GrayText. */
1531
1598
  @media (forced-colors: active) {
1532
1599
  .fs-calendar__cell[aria-selected='true'] {
1533
- color: HighlightText;
1534
- background-color: Highlight;
1600
+ color: CanvasText;
1601
+ background-color: Canvas;
1602
+ }
1603
+ .fs-calendar__cell[aria-selected='true']:not(.fs-calendar__cell--range)::before {
1604
+ content: '';
1605
+ position: absolute;
1606
+ inset: 0;
1607
+ border: 2px solid Highlight;
1608
+ border-radius: var(--fs-radius-sm);
1609
+ pointer-events: none;
1535
1610
  }
1536
1611
  .fs-calendar__cell[aria-current='date']::after {
1537
1612
  border-color: CanvasText;
1538
1613
  }
1539
- .fs-calendar__cell[aria-selected='true'][aria-current='date']::after {
1540
- border-color: HighlightText;
1614
+ .fs-calendar__cell[aria-selected='true'][aria-current='date']:not(.fs-calendar__cell--range)::after {
1615
+ inset: 4px;
1616
+ border-color: CanvasText;
1541
1617
  }
1542
1618
  .fs-calendar__cell[aria-disabled='true'] {
1543
1619
  color: GrayText;
1544
1620
  }
1621
+ /* The band keeps its shape as a Highlight edge above and below; start and end take the edge above. */
1622
+ .fs-calendar__cell--range[aria-selected='true'] {
1623
+ color: CanvasText;
1624
+ background-color: Canvas;
1625
+ }
1626
+ .fs-calendar__cell--range[aria-selected='true']::before {
1627
+ content: '';
1628
+ position: absolute;
1629
+ inset: 2px 0;
1630
+ border-block: var(--fs-line-width) solid Highlight;
1631
+ pointer-events: none;
1632
+ }
1633
+ .fs-calendar__cell--range[aria-selected='true'][aria-current='date']::after {
1634
+ border-color: CanvasText;
1635
+ }
1636
+ .fs-calendar__cell--preview::before {
1637
+ border-color: Highlight;
1638
+ }
1545
1639
  }
1546
1640
  }
1547
1641