@primer/components 0.0.0-2021103231920 → 0.0.0-20211040245

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 (70) hide show
  1. package/CHANGELOG.md +1 -5
  2. package/dist/browser.esm.js +5 -3
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +30 -28
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  7. package/lib/Autocomplete/Autocomplete.d.ts +4 -2
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
  9. package/lib/DatePicker/DatePicker.d.ts +52 -0
  10. package/lib/DatePicker/DatePicker.js +109 -0
  11. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  12. package/lib/DatePicker/DatePickerAnchor.js +202 -0
  13. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  14. package/lib/DatePicker/DatePickerOverlay.js +55 -0
  15. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  16. package/lib/DatePicker/DatePickerPanel.js +363 -0
  17. package/lib/DatePicker/Day.d.ts +15 -0
  18. package/lib/DatePicker/Day.js +206 -0
  19. package/lib/DatePicker/Month.d.ts +8 -0
  20. package/lib/DatePicker/Month.js +122 -0
  21. package/lib/DatePicker/dateParser.d.ts +12 -0
  22. package/lib/DatePicker/dateParser.js +192 -0
  23. package/lib/DatePicker/index.d.ts +2 -0
  24. package/lib/DatePicker/index.js +13 -0
  25. package/lib/DatePicker/useDatePicker.d.ts +107 -0
  26. package/lib/DatePicker/useDatePicker.js +558 -0
  27. package/lib/Link.d.ts +2 -1
  28. package/lib/Link.js +1 -1
  29. package/lib/SelectMenu/SelectMenu.d.ts +4 -2
  30. package/lib/SideNav.d.ts +2 -2
  31. package/lib/TextInputWithTokens.d.ts +4 -2
  32. package/lib/hooks/useDebounce.d.ts +2 -0
  33. package/lib/hooks/useDebounce.js +24 -0
  34. package/lib/hooks/useResizeObserver.d.ts +1 -1
  35. package/lib/hooks/useResizeObserver.js +1 -1
  36. package/lib/theme-preval.js +2 -2
  37. package/lib/utils/testing.d.ts +1 -1
  38. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  39. package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
  40. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
  41. package/lib-esm/DatePicker/DatePicker.d.ts +52 -0
  42. package/lib-esm/DatePicker/DatePicker.js +92 -0
  43. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  44. package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
  45. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  46. package/lib-esm/DatePicker/DatePickerOverlay.js +40 -0
  47. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  48. package/lib-esm/DatePicker/DatePickerPanel.js +332 -0
  49. package/lib-esm/DatePicker/Day.d.ts +15 -0
  50. package/lib-esm/DatePicker/Day.js +182 -0
  51. package/lib-esm/DatePicker/Month.d.ts +8 -0
  52. package/lib-esm/DatePicker/Month.js +98 -0
  53. package/lib-esm/DatePicker/dateParser.d.ts +12 -0
  54. package/lib-esm/DatePicker/dateParser.js +178 -0
  55. package/lib-esm/DatePicker/index.d.ts +2 -0
  56. package/lib-esm/DatePicker/index.js +1 -0
  57. package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
  58. package/lib-esm/DatePicker/useDatePicker.js +523 -0
  59. package/lib-esm/Link.d.ts +2 -1
  60. package/lib-esm/Link.js +2 -2
  61. package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
  62. package/lib-esm/SideNav.d.ts +2 -2
  63. package/lib-esm/TextInputWithTokens.d.ts +4 -2
  64. package/lib-esm/hooks/useDebounce.d.ts +2 -0
  65. package/lib-esm/hooks/useDebounce.js +16 -0
  66. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  67. package/lib-esm/hooks/useResizeObserver.js +1 -1
  68. package/lib-esm/theme-preval.js +2 -2
  69. package/lib-esm/utils/testing.d.ts +1 -1
  70. package/package.json +9 -8
@@ -0,0 +1,523 @@
1
+ import { CheckIcon, TrashIcon } from '@primer/octicons-react';
2
+ import { isEqual, isAfter, isBefore, addMonths, subMonths, isToday, isWeekend, differenceInDays, addDays, subDays, previousFriday, differenceInBusinessDays, addYears, setDate } from 'date-fns';
3
+ import { addBusinessDays, subBusinessDays } from 'date-fns/esm';
4
+ import deepmerge from 'deepmerge';
5
+ import React, { createContext, useCallback, useContext, useMemo, useEffect, useState } from 'react';
6
+ import { Text, useConfirm } from '..';
7
+ import { useResizeObserver } from '../hooks/useResizeObserver';
8
+ import { formatDate } from './dateParser';
9
+ const DatePickerContext = /*#__PURE__*/createContext(null);
10
+
11
+ const useDatePicker = date => {
12
+ const dateCtx = useContext(DatePickerContext);
13
+ const [selected, setSelected] = useState(false);
14
+ const [focused, setFocused] = useState(false);
15
+ const today = date ? isToday(date) : false;
16
+
17
+ if (!dateCtx) {
18
+ throw new Error('useDatePicker must be used inside a DatePickerProvider');
19
+ }
20
+
21
+ useEffect(() => {
22
+ if (date) {
23
+ if (dateCtx.hoverRange) {
24
+ if (isRangeSelection(dateCtx.hoverRange)) {
25
+ if (isEqual(date, dateCtx.hoverRange.from)) {
26
+ setSelected('start');
27
+ } else if (dateCtx.hoverRange.to && isEqual(date, dateCtx.hoverRange.to)) {
28
+ setSelected('end');
29
+ } else if (isAfter(date, dateCtx.hoverRange.from) && dateCtx.hoverRange.to && isBefore(date, dateCtx.hoverRange.to)) {
30
+ setSelected('middle');
31
+ } else {
32
+ setSelected(false);
33
+ }
34
+ }
35
+ } else if (dateCtx.selection) {
36
+ if (isMultiSelection(dateCtx.selection)) {
37
+ setSelected(!!dateCtx.selection.find(d => isEqual(d, date)));
38
+ } else if (isRangeSelection(dateCtx.selection)) {
39
+ if (isEqual(date, dateCtx.selection.from)) {
40
+ setSelected('start');
41
+ } else if (dateCtx.selection.to && isEqual(date, dateCtx.selection.to)) {
42
+ setSelected('end');
43
+ } else if (isAfter(date, dateCtx.selection.from) && dateCtx.selection.to && isBefore(date, dateCtx.selection.to)) {
44
+ setSelected('middle');
45
+ } else {
46
+ setSelected(false);
47
+ }
48
+ } else {
49
+ setSelected(isEqual(date, dateCtx.selection));
50
+ }
51
+ }
52
+ }
53
+ }, [date, dateCtx.hoverRange, dateCtx.selection, today]);
54
+ useEffect(() => {
55
+ if (date) {
56
+ // Determine if date is focused
57
+ setFocused(isEqual(dateCtx.focusDate, date));
58
+ }
59
+ }, [date, dateCtx.focusDate]);
60
+ let blocked,
61
+ disabled = false;
62
+
63
+ if (date) {
64
+ // Determine if date is blocked out
65
+ if (dateCtx.configuration.blockedDates) {
66
+ blocked = !!dateCtx.configuration.blockedDates.find(d => isEqual(d, date));
67
+ } // Determine if date is disabled
68
+
69
+
70
+ if (dateCtx.configuration.minDate || dateCtx.configuration.maxDate || dateCtx.configuration.disableWeekends) {
71
+ disabled = (dateCtx.configuration.minDate ? isBefore(date, dateCtx.configuration.minDate) : false) || (dateCtx.configuration.maxDate ? isAfter(date, dateCtx.configuration.maxDate) : false) || (dateCtx.configuration.disableWeekends ? isWeekend(date) : false);
72
+ }
73
+ }
74
+
75
+ return { ...dateCtx,
76
+ blocked,
77
+ disabled,
78
+ focused,
79
+ selected,
80
+ today
81
+ };
82
+ };
83
+
84
+ export default useDatePicker;
85
+ export function isSingleSelection(selection) {
86
+ return selection instanceof Date;
87
+ }
88
+ export function isMultiSelection(selection) {
89
+ return Array.isArray(selection);
90
+ }
91
+ export function isRangeSelection(selection) {
92
+ return !!selection.from;
93
+ }
94
+ export function isStringRangeSelection(selection) {
95
+ return !!selection.from;
96
+ }
97
+
98
+ function parseSelection(selection, variant) {
99
+ if (!selection) return;
100
+
101
+ if (variant === 'multi') {
102
+ if (isMultiSelection(selection)) {
103
+ const parsedSelection = [];
104
+
105
+ for (const d of selection) {
106
+ parsedSelection.push(normalizeDate(d));
107
+ }
108
+
109
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
110
+ } else if (selection instanceof Date) {
111
+ return [normalizeDate(selection)];
112
+ } else if (isRangeSelection(selection)) {
113
+ const parsedSelection = [];
114
+ parsedSelection.push(normalizeDate(selection.from));
115
+
116
+ if (selection.to) {
117
+ parsedSelection.push(normalizeDate(selection.to));
118
+ }
119
+
120
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
121
+ }
122
+ } else if (variant === 'range') {
123
+ if (isRangeSelection(selection)) {
124
+ return {
125
+ from: normalizeDate(selection.from),
126
+ to: selection.to ? normalizeDate(selection.to) : null
127
+ };
128
+ } else if (isMultiSelection(selection)) {
129
+ return {
130
+ from: normalizeDate(selection[0]),
131
+ to: selection[1] ? normalizeDate(selection[1]) : null
132
+ };
133
+ } else if (selection instanceof Date) {
134
+ return {
135
+ from: normalizeDate(selection),
136
+ to: null
137
+ };
138
+ }
139
+ } else {
140
+ if (selection instanceof Date) {
141
+ return normalizeDate(selection);
142
+ } else if (isMultiSelection(selection)) {
143
+ return normalizeDate(selection[0]);
144
+ } else if (isRangeSelection(selection)) {
145
+ return normalizeDate(selection.from);
146
+ } else {
147
+ return;
148
+ }
149
+ }
150
+ }
151
+
152
+ const getInitialFocusDate = selection => {
153
+ if (!selection) return normalizeDate(new Date());
154
+
155
+ if (selection instanceof Date) {
156
+ return normalizeDate(selection);
157
+ } else if (Array.isArray(selection)) {
158
+ return normalizeDate(selection[0]);
159
+ } else if (isRangeSelection(selection)) {
160
+ return normalizeDate(selection.from);
161
+ } else {
162
+ return normalizeDate(new Date());
163
+ }
164
+ };
165
+
166
+ export const normalizeDate = date => new Date(new Date(date).toDateString());
167
+ const defaultConfiguration = {
168
+ anchorVariant: 'button',
169
+ confirmation: false,
170
+ confirmUnsavedClose: false,
171
+ compressedHeader: false,
172
+ disableWeekends: false,
173
+ iconPlacement: 'start',
174
+ placeholder: 'Choose Date...',
175
+ showInputPrompt: false,
176
+ variant: 'single',
177
+ view: '2-month',
178
+ weekStartsOn: 'Sunday'
179
+ };
180
+ export const DatePickerProvider = ({
181
+ configuration: externalConfig = {},
182
+ children,
183
+ closePicker,
184
+ value
185
+ }) => {
186
+ const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
187
+ const initialSelection = parseSelection(value, configuration.variant);
188
+ const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.variant));
189
+ const [isDirty, setIsDirty] = useState(false);
190
+ const [selection, setSelection] = useState(initialSelection);
191
+ const [hoverRange, setHoverRange] = useState(null);
192
+ const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
193
+ const [multiMonthSupport, setMultiMonthSupport] = useState(true);
194
+ const confirm = useConfirm();
195
+ const [dialogOpen, setDialogOpen] = useState(false);
196
+ const [focusDate, setFocusDate] = useState(getInitialFocusDate(initialSelection));
197
+ useEffect(() => {
198
+ setConfiguration(deepmerge(defaultConfiguration, externalConfig));
199
+ setSelection(parseSelection(selection, configuration.variant)); // Don't want this to run every time selection gets updated
200
+ // eslint-disable-next-line react-hooks/exhaustive-deps
201
+ }, [configuration.variant, externalConfig]);
202
+ const goToMonth = useCallback(date => {
203
+ let newDate = date;
204
+ const {
205
+ minDate,
206
+ maxDate
207
+ } = configuration;
208
+
209
+ if (minDate && isBefore(date, minDate)) {
210
+ newDate = minDate;
211
+ } else if (maxDate && isAfter(date, maxDate)) {
212
+ newDate = maxDate;
213
+ }
214
+
215
+ setFocusDate(normalizeDate(newDate));
216
+ setCurrentViewingDate(normalizeDate(newDate));
217
+ }, [configuration]);
218
+ const nextMonth = useCallback(() => {
219
+ const date = addMonths(currentViewingDate, 1);
220
+ setFocusDate(normalizeDate(date));
221
+ setCurrentViewingDate(date);
222
+ }, [currentViewingDate]);
223
+ const previousMonth = useCallback(() => {
224
+ const date = subMonths(currentViewingDate, 1);
225
+ setFocusDate(normalizeDate(date));
226
+ setCurrentViewingDate(date);
227
+ }, [currentViewingDate]);
228
+ const formattedDate = useMemo(() => {
229
+ const {
230
+ anchorVariant,
231
+ dateFormat,
232
+ placeholder,
233
+ variant
234
+ } = configuration;
235
+ return formatDate({
236
+ selection,
237
+ anchorVariant,
238
+ dateFormat,
239
+ placeholder,
240
+ rawFormat: false,
241
+ variant
242
+ });
243
+ }, [configuration, selection]);
244
+ const inputDate = useMemo(() => {
245
+ const {
246
+ dateFormat,
247
+ placeholder,
248
+ variant
249
+ } = configuration;
250
+ return formatDate({
251
+ selection,
252
+ dateFormat,
253
+ placeholder,
254
+ rawFormat: true,
255
+ variant
256
+ });
257
+ }, [configuration, selection]);
258
+ const saveValue = useCallback(updatedSelection => {
259
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
260
+ setIsDirty(false);
261
+ closePicker === null || closePicker === void 0 ? void 0 : closePicker();
262
+ }, [closePicker, selection]);
263
+ const revertValue = useCallback(() => {
264
+ setSelection(previousSelection);
265
+ setIsDirty(false);
266
+ }, [previousSelection]);
267
+ const handleClose = useCallback(async () => {
268
+ if (configuration.confirmUnsavedClose) {
269
+ if (isDirty) {
270
+ const result = await confirm({
271
+ title: 'Save Changes?',
272
+ content: 'You have unsaved changes, would you like to save them?',
273
+ confirmButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CheckIcon, null), /*#__PURE__*/React.createElement(Text, {
274
+ sx: {
275
+ ml: 1
276
+ }
277
+ }, "Save")),
278
+ cancelButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TrashIcon, null), /*#__PURE__*/React.createElement(Text, {
279
+ sx: {
280
+ ml: 1
281
+ }
282
+ }, "Discard"))
283
+ });
284
+
285
+ if (result) {
286
+ saveValue();
287
+ } else {
288
+ revertValue();
289
+ }
290
+ }
291
+ } else if (isDirty) revertValue();
292
+ }, [configuration.confirmUnsavedClose, confirm, isDirty, revertValue, saveValue]);
293
+ const inputHandler = useCallback(updatedSelection => {
294
+ if (!updatedSelection) return;
295
+ const {
296
+ maxDate,
297
+ minDate,
298
+ variant,
299
+ maxSelections,
300
+ maxRangeSize
301
+ } = configuration;
302
+
303
+ switch (variant) {
304
+ case 'single':
305
+ {
306
+ if (updatedSelection instanceof Date) {
307
+ if (maxDate && isAfter(updatedSelection, maxDate)) {
308
+ setSelection(maxDate);
309
+ } else if (minDate && isBefore(minDate, updatedSelection)) {
310
+ setSelection(minDate);
311
+ } else {
312
+ setSelection(updatedSelection);
313
+ }
314
+ }
315
+
316
+ break;
317
+ }
318
+
319
+ case 'multi':
320
+ {
321
+ if (Array.isArray(updatedSelection)) {
322
+ let validSelections = updatedSelection.filter(d => (maxDate ? isBefore(d, maxDate) : true) && (minDate ? isAfter(d, minDate) : true));
323
+
324
+ if (maxSelections) {
325
+ validSelections = validSelections.slice(0, maxSelections);
326
+ }
327
+
328
+ setSelection(validSelections);
329
+ }
330
+
331
+ break;
332
+ }
333
+
334
+ case 'range':
335
+ {
336
+ if (isRangeSelection(updatedSelection)) {
337
+ const validRange = updatedSelection;
338
+
339
+ if (minDate) {
340
+ validRange.from = isAfter(updatedSelection.from, minDate) ? updatedSelection.from : minDate;
341
+
342
+ if (updatedSelection.to) {
343
+ validRange.to = isAfter(updatedSelection.to, minDate) ? updatedSelection.to : minDate;
344
+ }
345
+ }
346
+
347
+ if (maxDate) {
348
+ validRange.from = isBefore(updatedSelection.from, maxDate) ? updatedSelection.from : maxDate;
349
+
350
+ if (updatedSelection.to) {
351
+ validRange.to = isBefore(updatedSelection.to, maxDate) ? updatedSelection.to : maxDate;
352
+ }
353
+ }
354
+
355
+ if (maxRangeSize && validRange.to && Math.abs(differenceInDays(validRange.from, validRange.to)) >= maxRangeSize) {
356
+ validRange.to = addDays(validRange.from, maxRangeSize - 1);
357
+ }
358
+
359
+ setSelection(updatedSelection);
360
+ }
361
+
362
+ break;
363
+ }
364
+ }
365
+ }, [configuration]);
366
+ useEffect(() => {
367
+ if (configuration.view === '1-month') {
368
+ if (currentViewingDate.getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear()) {
369
+ return;
370
+ } else {
371
+ setCurrentViewingDate(setDate(focusDate, 1));
372
+ return;
373
+ }
374
+ }
375
+ /**
376
+ * This logic is rough, so buckle up.
377
+ * We want to set the currently shown months based on what has focus. If the focus leaves what we're able to view,
378
+ * we want to be able to change the currently shown month. However, this gets complicated with the 2-month view.
379
+ * FIRST: If it's the same month/year: Easy
380
+ * SECOND: If it's the next month, but same year: Done
381
+ * THIRD: If it's the next month AND next year, but it's January (i.e. we're viewing Dec/Jan): Good to go
382
+ */
383
+
384
+
385
+ if (currentViewingDate.getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear() || addMonths(currentViewingDate, 1).getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear() || addMonths(currentViewingDate, 1).getMonth() === focusDate.getMonth() && focusDate.getMonth() === 0 && addYears(currentViewingDate, 1).getFullYear() === focusDate.getFullYear()) {
386
+ return;
387
+ } else {
388
+ setCurrentViewingDate(setDate(focusDate, 1));
389
+ }
390
+ }, [configuration.view, currentViewingDate, focusDate]);
391
+ const selectionHandler = useCallback(date => {
392
+ setIsDirty(true);
393
+
394
+ if (configuration.variant === 'multi') {
395
+ const selections = Array.isArray(selection) ? selection : [];
396
+ const existingIndex = selections.findIndex(s => isEqual(s, date));
397
+
398
+ if (existingIndex > -1) {
399
+ selections.splice(existingIndex, 1);
400
+ setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
401
+ } else {
402
+ if (configuration.maxSelections && selections.length + 1 > configuration.maxSelections) return;
403
+ setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
404
+ }
405
+ } else if (configuration.variant === 'range') {
406
+ if (selection && isRangeSelection(selection) && !selection.to) {
407
+ let toDate = date;
408
+
409
+ if (configuration.maxRangeSize && Math.abs(differenceInDays(selection.from, date)) >= configuration.maxRangeSize) {
410
+ toDate = isBefore(date, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
411
+ }
412
+
413
+ const updatedSelection = isBefore(toDate, selection.from) ? {
414
+ from: toDate,
415
+ to: selection.from
416
+ } : {
417
+ from: selection.from,
418
+ to: toDate
419
+ };
420
+ setSelection(updatedSelection);
421
+ setHoverRange(null);
422
+
423
+ if (!configuration.confirmation) {
424
+ saveValue(updatedSelection);
425
+ }
426
+ } else {
427
+ setHoverRange({
428
+ from: date,
429
+ to: date
430
+ });
431
+ setSelection({
432
+ from: date,
433
+ to: null
434
+ });
435
+ }
436
+ } else {
437
+ setSelection(date);
438
+
439
+ if (!configuration.confirmation) {
440
+ saveValue(date);
441
+ }
442
+ }
443
+ }, [configuration.confirmation, configuration.maxRangeSize, configuration.maxSelections, configuration.variant, saveValue, selection]);
444
+ const focusHandler = useCallback(date => {
445
+ if (!selection) return;
446
+ const {
447
+ minDate,
448
+ maxDate,
449
+ maxRangeSize,
450
+ disableWeekends,
451
+ variant
452
+ } = configuration;
453
+
454
+ if (variant === 'range' && isRangeSelection(selection) && hoverRange) {
455
+ let hoverDate = date;
456
+ if (minDate) hoverDate = isBefore(date, minDate) ? minDate : hoverDate;
457
+ if (maxDate) hoverDate = isAfter(date, maxDate) ? maxDate : hoverDate;
458
+ const daysInRange = disableWeekends ? Math.abs(differenceInBusinessDays(selection.from, hoverDate)) : Math.abs(differenceInDays(selection.from, hoverDate));
459
+
460
+ if (maxRangeSize && daysInRange >= maxRangeSize) {
461
+ if (disableWeekends) {
462
+ hoverDate = isBefore(hoverDate, selection.from) ? subBusinessDays(selection.from, configuration.maxRangeSize - 1) : addBusinessDays(selection.from, configuration.maxRangeSize - 1);
463
+ } else {
464
+ hoverDate = isBefore(hoverDate, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
465
+ }
466
+ }
467
+
468
+ if (disableWeekends && isWeekend(hoverDate)) {
469
+ hoverDate = previousFriday(hoverDate);
470
+ }
471
+
472
+ setHoverRange(isBefore(hoverDate, selection.from) ? {
473
+ from: hoverDate,
474
+ to: selection.from
475
+ } : {
476
+ from: selection.from,
477
+ to: hoverDate
478
+ });
479
+ }
480
+ }, [configuration, hoverRange, selection]);
481
+
482
+ const onResize = windowEntry => {
483
+ // Only care about the first element, we expect one element ot be watched
484
+ const {
485
+ width
486
+ } = windowEntry.contentRect; // 610 is the panel width with 2 months
487
+
488
+ setMultiMonthSupport(width > 610);
489
+ };
490
+
491
+ useResizeObserver(onResize);
492
+ const datePickerCtx = useMemo(() => {
493
+ return {
494
+ configuration,
495
+ currentViewingDate,
496
+ disabled: false,
497
+ focusDate,
498
+ formattedDate,
499
+ inputDate,
500
+ goToMonth,
501
+ hoverRange,
502
+ dialogOpen,
503
+ nextMonth,
504
+ onClose: handleClose,
505
+ onDateInput: inputHandler,
506
+ onDayFocus: focusHandler,
507
+ onSelection: selectionHandler,
508
+ previousMonth,
509
+ revertValue,
510
+ saveValue,
511
+ selectionActive: false,
512
+ setFocusDate,
513
+ setHoverRange,
514
+ selection,
515
+ setDialogOpen,
516
+ viewMode: configuration.view === '2-month' && multiMonthSupport ? '2-month' : '1-month'
517
+ };
518
+ }, [configuration, currentViewingDate, dialogOpen, focusDate, focusHandler, formattedDate, goToMonth, handleClose, hoverRange, inputDate, inputHandler, multiMonthSupport, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
519
+ return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
520
+ value: datePickerCtx
521
+ }, children);
522
+ };
523
+ DatePickerProvider.displayName = "DatePickerProvider";
package/lib-esm/Link.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { SystemCommonProps, SystemTypographyProps } from './constants';
1
2
  import { SxProp } from './sx';
2
3
  import { ComponentProps } from './utils/types';
3
4
  declare const Link: import("styled-components").StyledComponent<"a", any, {
4
5
  hoverColor?: string | undefined;
5
6
  muted?: boolean | undefined;
6
7
  underline?: boolean | undefined;
7
- } & SxProp, never>;
8
+ } & SystemCommonProps & SxProp & SystemTypographyProps, never>;
8
9
  export declare type LinkProps = ComponentProps<typeof Link>;
9
10
  export default Link;
package/lib-esm/Link.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import styled from 'styled-components';
2
2
  import { system } from 'styled-system';
3
- import { get } from './constants';
3
+ import { COMMON, get, TYPOGRAPHY } from './constants';
4
4
  import sx from './sx';
5
5
  const hoverColor = system({
6
6
  hoverColor: {
@@ -11,5 +11,5 @@ const hoverColor = system({
11
11
  const Link = styled.a.withConfig({
12
12
  displayName: "Link",
13
13
  componentId: "sc-1brdqhf-0"
14
- })(["color:", ";text-decoration:", ";&:hover{text-decoration:", ";", ";}&:is(button){display:inline-block;padding:0;font-size:inherit;white-space:nowrap;cursor:pointer;user-select:none;background-color:transparent;border:0;appearance:none;}", ";"], props => props.muted ? get('colors.fg.muted')(props) : get('colors.accent.fg')(props), props => props.underline ? 'underline' : 'none', props => props.muted ? 'none' : 'underline', props => props.hoverColor ? hoverColor : props.muted ? `color: ${get('colors.accent.fg')(props)}` : '', sx);
14
+ })(["color:", ";text-decoration:", ";&:hover{text-decoration:", ";", ";}&:is(button){display:inline-block;padding:0;font-size:inherit;white-space:nowrap;cursor:pointer;user-select:none;background-color:transparent;border:0;appearance:none;}", ";", ";", ";"], props => props.muted ? get('colors.fg.muted')(props) : get('colors.accent.fg')(props), props => props.underline ? 'underline' : 'none', props => props.muted ? 'none' : 'underline', props => props.hoverColor ? hoverColor : props.muted ? `color: ${get('colors.accent.fg')(props)}` : '', TYPOGRAPHY, COMMON, sx);
15
15
  export default Link;
@@ -32,12 +32,14 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
32
32
  Divider: import("styled-components").StyledComponent<"div", any, SystemCommonProps & SxProp, never>;
33
33
  Filter: React.ForwardRefExoticComponent<Pick<{
34
34
  value?: string | undefined;
35
- } & Pick<Omit<Pick<{
35
+ } & Pick<Omit<Pick<({
36
36
  [x: string]: any;
37
37
  [x: number]: any;
38
38
  } & {
39
39
  theme?: any;
40
- } & {
40
+ } & ({} | {
41
+ children?: React.ReactNode;
42
+ })) & {
41
43
  as?: string | React.ComponentType<any> | undefined;
42
44
  forwardedAs?: string | React.ComponentType<any> | undefined;
43
45
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -18,7 +18,7 @@ declare const SideNavLink: import("styled-components").StyledComponent<"a", any,
18
18
  hoverColor?: string | undefined;
19
19
  muted?: boolean | undefined;
20
20
  underline?: boolean | undefined;
21
- } & import("./sx").SxProp & StyledSideNavLinkProps, never>;
21
+ } & import("./constants").SystemCommonProps & import("./sx").SxProp & import("./constants").SystemTypographyProps & StyledSideNavLinkProps, never>;
22
22
  export declare type SideNavProps = ComponentProps<typeof SideNav>;
23
23
  export declare type SideNavLinkProps = ComponentProps<typeof SideNavLink>;
24
24
  declare const _default: string & import("styled-components").StyledComponentBase<typeof SideNavBase, any, {}, never> & import("hoist-non-react-statics").NonReactStatics<typeof SideNavBase, {}> & {
@@ -26,6 +26,6 @@ declare const _default: string & import("styled-components").StyledComponentBase
26
26
  hoverColor?: string | undefined;
27
27
  muted?: boolean | undefined;
28
28
  underline?: boolean | undefined;
29
- } & import("./sx").SxProp & StyledSideNavLinkProps, never>;
29
+ } & import("./constants").SystemCommonProps & import("./sx").SxProp & import("./constants").SystemTypographyProps & StyledSideNavLinkProps, never>;
30
30
  };
31
31
  export default _default;
@@ -36,12 +36,14 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
36
36
  * The number of tokens to display before truncating
37
37
  */
38
38
  visibleTokenCount?: number | undefined;
39
- } & Pick<Omit<Pick<{
39
+ } & Pick<Omit<Pick<({
40
40
  [x: string]: any;
41
41
  [x: number]: any;
42
42
  } & {
43
43
  theme?: any;
44
- } & {
44
+ } & ({} | {
45
+ children?: React.ReactNode;
46
+ })) & {
45
47
  as?: string | React.ComponentType<any> | undefined;
46
48
  forwardedAs?: string | React.ComponentType<any> | undefined;
47
49
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -0,0 +1,2 @@
1
+ declare function useDebounce<T>(value: T, delay: number): T;
2
+ export default useDebounce;
@@ -0,0 +1,16 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ function useDebounce(value, delay) {
4
+ const [debouncedValue, setDebouncedValue] = useState(value);
5
+ useEffect(() => {
6
+ const handler = setTimeout(() => {
7
+ setDebouncedValue(value);
8
+ }, delay);
9
+ return () => {
10
+ clearTimeout(handler);
11
+ };
12
+ }, [value, delay]);
13
+ return debouncedValue;
14
+ }
15
+
16
+ export default useDebounce;
@@ -1 +1 @@
1
- export declare function useResizeObserver(callback: () => void): void;
1
+ export declare function useResizeObserver(callback: (window: ResizeObserverEntry) => void): void;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  export function useResizeObserver(callback) {
3
3
  React.useLayoutEffect(() => {
4
- const observer = new window.ResizeObserver(() => callback());
4
+ const observer = new window.ResizeObserver(entries => callback(entries[0]));
5
5
  observer.observe(document.documentElement);
6
6
  return () => {
7
7
  observer.disconnect();
@@ -515,7 +515,7 @@ module.exports = {
515
515
  }
516
516
  }
517
517
  },
518
- "light_protanopia": {
518
+ "light_colorblind": {
519
519
  "colors": {
520
520
  "canvasDefaultTransparent": "rgba(255,255,255,0)",
521
521
  "marketingIcon": {
@@ -2456,7 +2456,7 @@ module.exports = {
2456
2456
  }
2457
2457
  }
2458
2458
  },
2459
- "dark_protanopia": {
2459
+ "dark_colorblind": {
2460
2460
  "colors": {
2461
2461
  "canvasDefaultTransparent": "rgba(13,17,23,0)",
2462
2462
  "marketingIcon": {
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
53
53
  xlarge: string;
54
54
  };
55
55
  space: string[];
56
- colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
56
+ colorSchemes: Record<"light" | "light_colorblind" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_colorblind", Record<"colors" | "shadows", Partial<{
57
57
  canvasDefaultTransparent: string;
58
58
  marketingIcon: {
59
59
  primary: string;