rift-ds 1.23.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 (124) hide show
  1. package/README.md +4 -4
  2. package/behaviors/shell.css +119 -0
  3. package/bin/templates/blocks/components/blocks/AppShell.module.css +69 -15
  4. package/bin/templates/blocks/components/blocks/AppShell.tsx +45 -30
  5. package/bin/templates/blocks/registry.json +1 -1
  6. package/chat/ChatAgentPane.css +6 -6
  7. package/chat/ChatLauncher.d.ts +3 -3
  8. package/chat/ChatWidget.css +260 -8
  9. package/chat/ChatWidget.d.ts +41 -6
  10. package/chat/ChatWidget.js +49 -2
  11. package/chat/index.d.ts +1 -1
  12. package/chat/registry.json.d.ts +1 -1
  13. package/chat/registry.json.js +1 -1
  14. package/components/AppLayout/AppLayout.css +17 -4
  15. package/components/AppLayout/AppLayout.d.ts +8 -5
  16. package/components/AppLayout/AppLayout.js +2 -0
  17. package/components/AppSidebar/AppSidebar.css +108 -23
  18. package/components/AppSidebar/AppSidebar.d.ts +8 -5
  19. package/components/AppSidebar/AppSidebar.js +6 -3
  20. package/components/Attachment/Attachment.css +8 -0
  21. package/components/Attachment/AttachmentViewer.js +26 -5
  22. package/components/Attachment/fileTypes.d.ts +4 -0
  23. package/components/CurrencyInput/CurrencyInput.css +12 -0
  24. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  25. package/components/CurrencyInput/CurrencyInput.js +158 -0
  26. package/components/DataTable/columnTypes.js +4 -16
  27. package/components/DatePicker/DatePicker.d.ts +2 -0
  28. package/components/DatePicker/DatePicker.js +44 -131
  29. package/components/DatePicker/MonthGrid.d.ts +56 -0
  30. package/components/DatePicker/MonthGrid.js +65 -0
  31. package/components/DatePicker/calendar.d.ts +42 -0
  32. package/components/DatePicker/calendar.js +108 -0
  33. package/components/DateRangePicker/DateRangePicker.css +92 -0
  34. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  35. package/components/DateRangePicker/DateRangePicker.js +294 -0
  36. package/components/Deadline/Deadline.css +82 -0
  37. package/components/Deadline/Deadline.d.ts +44 -0
  38. package/components/Deadline/Deadline.js +94 -0
  39. package/components/Deadline/deadlineStatus.d.ts +15 -0
  40. package/components/Deadline/deadlineStatus.js +13 -0
  41. package/components/DescriptionList/DescriptionList.css +184 -0
  42. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  43. package/components/DescriptionList/DescriptionList.js +100 -0
  44. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  45. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  46. package/components/DocumentViewer/DocumentViewer.css +188 -0
  47. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  48. package/components/DocumentViewer/DocumentViewer.js +185 -0
  49. package/components/ErrorSummary/ErrorSummary.css +94 -0
  50. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  51. package/components/ErrorSummary/ErrorSummary.js +70 -0
  52. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  53. package/components/ErrorSummary/fieldErrors.js +19 -0
  54. package/components/Field/Field.css +12 -0
  55. package/components/Field/Field.d.ts +10 -2
  56. package/components/Field/Field.js +12 -5
  57. package/components/Heading/Heading.css +129 -0
  58. package/components/Heading/Heading.d.ts +31 -0
  59. package/components/Heading/Heading.js +39 -0
  60. package/components/Input/Input.css +120 -0
  61. package/components/Input/Input.d.ts +20 -1
  62. package/components/Input/Input.js +70 -5
  63. package/components/Link/Link.css +84 -0
  64. package/components/Link/Link.d.ts +43 -0
  65. package/components/Link/Link.js +74 -0
  66. package/components/List/List.css +173 -0
  67. package/components/List/List.d.ts +44 -0
  68. package/components/List/List.js +60 -0
  69. package/components/MaskedInput/MaskedInput.css +16 -0
  70. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  71. package/components/MaskedInput/MaskedInput.js +142 -0
  72. package/components/MaskedInput/mask.d.ts +58 -0
  73. package/components/MaskedInput/mask.js +106 -0
  74. package/components/ShaderScene/ShaderScene.css +19 -0
  75. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  76. package/components/ShaderScene/ShaderScene.js +144 -0
  77. package/components/ShaderScene/assemble.d.ts +5 -0
  78. package/components/ShaderScene/assemble.js +74 -0
  79. package/components/ShaderScene/common.glsl.d.ts +6 -0
  80. package/components/ShaderScene/common.glsl.js +49 -0
  81. package/components/ShaderScene/passes.d.ts +2 -0
  82. package/components/ShaderScene/passes.js +93 -0
  83. package/components/ShaderScene/renderer.d.ts +35 -0
  84. package/components/ShaderScene/renderer.js +125 -0
  85. package/components/ShaderScene/scenes.d.ts +20 -0
  86. package/components/ShaderScene/scenes.js +184 -0
  87. package/components/ShaderScene/types.d.ts +70 -0
  88. package/components/ShaderScene/types.js +8 -0
  89. package/components/SignaturePad/SignaturePad.css +141 -0
  90. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  91. package/components/SignaturePad/SignaturePad.js +287 -0
  92. package/components/SignaturePad/signature.d.ts +32 -0
  93. package/components/SignaturePad/signature.js +46 -0
  94. package/components/Text/Text.css +129 -0
  95. package/components/Text/Text.d.ts +36 -0
  96. package/components/Text/Text.js +36 -0
  97. package/components/ThemePicker/ThemePicker.css +6 -0
  98. package/components/ThemePicker/ThemePicker.js +20 -11
  99. package/components/ThreadPanel/ThreadPanel.css +65 -36
  100. package/components/ThreadPanel/ThreadPanel.d.ts +5 -5
  101. package/components/ThreadPanel/ThreadPanel.js +1 -1
  102. package/components/Widget/Widget.css +111 -0
  103. package/components/Widget/Widget.d.ts +15 -1
  104. package/components/Widget/Widget.js +63 -11
  105. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  106. package/components/Widget/WidgetDisclosure.js +52 -0
  107. package/components/registry.json +112 -3
  108. package/components/registry.json.d.ts +112 -3
  109. package/components/registry.json.js +2 -2
  110. package/format/index.d.ts +15 -0
  111. package/format/index.js +17 -0
  112. package/format/money.d.ts +89 -0
  113. package/format/money.js +187 -0
  114. package/format/relative.d.ts +49 -0
  115. package/format/relative.js +50 -0
  116. package/index.d.ts +13 -0
  117. package/index.js +46 -0
  118. package/package.json +9 -2
  119. package/tokens/motion.d.ts +4 -0
  120. package/tokens/motion.js +4 -0
  121. package/tokens/presets/plum.css +234 -240
  122. package/tokens/tokens-dark.css +2 -2
  123. package/tokens/tokens-light.css +2 -2
  124. package/tokens/values.json.js +1 -1
@@ -0,0 +1,86 @@
1
+ import { default as React } from 'react';
2
+ import { Weekday } from '../../behaviors/locale';
3
+ /** A range as two `YYYY-MM-DD` strings; `end` is null while the second day is still to be chosen. */
4
+ export type DateRange = {
5
+ start: string | null;
6
+ end: string | null;
7
+ };
8
+ /** A ready-made range the reader can pick in one press. */
9
+ export type DateRangePreset = {
10
+ /** What the preset is called: "Last 7 days", "This month". */
11
+ label: string;
12
+ /** The range it sets. */
13
+ range: {
14
+ start: string;
15
+ end: string;
16
+ };
17
+ };
18
+ /** Where a day sits in the range, for its spoken name. */
19
+ export type DateRangePosition = 'start' | 'end' | 'start-end' | 'inside' | 'outside';
20
+ /** Props owned by DateRangePicker itself; everything else falls through to the wrapper. */
21
+ type DateRangePickerOwnProps = {
22
+ /** The chosen range (controlled). Pair with `onValueChange`. */
23
+ value?: DateRange;
24
+ /** The range it starts with (uncontrolled). */
25
+ defaultValue?: DateRange;
26
+ /** Called with the range as the reader chooses it: once with only `start` after the first day, then with both. */
27
+ onValueChange?: (range: DateRange) => void;
28
+ /** How many months show side by side, 1 or 2. Two stack when the picker is narrow. Defaults to 2. */
29
+ months?: 1 | 2;
30
+ /** The first day that can be chosen (YYYY-MM-DD). */
31
+ min?: string;
32
+ /** The last day that can be chosen (YYYY-MM-DD). */
33
+ max?: string;
34
+ /** Mark further days unavailable: weekends, holidays, booked nights. Given each day as a `YYYY-MM-DD` string. A range may not span one. */
35
+ isDateDisabled?: (date: string) => boolean;
36
+ /** The fewest days a range may hold, counting both ends. */
37
+ minLength?: number;
38
+ /** The most days a range may hold, counting both ends. */
39
+ maxLength?: number;
40
+ /** Ranges the reader can pick in one press, shown above the calendar: "Last 7 days", "This quarter". */
41
+ presets?: DateRangePreset[];
42
+ /** Accessible name of the presets. Defaults to "Presets". */
43
+ presetsLabel?: string;
44
+ /** Component size */
45
+ size?: 'default' | 'compact';
46
+ /** Whether the picker is disabled */
47
+ disabled?: boolean;
48
+ /** The form field name: the form receives `<name>[start]` and `<name>[end]` as `YYYY-MM-DD` through hidden inputs. */
49
+ name?: string;
50
+ /** Accessible name of the previous-month button. */
51
+ previousLabel?: string;
52
+ /** Accessible name of the next-month button. */
53
+ nextLabel?: string;
54
+ /** The month heading, given the first day of a month in view. Defaults to the month name and the year in `locale`. */
55
+ monthLabel?: (month: Date) => string;
56
+ /** A day button's accessible name, given its date and where it sits in the range. Defaults to the full date in `locale`, followed by the matching position label. */
57
+ dayLabel?: (date: Date, position: DateRangePosition) => string;
58
+ /** Said after the first day of the range. Defaults to "start of range". */
59
+ rangeStartLabel?: string;
60
+ /** Said after the last day of the range. Defaults to "end of range". */
61
+ rangeEndLabel?: string;
62
+ /** Said after a day inside the range. Defaults to "in range". */
63
+ inRangeLabel?: string;
64
+ /** The visible weekday headers: seven entries, Sunday first. Defaults as in DatePicker. */
65
+ weekdayLabels?: string[];
66
+ /** The weekday headers' spoken names: seven entries, Sunday first. Defaults to the weekday names in `locale`. */
67
+ weekdayNames?: string[];
68
+ /** The BCP 47 locale the calendar is written and laid out in. Defaults to the nearest LocaleProvider's, else `en-US`. */
69
+ locale?: string;
70
+ /** The first column of the grid, 0 (Sunday) to 6 (Saturday). Defaults to the first day of the week in `locale`. */
71
+ weekStartsOn?: Weekday;
72
+ /** Additional CSS classes */
73
+ className?: string;
74
+ };
75
+ export interface DateRangePickerProps extends DateRangePickerOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof DateRangePickerOwnProps> {
76
+ }
77
+ /**
78
+ * An inline calendar for choosing a range of days: a billing period, a
79
+ * report's window, a booking, a leave request. The first press sets the
80
+ * start, the second the end, with the days between previewed as the pointer
81
+ * or the focus moves; presets set a range in one press. Keyboard as
82
+ * DatePicker: arrows, Home and End, Page Up and Page Down move, Enter or
83
+ * Space chooses.
84
+ */
85
+ export declare function DateRangePicker({ value: valueProp, defaultValue, onValueChange, months, min, max, isDateDisabled: isDateDisabledProp, minLength, maxLength, presets, presetsLabel, size, disabled, name, previousLabel, nextLabel, monthLabel: monthLabelProp, dayLabel: dayLabelProp, rangeStartLabel, rangeEndLabel, inRangeLabel, weekdayLabels, weekdayNames, locale: localeProp, weekStartsOn, className, onPointerLeave, ref, ...rest }: DateRangePickerProps): React.JSX.Element;
86
+ export {};
@@ -0,0 +1,294 @@
1
+ "use client";
2
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
+ import { useState, useMemo, useRef, useEffect } from "react";
4
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
5
+ import { weekStartOf, rotateWeek, isEnglish, weekdayNamesIn } from "../../behaviors/locale.js";
6
+ import { MonthGrid } from "../DatePicker/MonthGrid.js";
7
+ import { parseDate, monthLabelIn, fullDateIn, weekdaysOr, EN_DAYS, formatDate, isSameDay, visuallyHidden, addMonths, keyMove, daysBetween } from "../DatePicker/calendar.js";
8
+ import { Chip } from "../Chip/Chip.js";
9
+ import "../DatePicker/DatePicker.css";
10
+ import "../../fonts/material-symbols.css";
11
+ import "./DateRangePicker.css";
12
+ const EMPTY = { start: null, end: null };
13
+ function DateRangePicker({
14
+ value: valueProp,
15
+ defaultValue = EMPTY,
16
+ onValueChange,
17
+ months = 2,
18
+ min,
19
+ max,
20
+ isDateDisabled: isDateDisabledProp,
21
+ minLength,
22
+ maxLength,
23
+ presets,
24
+ presetsLabel = "Presets",
25
+ size = "default",
26
+ disabled = false,
27
+ name,
28
+ previousLabel = "Previous month",
29
+ nextLabel = "Next month",
30
+ monthLabel: monthLabelProp,
31
+ dayLabel: dayLabelProp,
32
+ rangeStartLabel = "start of range",
33
+ rangeEndLabel = "end of range",
34
+ inRangeLabel = "in range",
35
+ weekdayLabels,
36
+ weekdayNames,
37
+ locale: localeProp,
38
+ weekStartsOn,
39
+ className = "",
40
+ onPointerLeave,
41
+ ref,
42
+ ...rest
43
+ }) {
44
+ const locale = useLocale(localeProp);
45
+ const weekStart = weekStartsOn ?? weekStartOf(locale);
46
+ const controlled = valueProp !== void 0;
47
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
48
+ const range = controlled ? valueProp : uncontrolled;
49
+ const start = parseDate(range.start);
50
+ const end = parseDate(range.end);
51
+ const minDate = parseDate(min);
52
+ const maxDate = parseDate(max);
53
+ const dayNumber = useMemo(() => new Intl.NumberFormat(locale), [locale]);
54
+ const monthLabel = useMemo(() => monthLabelProp ?? monthLabelIn(locale), [monthLabelProp, locale]);
55
+ const fullDate = useMemo(() => fullDateIn(locale), [locale]);
56
+ const weekdays = rotateWeek(
57
+ weekdaysOr(weekdayLabels, isEnglish(locale) ? EN_DAYS : weekdayNamesIn(locale, "short")),
58
+ weekStart
59
+ );
60
+ const weekdayFullNames = rotateWeek(weekdaysOr(weekdayNames, weekdayNamesIn(locale, "long")), weekStart);
61
+ const today = useMemo(() => /* @__PURE__ */ new Date(), []);
62
+ const initial = start ?? today;
63
+ const [view, setView] = useState({ year: initial.getFullYear(), month: initial.getMonth() });
64
+ const [focusedDate, setFocusedDate] = useState(null);
65
+ const [hoverDate, setHoverDate] = useState(null);
66
+ const pendingFocus = useRef(false);
67
+ const rootRef = useRef(null);
68
+ const setRef = (node) => {
69
+ rootRef.current = node;
70
+ if (typeof ref === "function") ref(node);
71
+ else if (ref) ref.current = node;
72
+ };
73
+ useEffect(() => {
74
+ if (!pendingFocus.current || !focusedDate) return;
75
+ pendingFocus.current = false;
76
+ rootRef.current?.querySelector(`[data-date="${formatDate(focusedDate)}"]`)?.focus();
77
+ }, [focusedDate, view]);
78
+ const shown = Array.from({ length: months }, (_, i) => {
79
+ const first = new Date(view.year, view.month + i, 1);
80
+ return { year: first.getFullYear(), month: first.getMonth() };
81
+ });
82
+ const firstShown = new Date(shown[0].year, shown[0].month, 1);
83
+ const lastShown = new Date(shown[months - 1].year, shown[months - 1].month + 1, 0);
84
+ const isInView = (date) => date >= firstShown && date <= lastShown;
85
+ const titles = shown.map(({ year, month }) => monthLabel(new Date(year, month, 1)));
86
+ const choosingEnd = Boolean(start && !end);
87
+ const blocked = (date) => disabled || minDate !== null && date < minDate || maxDate !== null && date > maxDate || Boolean(isDateDisabledProp?.(formatDate(date)));
88
+ const rangeRefused = (a, b) => {
89
+ const length = daysBetween(a, b) + 1;
90
+ if (minLength !== void 0 && length < minLength) return true;
91
+ if (maxLength !== void 0 && length > maxLength) return true;
92
+ if (isDateDisabledProp) {
93
+ for (let d = new Date(a); d <= b; d = new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1))
94
+ if (isDateDisabledProp(formatDate(d))) return true;
95
+ }
96
+ return false;
97
+ };
98
+ const isDayDisabled = (date) => {
99
+ if (blocked(date)) return true;
100
+ if (choosingEnd && start && date >= start) return rangeRefused(start, date);
101
+ return false;
102
+ };
103
+ const commit = (next) => {
104
+ if (!controlled) setUncontrolled(next);
105
+ onValueChange?.(next);
106
+ };
107
+ const choose = (date) => {
108
+ if (isDayDisabled(date)) return;
109
+ if (!choosingEnd || !start || date < start) {
110
+ commit({ start: formatDate(date), end: null });
111
+ return;
112
+ }
113
+ commit({ start: formatDate(start), end: formatDate(date) });
114
+ setHoverDate(null);
115
+ };
116
+ const moveFocusTo = (date) => {
117
+ if (!isInView(date)) {
118
+ const offset = date < firstShown ? 0 : months - 1;
119
+ const first = new Date(date.getFullYear(), date.getMonth() - offset, 1);
120
+ setView({ year: first.getFullYear(), month: first.getMonth() });
121
+ }
122
+ setFocusedDate(date);
123
+ if (choosingEnd) setHoverDate(date);
124
+ pendingFocus.current = true;
125
+ };
126
+ const clampToRange = (date) => {
127
+ if (minDate && date < minDate) return minDate;
128
+ if (maxDate && date > maxDate) return maxDate;
129
+ return date;
130
+ };
131
+ const handleDayKeyDown = (event, date) => {
132
+ let next = keyMove(event, date, weekStart);
133
+ if (!next) return;
134
+ event.preventDefault();
135
+ next = clampToRange(next);
136
+ if (isSameDay(next, date)) return;
137
+ moveFocusTo(next);
138
+ };
139
+ const handleSelect = (cell) => {
140
+ if (!cell.inMonth) moveFocusTo(cell.date);
141
+ choose(cell.date);
142
+ };
143
+ const previewEnd = choosingEnd && hoverDate && start && hoverDate >= start ? hoverDate : null;
144
+ const spanEnd = end ?? previewEnd;
145
+ const positionOf = (date) => {
146
+ if (!start) return "outside";
147
+ const isStart = isSameDay(date, start);
148
+ const isEnd = end ? isSameDay(date, end) : false;
149
+ if (isStart && (isEnd || !end)) return end ? "start-end" : "start";
150
+ if (isStart) return "start";
151
+ if (isEnd) return "end";
152
+ if (end && date > start && date < end) return "inside";
153
+ return "outside";
154
+ };
155
+ const dayLabel = dayLabelProp ?? ((date, position) => {
156
+ const where = position === "start" ? rangeStartLabel : position === "end" ? rangeEndLabel : position === "start-end" ? `${rangeStartLabel}, ${rangeEndLabel}` : position === "inside" ? inRangeLabel : "";
157
+ return where ? `${fullDate(date)}, ${where}` : fullDate(date);
158
+ });
159
+ let tabStop = [focusedDate, start, today].find(
160
+ (date) => date !== null && isInView(date) && !isDayDisabled(date)
161
+ ) ?? null;
162
+ for (let d = new Date(firstShown); !tabStop && d <= lastShown; d = new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1)) {
163
+ if (!isDayDisabled(d)) tabStop = d;
164
+ }
165
+ const activePreset = presets?.findIndex((p) => p.range.start === range.start && p.range.end === range.end) ?? -1;
166
+ const applyPreset = (index) => {
167
+ const preset = presets?.[index];
168
+ if (!preset) return;
169
+ commit({ start: preset.range.start, end: preset.range.end });
170
+ const first = parseDate(preset.range.start);
171
+ if (first) setView({ year: first.getFullYear(), month: first.getMonth() });
172
+ };
173
+ const baseClass = "ds-date-picker";
174
+ const classes = [
175
+ "ds-date-range-picker",
176
+ `ds-date-range-picker--months-${months}`,
177
+ baseClass,
178
+ `${baseClass}--${size}`,
179
+ disabled ? `${baseClass}--disabled` : "",
180
+ className
181
+ ].filter(Boolean).join(" ");
182
+ const turn = (by) => {
183
+ const first = addMonths(new Date(view.year, view.month, 1), by);
184
+ setView({ year: first.getFullYear(), month: first.getMonth() });
185
+ };
186
+ return /* @__PURE__ */ jsxs(
187
+ "div",
188
+ {
189
+ ...rest,
190
+ ref: setRef,
191
+ className: classes,
192
+ onPointerLeave: (event) => {
193
+ setHoverDate(null);
194
+ onPointerLeave?.(event);
195
+ },
196
+ children: [
197
+ presets && presets.length > 0 && /* @__PURE__ */ jsx("div", { className: "ds-date-range-picker__presets", role: "group", "aria-label": presetsLabel, children: presets.map((preset, index) => /* @__PURE__ */ jsx(
198
+ Chip,
199
+ {
200
+ label: preset.label,
201
+ tone: "neutral",
202
+ selected: index === activePreset,
203
+ disabled,
204
+ onClick: () => applyPreset(index)
205
+ },
206
+ preset.label
207
+ )) }),
208
+ /* @__PURE__ */ jsx("div", { className: "ds-date-range-picker__months", children: shown.map(({ year, month }, index) => /* @__PURE__ */ jsxs("div", { className: "ds-date-range-picker__month", children: [
209
+ /* @__PURE__ */ jsxs("div", { className: `${baseClass}__header`, children: [
210
+ index === 0 ? /* @__PURE__ */ jsx(
211
+ "button",
212
+ {
213
+ type: "button",
214
+ className: `${baseClass}__nav-btn material-symbols-rounded ds-mirror-rtl`,
215
+ onClick: () => turn(-1),
216
+ disabled,
217
+ "aria-label": previousLabel,
218
+ children: "chevron_left"
219
+ }
220
+ ) : /* @__PURE__ */ jsx("span", { className: "ds-date-range-picker__nav-space", "aria-hidden": "true" }),
221
+ /* @__PURE__ */ jsx("span", { className: `${baseClass}__month-year`, children: titles[index] }),
222
+ index === months - 1 ? /* @__PURE__ */ jsx(
223
+ "button",
224
+ {
225
+ type: "button",
226
+ className: `${baseClass}__nav-btn material-symbols-rounded ds-mirror-rtl`,
227
+ onClick: () => turn(1),
228
+ disabled,
229
+ "aria-label": nextLabel,
230
+ children: "chevron_right"
231
+ }
232
+ ) : /* @__PURE__ */ jsx("span", { className: "ds-date-range-picker__nav-space", "aria-hidden": "true" })
233
+ ] }),
234
+ /* @__PURE__ */ jsx(
235
+ MonthGrid,
236
+ {
237
+ baseClass,
238
+ year,
239
+ month,
240
+ weekStart,
241
+ weekdays,
242
+ weekdayFullNames,
243
+ label: titles[index],
244
+ dayNumber,
245
+ today,
246
+ hideOutside: months > 1,
247
+ dayState: (cell) => {
248
+ const position = positionOf(cell.date);
249
+ const chosenEnd = position === "start" || position === "end" || position === "start-end";
250
+ const inSpan = Boolean(start && spanEnd && cell.date > start && cell.date < spanEnd);
251
+ const isToday = isSameDay(cell.date, today);
252
+ const dayDisabled = isDayDisabled(cell.date);
253
+ return {
254
+ className: [
255
+ !cell.inMonth ? `${baseClass}__cell--outside` : "",
256
+ chosenEnd ? `${baseClass}__cell--selected` : "",
257
+ inSpan ? "ds-date-range-picker__cell--in-range" : "",
258
+ inSpan && !end ? "ds-date-range-picker__cell--preview" : "",
259
+ position === "start" && spanEnd ? "ds-date-range-picker__cell--start" : "",
260
+ position === "end" ? "ds-date-range-picker__cell--end" : "",
261
+ previewEnd && isSameDay(cell.date, previewEnd) && !chosenEnd ? "ds-date-range-picker__cell--preview-end" : "",
262
+ isToday && !chosenEnd ? `${baseClass}__cell--today` : "",
263
+ dayDisabled ? `${baseClass}__cell--disabled` : ""
264
+ ].filter(Boolean).join(" "),
265
+ disabled: dayDisabled,
266
+ label: dayLabel(cell.date, position),
267
+ tabStop: tabStop !== null && isSameDay(cell.date, tabStop),
268
+ selected: position !== "outside"
269
+ };
270
+ },
271
+ onSelect: handleSelect,
272
+ onDayKeyDown: handleDayKeyDown,
273
+ onDayFocus: (date) => {
274
+ if (!focusedDate || !isSameDay(focusedDate, date)) setFocusedDate(date);
275
+ if (choosingEnd) setHoverDate(date);
276
+ },
277
+ onDayPointerEnter: (date) => {
278
+ if (choosingEnd) setHoverDate(date);
279
+ }
280
+ }
281
+ )
282
+ ] }, `${year}-${month}`)) }),
283
+ /* @__PURE__ */ jsx("span", { "aria-live": "polite", style: visuallyHidden, children: titles.join(", ") }),
284
+ name && /* @__PURE__ */ jsxs(Fragment, { children: [
285
+ /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[start]`, value: range.start ?? "", disabled }),
286
+ /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[end]`, value: range.end ?? "", disabled })
287
+ ] })
288
+ ]
289
+ }
290
+ );
291
+ }
292
+ export {
293
+ DateRangePicker
294
+ };
@@ -0,0 +1,82 @@
1
+ /* ============================================
2
+ DEADLINE
3
+ The Badge family's tinted pill (status fill and
4
+ text, the badge's radius and inset), or the
5
+ status text colour alone inline. The status is
6
+ the deadline's distance from now: neutral, then
7
+ warning, then error, and error once it passes.
8
+ ============================================ */
9
+
10
+ /* Base */
11
+ .ds-deadline {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ white-space: nowrap;
15
+ font-variant-numeric: tabular-nums;
16
+ }
17
+
18
+ .ds-deadline time {
19
+ font: inherit;
20
+ }
21
+
22
+ /* Badge */
23
+ .ds-deadline--badge {
24
+ box-sizing: border-box;
25
+ padding: var(--padding-050) var(--padding-200);
26
+ border: var(--border-025) solid transparent;
27
+ border-radius: var(--radius-100);
28
+ font-family: var(--font-paragraph-sm-emphasis-family);
29
+ font-size: var(--font-paragraph-sm-emphasis-size);
30
+ font-weight: var(--font-paragraph-sm-emphasis-weight);
31
+ line-height: var(--font-paragraph-sm-emphasis-line-height);
32
+ letter-spacing: var(--font-paragraph-sm-emphasis-letter-spacing);
33
+ }
34
+
35
+ .ds-deadline--badge.ds-deadline--compact {
36
+ padding: 0 var(--padding-150);
37
+ font-size: var(--font-caption-size);
38
+ line-height: var(--font-caption-line-height);
39
+ }
40
+
41
+ .ds-deadline--badge.ds-deadline--neutral {
42
+ background-color: var(--color-status-neutral-bg);
43
+ color: var(--color-status-neutral-text);
44
+ }
45
+
46
+ .ds-deadline--badge.ds-deadline--warning {
47
+ background-color: var(--color-status-warning-bg);
48
+ color: var(--color-status-warning-text);
49
+ }
50
+
51
+ .ds-deadline--badge.ds-deadline--error {
52
+ background-color: var(--color-status-error-bg);
53
+ color: var(--color-status-error-text);
54
+ }
55
+
56
+ /* Text: inline in a sentence or a cell */
57
+ .ds-deadline--text {
58
+ font-family: inherit;
59
+ font-size: inherit;
60
+ line-height: inherit;
61
+ }
62
+
63
+ .ds-deadline--text.ds-deadline--compact {
64
+ font-size: var(--font-paragraph-sm-size);
65
+ line-height: var(--font-paragraph-sm-line-height);
66
+ }
67
+
68
+ .ds-deadline--text.ds-deadline--neutral {
69
+ color: var(--color-text-secondary);
70
+ }
71
+
72
+ .ds-deadline--text.ds-deadline--warning {
73
+ color: var(--color-status-warning-text);
74
+ }
75
+
76
+ .ds-deadline--text.ds-deadline--error {
77
+ color: var(--color-status-error-text);
78
+ }
79
+
80
+ .ds-deadline--text.ds-deadline--overdue {
81
+ font-weight: var(--font-paragraph-emphasis-weight);
82
+ }
@@ -0,0 +1,44 @@
1
+ import { default as React } from 'react';
2
+ import { DateInput } from '../../format/relative';
3
+ import { DeadlineStatus, DeadlineThresholds } from './deadlineStatus';
4
+ /** Props owned by Deadline itself; everything else falls through to the root `<span>`. */
5
+ type DeadlineOwnProps = {
6
+ /** The moment it falls due: a Date, an ISO 8601 string or milliseconds since the epoch. */
7
+ date: DateInput;
8
+ /** The IANA zone the time is shown in, named after it ("4:00 PM PST"), such as `America/Los_Angeles`. Without it the time shows in the reader's own zone. */
9
+ timeZone?: string;
10
+ /** `relative` writes the distance ("in 2 days"), `absolute` the date and time, `both` the two together. Defaults to `relative`. */
11
+ display?: 'relative' | 'absolute' | 'both';
12
+ /** How close the deadline must be before it turns to the warning and then the error role. */
13
+ thresholds?: DeadlineThresholds;
14
+ /** The word before the distance: "Due", "Closes", "Expires". Defaults to "Due". */
15
+ prefixLabel?: string;
16
+ /** What a deadline that has passed says in place of the distance. Defaults to "Overdue". */
17
+ overdueLabel?: string;
18
+ /** `badge` draws the Badge family's tinted pill; `text` writes it inline in the status text colour, for a sentence or a table cell. */
19
+ variant?: 'badge' | 'text';
20
+ /** Component size */
21
+ size?: 'default' | 'compact';
22
+ /** Rewrite the distance as time passes, pausing while the page is hidden. Defaults to true; off when `now` is set. */
23
+ tick?: boolean;
24
+ /** The moment to measure from, in place of the clock: for a server render that must match, a test, or a screenshot. */
25
+ now?: DateInput;
26
+ /** Called when the deadline moves to a new status as time passes, so a host can react (sort, notify). */
27
+ onStatusChange?: (status: DeadlineStatus) => void;
28
+ /** The BCP 47 locale the distance and the date are written in. Defaults to the nearest LocaleProvider's, else `en-US`. */
29
+ locale?: string;
30
+ /** Additional CSS classes */
31
+ className?: string;
32
+ };
33
+ export interface DeadlineProps extends DeadlineOwnProps, Omit<React.ComponentPropsWithRef<'span'>, keyof DeadlineOwnProps | 'children'> {
34
+ }
35
+ /**
36
+ * A deadline against now: "Due in 2 days", turning to the warning role as it
37
+ * nears and the error role on its last day, then "Overdue". Submission
38
+ * cutoffs, invoice due dates, trial expiry, ticket service levels. The full
39
+ * date sits in a `<time>` element, and the distance rewrites itself every
40
+ * half minute while the page shows.
41
+ */
42
+ export declare function Deadline({ date, timeZone, display, thresholds, prefixLabel, overdueLabel, variant, size, tick, now: nowProp, onStatusChange, locale: localeProp, className, ref, ...rest }: DeadlineProps): React.JSX.Element | null;
43
+ export { deadlineStatus } from './deadlineStatus';
44
+ export type { DeadlineStatus, DeadlineThresholds } from './deadlineStatus';
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useRef, useEffect, useState } from "react";
4
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
5
+ import { MOTION_DEADLINE_TICK_MS } from "../../tokens/motion.js";
6
+ import { toDate, formatInTimeZone, formatRelative } from "../../format/relative.js";
7
+ import { deadlineStatus } from "./deadlineStatus.js";
8
+ import "./Deadline.css";
9
+ function useNow(fixed, tick) {
10
+ const [clock, setClock] = useState(() => /* @__PURE__ */ new Date());
11
+ useEffect(() => {
12
+ if (fixed || !tick) return;
13
+ let timer;
14
+ const start = () => {
15
+ window.clearInterval(timer);
16
+ setClock(/* @__PURE__ */ new Date());
17
+ timer = window.setInterval(() => setClock(/* @__PURE__ */ new Date()), MOTION_DEADLINE_TICK_MS);
18
+ };
19
+ const onVisibility = () => {
20
+ if (document.hidden) window.clearInterval(timer);
21
+ else start();
22
+ };
23
+ start();
24
+ document.addEventListener("visibilitychange", onVisibility);
25
+ return () => {
26
+ window.clearInterval(timer);
27
+ document.removeEventListener("visibilitychange", onVisibility);
28
+ };
29
+ }, [fixed, tick]);
30
+ return fixed ?? clock;
31
+ }
32
+ function Deadline({
33
+ date,
34
+ timeZone,
35
+ display = "relative",
36
+ thresholds,
37
+ prefixLabel = "Due",
38
+ overdueLabel = "Overdue",
39
+ variant = "badge",
40
+ size = "default",
41
+ tick = true,
42
+ now: nowProp,
43
+ onStatusChange,
44
+ locale: localeProp,
45
+ className = "",
46
+ ref,
47
+ ...rest
48
+ }) {
49
+ const locale = useLocale(localeProp);
50
+ const due = toDate(date);
51
+ const fixed = nowProp !== void 0 ? toDate(nowProp) : null;
52
+ const now = useNow(fixed, tick);
53
+ const status = due ? deadlineStatus(due, now, thresholds) : "neutral";
54
+ const reported = useRef(status);
55
+ useEffect(() => {
56
+ if (reported.current === status) return;
57
+ reported.current = status;
58
+ onStatusChange?.(status);
59
+ }, [status, onStatusChange]);
60
+ if (!due) return null;
61
+ const zone = timeZone ?? new Intl.DateTimeFormat(locale).resolvedOptions().timeZone;
62
+ const absolute = formatInTimeZone(due, {
63
+ locale,
64
+ timeZone: zone,
65
+ month: "short",
66
+ day: "numeric",
67
+ hour: "numeric",
68
+ minute: "2-digit",
69
+ ...timeZone ? { timeZoneName: "short" } : {}
70
+ });
71
+ const full = formatInTimeZone(due, {
72
+ locale,
73
+ timeZone: zone,
74
+ dateStyle: "full",
75
+ timeStyle: "long"
76
+ });
77
+ const relative = formatRelative(due, { now, locale });
78
+ const overdue = status === "overdue";
79
+ const lead = overdue ? overdueLabel : prefixLabel;
80
+ const text = display === "absolute" ? `${lead} ${absolute}` : display === "both" ? `${overdue ? lead : `${lead} ${relative}`} · ${absolute}` : overdue ? lead : `${lead} ${relative}`;
81
+ const classes = [
82
+ "ds-deadline",
83
+ `ds-deadline--${variant}`,
84
+ `ds-deadline--${size}`,
85
+ `ds-deadline--${overdue ? "error" : status}`,
86
+ overdue && "ds-deadline--overdue",
87
+ className
88
+ ].filter(Boolean).join(" ");
89
+ return /* @__PURE__ */ jsx("span", { ...rest, ref, className: classes, children: /* @__PURE__ */ jsx("time", { dateTime: due.toISOString(), title: full, suppressHydrationWarning: true, children: text }) });
90
+ }
91
+ export {
92
+ Deadline,
93
+ deadlineStatus
94
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Where a deadline stands against now, without React: Deadline reads it, and
3
+ * a host can call it to sort or filter by the same rule.
4
+ */
5
+ /** How close a deadline must be for each warning, in milliseconds. */
6
+ export type DeadlineThresholds = {
7
+ /** Under this long to go, the deadline turns to the warning role. Defaults to three days. */
8
+ warning?: number;
9
+ /** Under this long to go, the deadline turns to the error role. Defaults to one day. */
10
+ critical?: number;
11
+ };
12
+ /** Where a deadline stands against now. */
13
+ export type DeadlineStatus = 'neutral' | 'warning' | 'error' | 'overdue';
14
+ /** Where `due` stands against `now`, given the thresholds. */
15
+ export declare function deadlineStatus(due: Date, now: Date, thresholds?: DeadlineThresholds): DeadlineStatus;
@@ -0,0 +1,13 @@
1
+ const HOUR = 36e5;
2
+ const DAY = 24 * HOUR;
3
+ function deadlineStatus(due, now, thresholds = {}) {
4
+ const { warning = 3 * DAY, critical = DAY } = thresholds;
5
+ const left = due.getTime() - now.getTime();
6
+ if (left < 0) return "overdue";
7
+ if (left < critical) return "error";
8
+ if (left < warning) return "warning";
9
+ return "neutral";
10
+ }
11
+ export {
12
+ deadlineStatus
13
+ };