@primer/components 0.0.0-2021104181937 → 0.0.0-2021104225742

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 +5 -1
  2. package/dist/browser.esm.js +4 -7
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +29 -32
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  7. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  9. package/lib/Button/Button.js +1 -1
  10. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  11. package/lib/TextInputWithTokens.d.ts +2 -4
  12. package/lib/Truncate.d.ts +1 -2
  13. package/lib/Truncate.js +1 -3
  14. package/lib/hooks/useResizeObserver.d.ts +1 -1
  15. package/lib/hooks/useResizeObserver.js +1 -1
  16. package/lib/theme-preval.js +2 -2
  17. package/lib/utils/testing.d.ts +1 -1
  18. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  19. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  20. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  21. package/lib-esm/Button/Button.js +1 -1
  22. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  23. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  24. package/lib-esm/Truncate.d.ts +1 -2
  25. package/lib-esm/Truncate.js +1 -2
  26. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  27. package/lib-esm/hooks/useResizeObserver.js +1 -1
  28. package/lib-esm/theme-preval.js +2 -2
  29. package/lib-esm/utils/testing.d.ts +1 -1
  30. package/package.json +8 -9
  31. package/lib/DatePicker/DatePicker.d.ts +0 -52
  32. package/lib/DatePicker/DatePicker.js +0 -109
  33. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  34. package/lib/DatePicker/DatePickerAnchor.js +0 -202
  35. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  36. package/lib/DatePicker/DatePickerOverlay.js +0 -55
  37. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  38. package/lib/DatePicker/DatePickerPanel.js +0 -363
  39. package/lib/DatePicker/Day.d.ts +0 -15
  40. package/lib/DatePicker/Day.js +0 -204
  41. package/lib/DatePicker/Month.d.ts +0 -8
  42. package/lib/DatePicker/Month.js +0 -122
  43. package/lib/DatePicker/dateParser.d.ts +0 -12
  44. package/lib/DatePicker/dateParser.js +0 -193
  45. package/lib/DatePicker/index.d.ts +0 -2
  46. package/lib/DatePicker/index.js +0 -13
  47. package/lib/DatePicker/useDatePicker.d.ts +0 -107
  48. package/lib/DatePicker/useDatePicker.js +0 -561
  49. package/lib/hooks/useDebounce.d.ts +0 -2
  50. package/lib/hooks/useDebounce.js +0 -24
  51. package/lib-esm/DatePicker/DatePicker.d.ts +0 -52
  52. package/lib-esm/DatePicker/DatePicker.js +0 -92
  53. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  54. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -174
  55. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  56. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -40
  57. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  58. package/lib-esm/DatePicker/DatePickerPanel.js +0 -332
  59. package/lib-esm/DatePicker/Day.d.ts +0 -15
  60. package/lib-esm/DatePicker/Day.js +0 -180
  61. package/lib-esm/DatePicker/Month.d.ts +0 -8
  62. package/lib-esm/DatePicker/Month.js +0 -98
  63. package/lib-esm/DatePicker/dateParser.d.ts +0 -12
  64. package/lib-esm/DatePicker/dateParser.js +0 -179
  65. package/lib-esm/DatePicker/index.d.ts +0 -2
  66. package/lib-esm/DatePicker/index.js +0 -1
  67. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -107
  68. package/lib-esm/DatePicker/useDatePicker.js +0 -526
  69. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  70. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,526 +0,0 @@
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: '1-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(getInitialFocusDate(initialSelection));
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
- setFocusDate(getInitialFocusDate(selection));
368
- }, [selection]);
369
- useEffect(() => {
370
- if (configuration.view === '1-month' || !multiMonthSupport) {
371
- if (currentViewingDate.getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear()) {
372
- return;
373
- } else {
374
- setCurrentViewingDate(setDate(focusDate, 1));
375
- return;
376
- }
377
- }
378
- /**
379
- * This logic is rough, so buckle up.
380
- * We want to set the currently shown months based on what has focus. If the focus leaves what we're able to view,
381
- * we want to be able to change the currently shown month. However, this gets complicated with the 2-month view.
382
- * FIRST: If it's the same month/year: Easy
383
- * SECOND: If it's the next month, but same year: Done
384
- * THIRD: If it's the next month AND next year, but it's January (i.e. we're viewing Dec/Jan): Good to go
385
- */
386
-
387
-
388
- 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()) {
389
- return;
390
- } else {
391
- setCurrentViewingDate(setDate(focusDate, 1));
392
- }
393
- }, [configuration.view, currentViewingDate, focusDate, multiMonthSupport]);
394
- const selectionHandler = useCallback(date => {
395
- setIsDirty(true);
396
-
397
- if (configuration.variant === 'multi') {
398
- const selections = Array.isArray(selection) ? selection : [];
399
- const existingIndex = selections.findIndex(s => isEqual(s, date));
400
-
401
- if (existingIndex > -1) {
402
- selections.splice(existingIndex, 1);
403
- setSelection([...selections].sort((a, b) => a.getTime() - b.getTime()));
404
- } else {
405
- if (configuration.maxSelections && selections.length + 1 > configuration.maxSelections) return;
406
- setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
407
- }
408
- } else if (configuration.variant === 'range') {
409
- if (selection && isRangeSelection(selection) && !selection.to) {
410
- let toDate = date;
411
-
412
- if (configuration.maxRangeSize && Math.abs(differenceInDays(selection.from, date)) >= configuration.maxRangeSize) {
413
- toDate = isBefore(date, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
414
- }
415
-
416
- const updatedSelection = isBefore(toDate, selection.from) ? {
417
- from: toDate,
418
- to: selection.from
419
- } : {
420
- from: selection.from,
421
- to: toDate
422
- };
423
- setSelection(updatedSelection);
424
- setHoverRange(null);
425
-
426
- if (!configuration.confirmation) {
427
- saveValue(updatedSelection);
428
- }
429
- } else {
430
- setHoverRange({
431
- from: date,
432
- to: date
433
- });
434
- setSelection({
435
- from: date,
436
- to: null
437
- });
438
- }
439
- } else {
440
- setSelection(date);
441
-
442
- if (!configuration.confirmation) {
443
- saveValue(date);
444
- }
445
- }
446
- }, [configuration.confirmation, configuration.maxRangeSize, configuration.maxSelections, configuration.variant, saveValue, selection]);
447
- const focusHandler = useCallback(date => {
448
- if (!selection) return;
449
- const {
450
- minDate,
451
- maxDate,
452
- maxRangeSize,
453
- disableWeekends,
454
- variant
455
- } = configuration;
456
-
457
- if (variant === 'range' && isRangeSelection(selection) && hoverRange) {
458
- let hoverDate = date;
459
- if (minDate) hoverDate = isBefore(date, minDate) ? minDate : hoverDate;
460
- if (maxDate) hoverDate = isAfter(date, maxDate) ? maxDate : hoverDate;
461
- const daysInRange = disableWeekends ? Math.abs(differenceInBusinessDays(selection.from, hoverDate)) : Math.abs(differenceInDays(selection.from, hoverDate));
462
-
463
- if (maxRangeSize && daysInRange >= maxRangeSize) {
464
- if (disableWeekends) {
465
- hoverDate = isBefore(hoverDate, selection.from) ? subBusinessDays(selection.from, configuration.maxRangeSize - 1) : addBusinessDays(selection.from, configuration.maxRangeSize - 1);
466
- } else {
467
- hoverDate = isBefore(hoverDate, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
468
- }
469
- }
470
-
471
- if (disableWeekends && isWeekend(hoverDate)) {
472
- hoverDate = previousFriday(hoverDate);
473
- }
474
-
475
- setHoverRange(isBefore(hoverDate, selection.from) ? {
476
- from: hoverDate,
477
- to: selection.from
478
- } : {
479
- from: selection.from,
480
- to: hoverDate
481
- });
482
- }
483
- }, [configuration, hoverRange, selection]);
484
-
485
- const onResize = windowEntry => {
486
- // Only care about the first element, we expect one element ot be watched
487
- const {
488
- width
489
- } = windowEntry.contentRect; // 610 is the panel width with 2 months
490
-
491
- setMultiMonthSupport(width > 610);
492
- };
493
-
494
- useResizeObserver(onResize);
495
- const datePickerCtx = useMemo(() => {
496
- return {
497
- configuration,
498
- currentViewingDate,
499
- disabled: false,
500
- focusDate,
501
- formattedDate,
502
- inputDate,
503
- goToMonth,
504
- hoverRange,
505
- dialogOpen,
506
- nextMonth,
507
- onClose: handleClose,
508
- onDateInput: inputHandler,
509
- onDayFocus: focusHandler,
510
- onSelection: selectionHandler,
511
- previousMonth,
512
- revertValue,
513
- saveValue,
514
- selectionActive: false,
515
- setFocusDate,
516
- setHoverRange,
517
- selection,
518
- setDialogOpen,
519
- viewMode: configuration.view === '2-month' && multiMonthSupport ? '2-month' : '1-month'
520
- };
521
- }, [configuration, currentViewingDate, dialogOpen, focusDate, focusHandler, formattedDate, goToMonth, handleClose, hoverRange, inputDate, inputHandler, multiMonthSupport, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
522
- return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
523
- value: datePickerCtx
524
- }, children);
525
- };
526
- DatePickerProvider.displayName = "DatePickerProvider";
@@ -1,2 +0,0 @@
1
- declare function useDebounce<T>(value: T, delay: number): T;
2
- export default useDebounce;
@@ -1,16 +0,0 @@
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;