rift-ds 1.24.0 → 1.25.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.
Files changed (99) hide show
  1. package/README.md +4 -4
  2. package/chat/ChatWidget.d.ts +5 -1
  3. package/chat/ChatWidget.js +12 -1
  4. package/components/Attachment/Attachment.css +8 -0
  5. package/components/Attachment/AttachmentViewer.js +26 -5
  6. package/components/Attachment/fileTypes.d.ts +4 -0
  7. package/components/CurrencyInput/CurrencyInput.css +12 -0
  8. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  9. package/components/CurrencyInput/CurrencyInput.js +158 -0
  10. package/components/DataTable/columnTypes.js +4 -16
  11. package/components/DatePicker/DatePicker.d.ts +2 -0
  12. package/components/DatePicker/DatePicker.js +44 -131
  13. package/components/DatePicker/MonthGrid.d.ts +56 -0
  14. package/components/DatePicker/MonthGrid.js +65 -0
  15. package/components/DatePicker/calendar.d.ts +42 -0
  16. package/components/DatePicker/calendar.js +108 -0
  17. package/components/DateRangePicker/DateRangePicker.css +92 -0
  18. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  19. package/components/DateRangePicker/DateRangePicker.js +294 -0
  20. package/components/Deadline/Deadline.css +82 -0
  21. package/components/Deadline/Deadline.d.ts +44 -0
  22. package/components/Deadline/Deadline.js +94 -0
  23. package/components/Deadline/deadlineStatus.d.ts +15 -0
  24. package/components/Deadline/deadlineStatus.js +13 -0
  25. package/components/DescriptionList/DescriptionList.css +184 -0
  26. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  27. package/components/DescriptionList/DescriptionList.js +100 -0
  28. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  29. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  30. package/components/DocumentViewer/DocumentViewer.css +188 -0
  31. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  32. package/components/DocumentViewer/DocumentViewer.js +185 -0
  33. package/components/ErrorSummary/ErrorSummary.css +94 -0
  34. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  35. package/components/ErrorSummary/ErrorSummary.js +70 -0
  36. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  37. package/components/ErrorSummary/fieldErrors.js +19 -0
  38. package/components/Field/Field.css +12 -0
  39. package/components/Field/Field.d.ts +10 -2
  40. package/components/Field/Field.js +12 -5
  41. package/components/Heading/Heading.css +129 -0
  42. package/components/Heading/Heading.d.ts +31 -0
  43. package/components/Heading/Heading.js +39 -0
  44. package/components/Input/Input.css +120 -0
  45. package/components/Input/Input.d.ts +20 -1
  46. package/components/Input/Input.js +70 -5
  47. package/components/Link/Link.css +84 -0
  48. package/components/Link/Link.d.ts +43 -0
  49. package/components/Link/Link.js +74 -0
  50. package/components/List/List.css +173 -0
  51. package/components/List/List.d.ts +44 -0
  52. package/components/List/List.js +60 -0
  53. package/components/MaskedInput/MaskedInput.css +16 -0
  54. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  55. package/components/MaskedInput/MaskedInput.js +142 -0
  56. package/components/MaskedInput/mask.d.ts +58 -0
  57. package/components/MaskedInput/mask.js +106 -0
  58. package/components/ShaderScene/ShaderScene.css +19 -0
  59. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  60. package/components/ShaderScene/ShaderScene.js +144 -0
  61. package/components/ShaderScene/assemble.d.ts +5 -0
  62. package/components/ShaderScene/assemble.js +74 -0
  63. package/components/ShaderScene/common.glsl.d.ts +6 -0
  64. package/components/ShaderScene/common.glsl.js +49 -0
  65. package/components/ShaderScene/passes.d.ts +2 -0
  66. package/components/ShaderScene/passes.js +93 -0
  67. package/components/ShaderScene/renderer.d.ts +35 -0
  68. package/components/ShaderScene/renderer.js +125 -0
  69. package/components/ShaderScene/scenes.d.ts +20 -0
  70. package/components/ShaderScene/scenes.js +184 -0
  71. package/components/ShaderScene/types.d.ts +70 -0
  72. package/components/ShaderScene/types.js +8 -0
  73. package/components/SignaturePad/SignaturePad.css +141 -0
  74. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  75. package/components/SignaturePad/SignaturePad.js +287 -0
  76. package/components/SignaturePad/signature.d.ts +32 -0
  77. package/components/SignaturePad/signature.js +46 -0
  78. package/components/Text/Text.css +129 -0
  79. package/components/Text/Text.d.ts +36 -0
  80. package/components/Text/Text.js +36 -0
  81. package/components/Widget/Widget.css +111 -0
  82. package/components/Widget/Widget.d.ts +15 -1
  83. package/components/Widget/Widget.js +63 -11
  84. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  85. package/components/Widget/WidgetDisclosure.js +52 -0
  86. package/components/registry.json +111 -2
  87. package/components/registry.json.d.ts +111 -2
  88. package/components/registry.json.js +2 -2
  89. package/format/index.d.ts +15 -0
  90. package/format/index.js +17 -0
  91. package/format/money.d.ts +89 -0
  92. package/format/money.js +187 -0
  93. package/format/relative.d.ts +49 -0
  94. package/format/relative.js +50 -0
  95. package/index.d.ts +13 -0
  96. package/index.js +46 -0
  97. package/package.json +9 -2
  98. package/tokens/motion.d.ts +4 -0
  99. package/tokens/motion.js +4 -0
@@ -4,53 +4,9 @@ import React, { useMemo, useState, useRef, useEffect } from "react";
4
4
  import "./DatePicker.css";
5
5
  import "../../fonts/material-symbols.css";
6
6
  import { useLocale } from "../../behaviors/LocaleProvider.js";
7
- import { weekStartOf, rotateWeek, isEnglish, weekdayNamesIn, weekdayOffset } from "../../behaviors/locale.js";
8
- import { logicalArrowKey } from "../../behaviors/direction.js";
9
- const EN_DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
10
- const weekdaysOr = (labels, fallback) => labels && labels.length === 7 ? labels : fallback;
11
- function parseDate(str) {
12
- if (!str) return null;
13
- const [y, m, d] = str.split("-").map(Number);
14
- return new Date(y, m - 1, d);
15
- }
16
- function formatDate(date) {
17
- const y = date.getFullYear();
18
- const m = String(date.getMonth() + 1).padStart(2, "0");
19
- const d = String(date.getDate()).padStart(2, "0");
20
- return `${y}-${m}-${d}`;
21
- }
22
- const visuallyHidden = {
23
- position: "absolute",
24
- width: 1,
25
- height: 1,
26
- padding: 0,
27
- margin: -1,
28
- overflow: "hidden",
29
- clip: "rect(0 0 0 0)",
30
- whiteSpace: "nowrap",
31
- border: 0
32
- };
33
- const monthLabelIn = (locale) => {
34
- const format = new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" });
35
- return (month) => format.format(month);
36
- };
37
- const dayLabelIn = (locale) => {
38
- const format = new Intl.DateTimeFormat(locale, {
39
- weekday: "long",
40
- year: "numeric",
41
- month: "long",
42
- day: "numeric"
43
- });
44
- return (date, selected) => `${format.format(date)}${selected ? ", selected" : ""}`;
45
- };
46
- function isSameDay(a, b) {
47
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
48
- }
49
- const addDays = (date, days) => new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);
50
- const addMonths = (date, months) => {
51
- const lastDay = new Date(date.getFullYear(), date.getMonth() + months + 1, 0).getDate();
52
- return new Date(date.getFullYear(), date.getMonth() + months, Math.min(date.getDate(), lastDay));
53
- };
7
+ import { weekStartOf, rotateWeek, isEnglish, weekdayNamesIn } from "../../behaviors/locale.js";
8
+ import { MonthGrid } from "./MonthGrid.js";
9
+ import { parseDate, monthLabelIn, dayLabelIn, weekdaysOr, EN_DAYS, formatDate, visuallyHidden, isSameDay, keyMove } from "./calendar.js";
54
10
  const DatePicker = React.forwardRef(
55
11
  ({
56
12
  value,
@@ -59,6 +15,7 @@ const DatePicker = React.forwardRef(
59
15
  min,
60
16
  max,
61
17
  onDateSelect,
18
+ isDateDisabled: isDateDisabledProp,
62
19
  previousLabel = "Previous month",
63
20
  nextLabel = "Next month",
64
21
  monthLabel: monthLabelProp,
@@ -110,21 +67,7 @@ const DatePicker = React.forwardRef(
110
67
  disabled ? `${baseClass}--disabled` : "",
111
68
  className
112
69
  ].filter(Boolean).join(" ");
113
- const firstDay = weekdayOffset(new Date(viewYear, viewMonth, 1).getDay(), weekStart);
114
70
  const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
115
- const daysInPrevMonth = new Date(viewYear, viewMonth, 0).getDate();
116
- const cells = [];
117
- for (let i = firstDay - 1; i >= 0; i--) {
118
- const d = daysInPrevMonth - i;
119
- cells.push({ day: d, inMonth: false, date: new Date(viewYear, viewMonth - 1, d) });
120
- }
121
- for (let d = 1; d <= daysInMonth; d++) {
122
- cells.push({ day: d, inMonth: true, date: new Date(viewYear, viewMonth, d) });
123
- }
124
- const remaining = 42 - cells.length;
125
- for (let d = 1; d <= remaining; d++) {
126
- cells.push({ day: d, inMonth: false, date: new Date(viewYear, viewMonth + 1, d) });
127
- }
128
71
  const goToPrevMonth = () => {
129
72
  if (viewMonth === 0) {
130
73
  setViewMonth(11);
@@ -145,6 +88,7 @@ const DatePicker = React.forwardRef(
145
88
  if (disabled) return true;
146
89
  if (minDate && date < minDate) return true;
147
90
  if (maxDate && date > maxDate) return true;
91
+ if (isDateDisabledProp?.(formatDate(date))) return true;
148
92
  return false;
149
93
  };
150
94
  const isInView = (date) => date.getMonth() === viewMonth && date.getFullYear() === viewYear;
@@ -169,35 +113,8 @@ const DatePicker = React.forwardRef(
169
113
  return date;
170
114
  };
171
115
  const handleDayKeyDown = (event, date) => {
172
- let next;
173
- switch (logicalArrowKey(event.key, event.currentTarget)) {
174
- case "ArrowLeft":
175
- next = addDays(date, -1);
176
- break;
177
- case "ArrowRight":
178
- next = addDays(date, 1);
179
- break;
180
- case "ArrowUp":
181
- next = addDays(date, -7);
182
- break;
183
- case "ArrowDown":
184
- next = addDays(date, 7);
185
- break;
186
- case "Home":
187
- next = addDays(date, -weekdayOffset(date.getDay(), weekStart));
188
- break;
189
- case "End":
190
- next = addDays(date, 6 - weekdayOffset(date.getDay(), weekStart));
191
- break;
192
- case "PageUp":
193
- next = addMonths(date, event.shiftKey ? -12 : -1);
194
- break;
195
- case "PageDown":
196
- next = addMonths(date, event.shiftKey ? 12 : 1);
197
- break;
198
- default:
199
- return;
200
- }
116
+ let next = keyMove(event, date, weekStart);
117
+ if (!next) return;
201
118
  event.preventDefault();
202
119
  next = clampToRange(next);
203
120
  if (isSameDay(next, date)) return;
@@ -210,8 +127,6 @@ const DatePicker = React.forwardRef(
210
127
  const date = new Date(viewYear, viewMonth, d);
211
128
  if (!isDateDisabled(date)) tabStop = date;
212
129
  }
213
- const weeks = [];
214
- for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
215
130
  return /* @__PURE__ */ jsxs("div", { ...rest, ref, className: classes, children: [
216
131
  /* @__PURE__ */ jsxs("div", { className: `${baseClass}__header`, children: [
217
132
  /* @__PURE__ */ jsx(
@@ -239,45 +154,43 @@ const DatePicker = React.forwardRef(
239
154
  )
240
155
  ] }),
241
156
  /* @__PURE__ */ jsx("span", { "aria-live": "polite", style: visuallyHidden, children: monthTitle }),
242
- /* @__PURE__ */ jsxs("div", { ref: gridRef, className: `${baseClass}__grid`, role: "grid", "aria-label": monthTitle, children: [
243
- /* @__PURE__ */ jsx("div", { className: `${baseClass}__row`, role: "row", children: weekdays.map((day, index) => /* @__PURE__ */ jsxs("div", { className: `${baseClass}__day-header`, role: "columnheader", children: [
244
- /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: day }),
245
- /* @__PURE__ */ jsx("span", { style: visuallyHidden, children: weekdayFullNames[index] })
246
- ] }, index)) }),
247
- weeks.map((week, weekIndex) => /* @__PURE__ */ jsx("div", { className: `${baseClass}__row`, role: "row", children: week.map((cell) => {
248
- const isSelected = selectedDate && isSameDay(cell.date, selectedDate);
249
- const isToday = isSameDay(cell.date, today);
250
- const isCellDisabled = isDateDisabled(cell.date);
251
- const isTabStop = tabStop !== null && isSameDay(cell.date, tabStop);
252
- const cellClasses = [
253
- `${baseClass}__cell`,
254
- !cell.inMonth ? `${baseClass}__cell--outside` : "",
255
- isSelected ? `${baseClass}__cell--selected` : "",
256
- isToday && !isSelected ? `${baseClass}__cell--today` : "",
257
- isCellDisabled ? `${baseClass}__cell--disabled` : ""
258
- ].filter(Boolean).join(" ");
259
- return /* @__PURE__ */ jsx("div", { className: `${baseClass}__gridcell`, role: "gridcell", children: /* @__PURE__ */ jsx(
260
- "button",
261
- {
262
- type: "button",
263
- className: cellClasses,
264
- onClick: () => handleSelect(cell),
265
- onKeyDown: (event) => handleDayKeyDown(event, cell.date),
266
- onFocus: () => {
267
- if (!focusedDate || !isSameDay(focusedDate, cell.date)) {
268
- setFocusedDate(cell.date);
269
- }
270
- },
271
- disabled: isCellDisabled,
272
- tabIndex: isTabStop ? 0 : -1,
273
- "data-date": formatDate(cell.date),
274
- "aria-label": dayLabel(cell.date, Boolean(isSelected)),
275
- "aria-current": isToday ? "date" : void 0,
276
- children: dayNumber.format(cell.day)
277
- }
278
- ) }, formatDate(cell.date));
279
- }) }, weekIndex))
280
- ] })
157
+ /* @__PURE__ */ jsx(
158
+ MonthGrid,
159
+ {
160
+ baseClass,
161
+ gridRef,
162
+ year: viewYear,
163
+ month: viewMonth,
164
+ weekStart,
165
+ weekdays,
166
+ weekdayFullNames,
167
+ label: monthTitle,
168
+ dayNumber,
169
+ today,
170
+ dayState: (cell) => {
171
+ const isSelected = Boolean(selectedDate && isSameDay(cell.date, selectedDate));
172
+ const isToday = isSameDay(cell.date, today);
173
+ return {
174
+ className: [
175
+ !cell.inMonth ? `${baseClass}__cell--outside` : "",
176
+ isSelected ? `${baseClass}__cell--selected` : "",
177
+ isToday && !isSelected ? `${baseClass}__cell--today` : "",
178
+ isDateDisabled(cell.date) ? `${baseClass}__cell--disabled` : ""
179
+ ].filter(Boolean).join(" "),
180
+ disabled: isDateDisabled(cell.date),
181
+ // Selection is spoken as part of the name rather than via
182
+ // aria-selected, which is not permitted on role="button".
183
+ label: dayLabel(cell.date, isSelected),
184
+ tabStop: tabStop !== null && isSameDay(cell.date, tabStop)
185
+ };
186
+ },
187
+ onSelect: handleSelect,
188
+ onDayKeyDown: handleDayKeyDown,
189
+ onDayFocus: (date) => {
190
+ if (!focusedDate || !isSameDay(focusedDate, date)) setFocusedDate(date);
191
+ }
192
+ }
193
+ )
281
194
  ] });
282
195
  }
283
196
  );
@@ -0,0 +1,56 @@
1
+ import { default as React } from 'react';
2
+ import { Weekday } from '../../behaviors/locale';
3
+ import { MonthCell } from './calendar';
4
+ /** What a host tells the grid about one day. */
5
+ export type DayState = {
6
+ /** Extra classes on the day's button. */
7
+ className: string;
8
+ /** Whether the day can be chosen. */
9
+ disabled: boolean;
10
+ /** The day button's accessible name. */
11
+ label: string;
12
+ /** Whether the day is the grid's one tab stop. */
13
+ tabStop: boolean;
14
+ /** `aria-selected` for the gridcell, when the host marks selection there. */
15
+ selected?: boolean;
16
+ };
17
+ /** Props for MonthGrid. */
18
+ export type MonthGridProps = {
19
+ /** The host's class prefix (`ds-date-picker`), so the grid draws in its family's classes. */
20
+ baseClass: string;
21
+ /** The grid element, for moving focus to a day. */
22
+ gridRef?: React.Ref<HTMLDivElement>;
23
+ /** The month and year in view. */
24
+ year: number;
25
+ month: number;
26
+ /** The first column. */
27
+ weekStart: Weekday;
28
+ /** The seven visible headers and their spoken names, already in the grid's order. */
29
+ weekdays: string[];
30
+ weekdayFullNames: string[];
31
+ /** The grid's accessible name: the month heading. */
32
+ label: string;
33
+ /** The day numbers' format. */
34
+ dayNumber: Intl.NumberFormat;
35
+ /** Today, for `aria-current="date"` and its ring. */
36
+ today: Date;
37
+ /** The state of each day. */
38
+ dayState: (cell: MonthCell) => DayState;
39
+ /** A day was pressed. */
40
+ onSelect: (cell: MonthCell) => void;
41
+ /** A key was pressed on a day. */
42
+ onDayKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>, date: Date) => void;
43
+ /** A day took focus. */
44
+ onDayFocus: (date: Date) => void;
45
+ /** The pointer moved onto a day, for a range preview. */
46
+ onDayPointerEnter?: (date: Date) => void;
47
+ /** Hide the days that belong to the neighbouring months (a second month beside the first). */
48
+ hideOutside?: boolean;
49
+ };
50
+ /**
51
+ * A WAI-ARIA date grid: a header row of column headers, then one row per
52
+ * week. The rows are subgrids of the one CSS grid, so the layout is seven
53
+ * columns. Each gridcell holds a real button; only the roving tab stop is in
54
+ * the tab order, and the host's key handler moves it.
55
+ */
56
+ export declare function MonthGrid({ baseClass, gridRef, year, month, weekStart, weekdays, weekdayFullNames, label, dayNumber, today, dayState, onSelect, onDayKeyDown, onDayFocus, onDayPointerEnter, hideOutside, }: MonthGridProps): React.JSX.Element;
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import "react";
4
+ import { monthWeeks, visuallyHidden, formatDate, isSameDay } from "./calendar.js";
5
+ function MonthGrid({
6
+ baseClass,
7
+ gridRef,
8
+ year,
9
+ month,
10
+ weekStart,
11
+ weekdays,
12
+ weekdayFullNames,
13
+ label,
14
+ dayNumber,
15
+ today,
16
+ dayState,
17
+ onSelect,
18
+ onDayKeyDown,
19
+ onDayFocus,
20
+ onDayPointerEnter,
21
+ hideOutside = false
22
+ }) {
23
+ const weeks = monthWeeks(year, month, weekStart);
24
+ return /* @__PURE__ */ jsxs("div", { ref: gridRef, className: `${baseClass}__grid`, role: "grid", "aria-label": label, children: [
25
+ /* @__PURE__ */ jsx("div", { className: `${baseClass}__row`, role: "row", children: weekdays.map((day, index) => /* @__PURE__ */ jsxs("div", { className: `${baseClass}__day-header`, role: "columnheader", children: [
26
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: day }),
27
+ /* @__PURE__ */ jsx("span", { style: visuallyHidden, children: weekdayFullNames[index] })
28
+ ] }, index)) }),
29
+ weeks.map((week, weekIndex) => /* @__PURE__ */ jsx("div", { className: `${baseClass}__row`, role: "row", children: week.map((cell) => {
30
+ if (hideOutside && !cell.inMonth)
31
+ return /* @__PURE__ */ jsx("div", { className: `${baseClass}__gridcell`, role: "gridcell" }, formatDate(cell.date));
32
+ const state = dayState(cell);
33
+ const isToday = isSameDay(cell.date, today);
34
+ return /* @__PURE__ */ jsx(
35
+ "div",
36
+ {
37
+ className: `${baseClass}__gridcell`,
38
+ role: "gridcell",
39
+ "aria-selected": state.selected,
40
+ children: /* @__PURE__ */ jsx(
41
+ "button",
42
+ {
43
+ type: "button",
44
+ className: [`${baseClass}__cell`, state.className].filter(Boolean).join(" "),
45
+ onClick: () => onSelect(cell),
46
+ onKeyDown: (event) => onDayKeyDown(event, cell.date),
47
+ onFocus: () => onDayFocus(cell.date),
48
+ onPointerEnter: onDayPointerEnter ? () => onDayPointerEnter(cell.date) : void 0,
49
+ disabled: state.disabled,
50
+ tabIndex: state.tabStop ? 0 : -1,
51
+ "data-date": formatDate(cell.date),
52
+ "aria-label": state.label,
53
+ "aria-current": isToday ? "date" : void 0,
54
+ children: dayNumber.format(cell.day)
55
+ }
56
+ )
57
+ },
58
+ formatDate(cell.date)
59
+ );
60
+ }) }, weekIndex))
61
+ ] });
62
+ }
63
+ export {
64
+ MonthGrid
65
+ };
@@ -0,0 +1,42 @@
1
+ import { default as React } from 'react';
2
+ import { Weekday } from '../../behaviors/locale';
3
+ /** The two-letter English headers, which Intl has no width for. */
4
+ export declare const EN_DAYS: string[];
5
+ /** A consumer's weekday list when it has the seven entries the grid needs, else the default. */
6
+ export declare const weekdaysOr: (labels: string[] | undefined, fallback: string[]) => string[];
7
+ /** A `YYYY-MM-DD` string as a local date, or null. */
8
+ export declare function parseDate(str?: string | null): Date | null;
9
+ /** A local date as `YYYY-MM-DD`. */
10
+ export declare function formatDate(date: Date): string;
11
+ /**
12
+ * Standard sr-only clip pattern, inline so no stylesheet change is needed.
13
+ * position: absolute takes the element out of flow, so it cannot affect
14
+ * layout; the 1px box + clip keep it invisible but still announced.
15
+ */
16
+ export declare const visuallyHidden: React.CSSProperties;
17
+ /** The month heading's default: the month and the year in `locale`. */
18
+ export declare const monthLabelIn: (locale: string) => (month: Date) => string;
19
+ /** A day's spoken name: the full date in `locale`. */
20
+ export declare const fullDateIn: (locale: string) => (date: Date) => string;
21
+ /** DatePicker's day label default: the full date, with ", selected" when it is. */
22
+ export declare const dayLabelIn: (locale: string) => (date: Date, selected: boolean) => string;
23
+ export declare function isSameDay(a: Date, b: Date): boolean;
24
+ export declare const addDays: (date: Date, days: number) => Date;
25
+ /** The same day of the month `months` away, pulled back to that month's last day when it is shorter. */
26
+ export declare const addMonths: (date: Date, months: number) => Date;
27
+ /** Whole days from `a` to `b`, counting calendar days so a clock change never shifts it. */
28
+ export declare const daysBetween: (a: Date, b: Date) => number;
29
+ /** One square of a month grid: the day, whether it belongs to the month in view, and its date. */
30
+ export type MonthCell = {
31
+ day: number;
32
+ inMonth: boolean;
33
+ date: Date;
34
+ };
35
+ /** A month as six weeks of seven, starting on `weekStart`, with the neighbouring months' days filling the edges. */
36
+ export declare function monthWeeks(year: number, month: number, weekStart: Weekday): MonthCell[][];
37
+ /**
38
+ * Where a key moves focus from `date` in a date grid: arrows a day or a
39
+ * week (along the reading direction), Home and End the ends of the week,
40
+ * Page Up and Page Down a month (a year with Shift). Null for any other key.
41
+ */
42
+ export declare function keyMove(event: React.KeyboardEvent<HTMLElement>, date: Date, weekStart: Weekday): Date | null;
@@ -0,0 +1,108 @@
1
+ import { weekdayOffset } from "../../behaviors/locale.js";
2
+ import { logicalArrowKey } from "../../behaviors/direction.js";
3
+ const EN_DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
4
+ const weekdaysOr = (labels, fallback) => labels && labels.length === 7 ? labels : fallback;
5
+ function parseDate(str) {
6
+ if (!str) return null;
7
+ const [y, m, d] = str.split("-").map(Number);
8
+ return new Date(y, m - 1, d);
9
+ }
10
+ function formatDate(date) {
11
+ const y = date.getFullYear();
12
+ const m = String(date.getMonth() + 1).padStart(2, "0");
13
+ const d = String(date.getDate()).padStart(2, "0");
14
+ return `${y}-${m}-${d}`;
15
+ }
16
+ const visuallyHidden = {
17
+ position: "absolute",
18
+ width: 1,
19
+ height: 1,
20
+ padding: 0,
21
+ margin: -1,
22
+ overflow: "hidden",
23
+ clip: "rect(0 0 0 0)",
24
+ whiteSpace: "nowrap",
25
+ border: 0
26
+ };
27
+ const monthLabelIn = (locale) => {
28
+ const format = new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" });
29
+ return (month) => format.format(month);
30
+ };
31
+ const fullDateIn = (locale) => {
32
+ const format = new Intl.DateTimeFormat(locale, {
33
+ weekday: "long",
34
+ year: "numeric",
35
+ month: "long",
36
+ day: "numeric"
37
+ });
38
+ return (date) => format.format(date);
39
+ };
40
+ const dayLabelIn = (locale) => {
41
+ const full = fullDateIn(locale);
42
+ return (date, selected) => `${full(date)}${selected ? ", selected" : ""}`;
43
+ };
44
+ function isSameDay(a, b) {
45
+ return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
46
+ }
47
+ const addDays = (date, days) => new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);
48
+ const addMonths = (date, months) => {
49
+ const lastDay = new Date(date.getFullYear(), date.getMonth() + months + 1, 0).getDate();
50
+ return new Date(date.getFullYear(), date.getMonth() + months, Math.min(date.getDate(), lastDay));
51
+ };
52
+ const daysBetween = (a, b) => Math.round(
53
+ (Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()) - Date.UTC(a.getFullYear(), a.getMonth(), a.getDate())) / 864e5
54
+ );
55
+ function monthWeeks(year, month, weekStart) {
56
+ const firstDay = weekdayOffset(new Date(year, month, 1).getDay(), weekStart);
57
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
58
+ const daysInPrevMonth = new Date(year, month, 0).getDate();
59
+ const cells = [];
60
+ for (let i = firstDay - 1; i >= 0; i--) {
61
+ const d = daysInPrevMonth - i;
62
+ cells.push({ day: d, inMonth: false, date: new Date(year, month - 1, d) });
63
+ }
64
+ for (let d = 1; d <= daysInMonth; d++) cells.push({ day: d, inMonth: true, date: new Date(year, month, d) });
65
+ const remaining = 42 - cells.length;
66
+ for (let d = 1; d <= remaining; d++) cells.push({ day: d, inMonth: false, date: new Date(year, month + 1, d) });
67
+ const weeks = [];
68
+ for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
69
+ return weeks;
70
+ }
71
+ function keyMove(event, date, weekStart) {
72
+ switch (logicalArrowKey(event.key, event.currentTarget)) {
73
+ case "ArrowLeft":
74
+ return addDays(date, -1);
75
+ case "ArrowRight":
76
+ return addDays(date, 1);
77
+ case "ArrowUp":
78
+ return addDays(date, -7);
79
+ case "ArrowDown":
80
+ return addDays(date, 7);
81
+ case "Home":
82
+ return addDays(date, -weekdayOffset(date.getDay(), weekStart));
83
+ case "End":
84
+ return addDays(date, 6 - weekdayOffset(date.getDay(), weekStart));
85
+ case "PageUp":
86
+ return addMonths(date, event.shiftKey ? -12 : -1);
87
+ case "PageDown":
88
+ return addMonths(date, event.shiftKey ? 12 : 1);
89
+ default:
90
+ return null;
91
+ }
92
+ }
93
+ export {
94
+ EN_DAYS,
95
+ addDays,
96
+ addMonths,
97
+ dayLabelIn,
98
+ daysBetween,
99
+ formatDate,
100
+ fullDateIn,
101
+ isSameDay,
102
+ keyMove,
103
+ monthLabelIn,
104
+ monthWeeks,
105
+ parseDate,
106
+ visuallyHidden,
107
+ weekdaysOr
108
+ };
@@ -0,0 +1,92 @@
1
+ /* ============================================
2
+ DATE RANGE PICKER
3
+ A member of the DatePicker family: the root,
4
+ the header, the grid and the day cells are
5
+ DatePicker's own classes and stylesheet. This
6
+ sheet adds only what a range needs: months
7
+ side by side that wrap when the picker is
8
+ narrow, the band between the two chosen ends
9
+ in the passive selection wash, and the preset
10
+ chips above, which wrap.
11
+ ============================================ */
12
+
13
+ /* Layout */
14
+ .ds-date-range-picker {
15
+ max-inline-size: 100%;
16
+ box-sizing: border-box;
17
+ }
18
+
19
+ .ds-date-range-picker__months {
20
+ display: flex;
21
+ flex-wrap: wrap;
22
+ gap: var(--gap-500);
23
+ }
24
+
25
+ .ds-date-range-picker__month {
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: var(--gap-200);
29
+ }
30
+
31
+ .ds-date-range-picker--compact .ds-date-range-picker__month {
32
+ gap: var(--gap-050);
33
+ }
34
+
35
+ /* Holds the header's balance where a month has no turn button of its own. */
36
+ .ds-date-range-picker__nav-space {
37
+ inline-size: var(--control-height-compact);
38
+ flex-shrink: 0;
39
+ }
40
+
41
+ .ds-date-range-picker--compact .ds-date-range-picker__nav-space {
42
+ inline-size: var(--icon-size-800);
43
+ }
44
+
45
+ .ds-date-range-picker__presets {
46
+ display: flex;
47
+ flex-wrap: wrap;
48
+ gap: var(--gap-100);
49
+ }
50
+
51
+ /* The band: no gaps between days, so the span reads as one run */
52
+ .ds-date-range-picker .ds-date-picker__grid,
53
+ .ds-date-range-picker .ds-date-picker__row {
54
+ column-gap: 0;
55
+ }
56
+
57
+ .ds-date-range-picker__cell--in-range {
58
+ border-radius: 0;
59
+ background-color: var(--color-action-passive-bg-active);
60
+ }
61
+
62
+ .ds-date-range-picker__cell--in-range:hover:not(:disabled) {
63
+ background-color: var(--color-action-passive-bg-hover);
64
+ }
65
+
66
+ /* A preview while the end is being chosen: the same band, outlined rather than filled. */
67
+ .ds-date-range-picker__cell--preview {
68
+ background-color: var(--color-action-passive-bg-hover);
69
+ }
70
+
71
+ .ds-date-range-picker__cell--preview-end {
72
+ border: var(--border-025) dashed var(--color-action-primary-border);
73
+ }
74
+
75
+ /* The band runs into each chosen end: half its cell, on the side facing the span. */
76
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--start) {
77
+ background: linear-gradient(to right, transparent 50%, var(--color-action-passive-bg-active) 50%); /* ds-allow(physical): a gradient has no logical direction; the rule below turns it round right to left */
78
+ }
79
+
80
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--start):dir(rtl) {
81
+ background: linear-gradient(to left, transparent 50%, var(--color-action-passive-bg-active) 50%); /* ds-allow(physical): the right-to-left twin of the rule above */
82
+ }
83
+
84
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--end),
85
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--preview-end) {
86
+ background: linear-gradient(to left, transparent 50%, var(--color-action-passive-bg-active) 50%); /* ds-allow(physical): a gradient has no logical direction; the rule below turns it round right to left */
87
+ }
88
+
89
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--end):dir(rtl),
90
+ .ds-date-picker__gridcell:has(> .ds-date-range-picker__cell--preview-end):dir(rtl) {
91
+ background: linear-gradient(to right, transparent 50%, var(--color-action-passive-bg-active) 50%); /* ds-allow(physical): the right-to-left twin of the rule above */
92
+ }