@primer/components 0.0.0-202192801738 → 0.0.0-2021928142718

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 (112) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/browser.esm.js +616 -616
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +177 -177
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Description.d.ts +6 -0
  7. package/lib/ActionList2/Description.js +53 -0
  8. package/lib/ActionList2/Divider.d.ts +5 -0
  9. package/lib/ActionList2/Divider.js +33 -0
  10. package/lib/ActionList2/Group.d.ts +8 -0
  11. package/lib/ActionList2/Group.js +46 -0
  12. package/lib/ActionList2/Header.d.ts +26 -0
  13. package/lib/ActionList2/Header.js +55 -0
  14. package/lib/ActionList2/Item.d.ts +48 -0
  15. package/lib/ActionList2/Item.js +204 -0
  16. package/lib/ActionList2/List.d.ts +26 -0
  17. package/lib/ActionList2/List.js +56 -0
  18. package/lib/ActionList2/Selection.d.ts +5 -0
  19. package/lib/ActionList2/Selection.js +64 -0
  20. package/lib/ActionList2/Visuals.d.ts +11 -0
  21. package/lib/ActionList2/Visuals.js +90 -0
  22. package/lib/ActionList2/hacks.d.ts +30 -0
  23. package/lib/ActionList2/hacks.js +38 -0
  24. package/lib/ActionList2/index.d.ts +25 -0
  25. package/lib/ActionList2/index.js +36 -0
  26. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  27. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  29. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  30. package/lib/TextInputWithTokens.d.ts +2 -4
  31. package/lib/index.d.ts +1 -0
  32. package/lib/index.js +8 -0
  33. package/lib/sx.d.ts +2 -0
  34. package/lib/sx.js +8 -0
  35. package/lib/theme-preval.js +2 -2
  36. package/lib/utils/create-slots.d.ts +17 -0
  37. package/lib/utils/create-slots.js +105 -0
  38. package/lib/utils/testing.d.ts +1 -1
  39. package/lib/utils/use-force-update.d.ts +1 -0
  40. package/lib/utils/use-force-update.js +19 -0
  41. package/lib-esm/ActionList2/Description.d.ts +6 -0
  42. package/lib-esm/ActionList2/Description.js +37 -0
  43. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  44. package/lib-esm/ActionList2/Divider.js +21 -0
  45. package/lib-esm/ActionList2/Group.d.ts +8 -0
  46. package/lib-esm/ActionList2/Group.js +35 -0
  47. package/lib-esm/ActionList2/Header.d.ts +26 -0
  48. package/lib-esm/ActionList2/Header.js +45 -0
  49. package/lib-esm/ActionList2/Item.d.ts +48 -0
  50. package/lib-esm/ActionList2/Item.js +176 -0
  51. package/lib-esm/ActionList2/List.d.ts +26 -0
  52. package/lib-esm/ActionList2/List.js +38 -0
  53. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  54. package/lib-esm/ActionList2/Selection.js +48 -0
  55. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  56. package/lib-esm/ActionList2/Visuals.js +68 -0
  57. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  58. package/lib-esm/ActionList2/hacks.js +30 -0
  59. package/lib-esm/ActionList2/index.d.ts +25 -0
  60. package/lib-esm/ActionList2/index.js +23 -0
  61. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  62. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  63. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  64. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  65. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  66. package/lib-esm/index.d.ts +1 -0
  67. package/lib-esm/index.js +1 -0
  68. package/lib-esm/sx.d.ts +2 -0
  69. package/lib-esm/sx.js +3 -1
  70. package/lib-esm/theme-preval.js +2 -2
  71. package/lib-esm/utils/create-slots.d.ts +17 -0
  72. package/lib-esm/utils/create-slots.js +84 -0
  73. package/lib-esm/utils/testing.d.ts +1 -1
  74. package/lib-esm/utils/use-force-update.d.ts +1 -0
  75. package/lib-esm/utils/use-force-update.js +6 -0
  76. package/package.json +8 -9
  77. package/lib/DatePicker/DatePicker.d.ts +0 -48
  78. package/lib/DatePicker/DatePicker.js +0 -104
  79. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  80. package/lib/DatePicker/DatePickerAnchor.js +0 -182
  81. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  82. package/lib/DatePicker/DatePickerOverlay.js +0 -48
  83. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  84. package/lib/DatePicker/DatePickerPanel.js +0 -126
  85. package/lib/DatePicker/Day.d.ts +0 -14
  86. package/lib/DatePicker/Day.js +0 -190
  87. package/lib/DatePicker/Month.d.ts +0 -9
  88. package/lib/DatePicker/Month.js +0 -120
  89. package/lib/DatePicker/index.d.ts +0 -2
  90. package/lib/DatePicker/index.js +0 -13
  91. package/lib/DatePicker/useDatePicker.d.ts +0 -88
  92. package/lib/DatePicker/useDatePicker.js +0 -438
  93. package/lib/hooks/useDebounce.d.ts +0 -2
  94. package/lib/hooks/useDebounce.js +0 -24
  95. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  96. package/lib-esm/DatePicker/DatePicker.js +0 -87
  97. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  98. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -155
  99. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  100. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
  101. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  102. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  103. package/lib-esm/DatePicker/Day.d.ts +0 -14
  104. package/lib-esm/DatePicker/Day.js +0 -167
  105. package/lib-esm/DatePicker/Month.d.ts +0 -9
  106. package/lib-esm/DatePicker/Month.js +0 -96
  107. package/lib-esm/DatePicker/index.d.ts +0 -2
  108. package/lib-esm/DatePicker/index.js +0 -1
  109. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -88
  110. package/lib-esm/DatePicker/useDatePicker.js +0 -408
  111. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  112. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,88 +0,0 @@
1
- import React from 'react';
2
- export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
3
- export declare type DateFormat = 'short' | 'long' | string;
4
- export declare type SelectionVariant = 'single' | 'multi' | 'range';
5
- export interface DatePickerConfiguration {
6
- anchorVariant?: AnchorVariant;
7
- blockedDates?: Array<Date>;
8
- confirmation?: boolean;
9
- confirmUnsavedClose?: boolean;
10
- dateFormat?: DateFormat;
11
- disableWeekends?: boolean;
12
- iconPlacement?: 'start' | 'end' | 'none';
13
- maxDate?: Date | null;
14
- maxSelections?: number;
15
- maxRangeSize?: number;
16
- minDate?: Date | null;
17
- placeholder?: string;
18
- rangeIncrement?: number;
19
- variant?: SelectionVariant;
20
- view?: '1-month' | '2-month';
21
- weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
22
- }
23
- export declare type RangeSelection = {
24
- from: Date;
25
- to: Date | null;
26
- };
27
- export declare type StringRangeSelection = {
28
- from: string;
29
- to: string;
30
- };
31
- export interface DatePickerContext {
32
- disabled?: boolean;
33
- configuration: DatePickerConfiguration;
34
- currentViewingDate: Date;
35
- goToMonth: (date: Date) => void;
36
- hoverRange?: RangeSelection | null;
37
- selection?: Selection;
38
- softSelection?: Partial<RangeSelection> | null;
39
- selectionActive?: boolean;
40
- formattedDate: string;
41
- nextMonth: () => void;
42
- onClose: () => void;
43
- onDateInput: (updatedSelection: Selection) => void;
44
- onDayFocus: (date: Date) => void;
45
- onSelection: (date: Date) => void;
46
- previousMonth: () => void;
47
- revertValue: () => void;
48
- saveValue: (selection?: Selection) => void;
49
- }
50
- export declare type Selection = Date | Array<Date> | RangeSelection | null;
51
- export declare type StringSelection = string | Array<string> | {
52
- to: string;
53
- from: string;
54
- } | null;
55
- export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
56
- declare const useDatePicker: (date?: Date | undefined) => {
57
- blocked: boolean | undefined;
58
- disabled: boolean;
59
- selected: DaySelection;
60
- today: boolean;
61
- configuration: DatePickerConfiguration;
62
- currentViewingDate: Date;
63
- goToMonth: (date: Date) => void;
64
- hoverRange?: RangeSelection | null | undefined;
65
- selection?: Selection | undefined;
66
- softSelection?: Partial<RangeSelection> | null | undefined;
67
- selectionActive?: boolean | undefined;
68
- formattedDate: string;
69
- nextMonth: () => void;
70
- onClose: () => void;
71
- onDateInput: (updatedSelection: Selection) => void;
72
- onDayFocus: (date: Date) => void;
73
- onSelection: (date: Date) => void;
74
- previousMonth: () => void;
75
- revertValue: () => void;
76
- saveValue: (selection?: Selection | undefined) => void;
77
- };
78
- export default useDatePicker;
79
- export interface DatePickerProviderProps {
80
- closePicker?: () => void;
81
- configuration?: DatePickerConfiguration;
82
- value?: Selection | StringSelection;
83
- }
84
- export declare function isSingleSelection(selection: Selection): selection is Date;
85
- export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
86
- export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
87
- export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
88
- export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
@@ -1,408 +0,0 @@
1
- import { CheckIcon, TrashIcon } from '@primer/octicons-react';
2
- import { format, isEqual, isAfter, isBefore, addMonths, subMonths, isToday, isWeekend, differenceInDays, addDays, subDays } from 'date-fns';
3
- import deepmerge from 'deepmerge';
4
- import React, { createContext, useCallback, useContext, useMemo, useEffect, useState } from 'react';
5
- import { Text, useConfirm } from '..';
6
- const DatePickerContext = /*#__PURE__*/createContext(null);
7
-
8
- const useDatePicker = date => {
9
- const value = useContext(DatePickerContext);
10
- const [selected, setSelected] = useState(false);
11
- const today = date ? isToday(date) : false;
12
-
13
- if (!value) {
14
- throw new Error('useDatePicker must be used inside a DatePickerProvider');
15
- }
16
-
17
- useEffect(() => {
18
- if (date) {
19
- if (value.hoverRange) {
20
- if (isRangeSelection(value.hoverRange)) {
21
- if (isEqual(date, value.hoverRange.from)) {
22
- setSelected('start');
23
- } else if (value.hoverRange.to && isEqual(date, value.hoverRange.to)) {
24
- setSelected('end');
25
- } else if (isAfter(date, value.hoverRange.from) && value.hoverRange.to && isBefore(date, value.hoverRange.to)) {
26
- setSelected('middle');
27
- } else {
28
- setSelected(false);
29
- }
30
- }
31
- } else if (value.selection) {
32
- if (isMultiSelection(value.selection)) {
33
- setSelected(!!value.selection.find(d => isEqual(d, date)));
34
- } else if (isRangeSelection(value.selection)) {
35
- if (isEqual(date, value.selection.from)) {
36
- setSelected('start');
37
- } else if (value.selection.to && isEqual(date, value.selection.to)) {
38
- setSelected('end');
39
- } else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
40
- setSelected('middle');
41
- } else {
42
- setSelected(false);
43
- }
44
- } else {
45
- setSelected(isEqual(date, value.selection));
46
- }
47
- }
48
- }
49
- }, [date, value.hoverRange, value.selection, today]);
50
- let blocked,
51
- disabled = false;
52
-
53
- if (date) {
54
- // Determine if date is blocked out
55
- if (value.configuration.blockedDates) {
56
- blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
57
- } // Determine if date is disabled
58
-
59
-
60
- if (value.configuration.minDate || value.configuration.maxDate || value.configuration.disableWeekends) {
61
- disabled = (value.configuration.minDate ? isBefore(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? isAfter(date, value.configuration.maxDate) : false) || (value.configuration.disableWeekends ? isWeekend(date) : false);
62
- }
63
- }
64
-
65
- return { ...value,
66
- blocked,
67
- disabled,
68
- selected,
69
- today
70
- };
71
- };
72
-
73
- export default useDatePicker;
74
- export function isSingleSelection(selection) {
75
- return selection instanceof Date;
76
- }
77
- export function isMultiSelection(selection) {
78
- return Array.isArray(selection);
79
- }
80
- export function isRangeSelection(selection) {
81
- return !!selection.from;
82
- }
83
- export function isStringRangeSelection(selection) {
84
- return !!selection.from;
85
- }
86
-
87
- function parseSelection(selection, variant) {
88
- if (!selection) return;
89
-
90
- if (variant === 'multi') {
91
- if (isMultiSelection(selection)) {
92
- const parsedSelection = [];
93
-
94
- for (const d of selection) {
95
- parsedSelection.push(new Date(new Date(d).toDateString()));
96
- }
97
-
98
- return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
99
- } else if (selection instanceof Date) {
100
- return [new Date(new Date(selection).toDateString())];
101
- } else if (isRangeSelection(selection)) {
102
- const parsedSelection = [];
103
- parsedSelection.push(new Date(new Date(selection.from).toDateString()));
104
-
105
- if (selection.to) {
106
- parsedSelection.push(new Date(new Date(selection.to).toDateString()));
107
- }
108
-
109
- return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
110
- }
111
- } else if (variant === 'range') {
112
- if (isRangeSelection(selection)) {
113
- return {
114
- from: new Date(new Date(selection.from).toDateString()),
115
- to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
116
- };
117
- } else if (isMultiSelection(selection)) {
118
- return {
119
- from: new Date(new Date(selection[0]).toDateString()),
120
- to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
121
- };
122
- } else if (selection instanceof Date) {
123
- return {
124
- from: new Date(new Date(selection).toDateString()),
125
- to: null
126
- };
127
- }
128
- } else {
129
- if (selection instanceof Date) {
130
- return new Date(new Date(selection).toDateString());
131
- } else if (isMultiSelection(selection)) {
132
- return new Date(new Date(selection[0]).toDateString());
133
- } else if (isRangeSelection(selection)) {
134
- return new Date(new Date(selection.from).toDateString());
135
- } else {
136
- return;
137
- }
138
- }
139
- }
140
-
141
- const defaultConfiguration = {
142
- anchorVariant: 'button',
143
- confirmation: false,
144
- confirmUnsavedClose: false,
145
- disableWeekends: false,
146
- iconPlacement: 'start',
147
- placeholder: 'Select a Date...',
148
- variant: 'single',
149
- view: '2-month',
150
- weekStartsOn: 'Sunday'
151
- };
152
- export const DatePickerProvider = ({
153
- configuration: externalConfig = {},
154
- children,
155
- closePicker,
156
- value
157
- }) => {
158
- const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
159
- const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.variant));
160
- const [isDirty, setIsDirty] = useState(false);
161
- const [selection, setSelection] = useState(parseSelection(value, configuration.variant));
162
- const [hoverRange, setHoverRange] = useState(null);
163
- const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
164
- const confirm = useConfirm();
165
- useEffect(() => {
166
- setConfiguration(deepmerge(defaultConfiguration, externalConfig));
167
- setSelection(parseSelection(selection, configuration.variant)); // Don't want this to run every time selection gets updated
168
- // eslint-disable-next-line react-hooks/exhaustive-deps
169
- }, [configuration.variant, externalConfig]);
170
- const goToMonth = useCallback(date => {
171
- setCurrentViewingDate(new Date(new Date(date).toDateString()));
172
- }, []);
173
- const nextMonth = useCallback(() => {
174
- setCurrentViewingDate(addMonths(currentViewingDate, 1));
175
- }, [currentViewingDate]);
176
- const previousMonth = useCallback(() => {
177
- setCurrentViewingDate(subMonths(currentViewingDate, 1));
178
- }, [currentViewingDate]);
179
- const getFormattedDate = useMemo(() => {
180
- if (!selection) {
181
- return configuration.placeholder;
182
- }
183
-
184
- const {
185
- anchorVariant,
186
- dateFormat,
187
- variant
188
- } = configuration;
189
- let template = 'MMM d';
190
-
191
- if (anchorVariant !== 'input' && dateFormat) {
192
- switch (dateFormat) {
193
- case 'short':
194
- template = 'MMM d';
195
- break;
196
-
197
- case 'long':
198
- template = 'MMM d, yyyy';
199
- break;
200
-
201
- default:
202
- template = dateFormat;
203
- break;
204
- }
205
- } else {
206
- template = 'MM/dd/yyyy';
207
- }
208
-
209
- switch (variant) {
210
- case 'single':
211
- {
212
- if (selection instanceof Date) {
213
- return format(selection, template);
214
- } else if (Array.isArray(selection)) {
215
- return format(selection[0], template);
216
- } else if (isRangeSelection(selection)) {
217
- return format(selection.from, template);
218
- } else {
219
- return 'Invalid Selection';
220
- }
221
- }
222
-
223
- case 'multi':
224
- {
225
- if (Array.isArray(selection)) {
226
- if (selection.length > 3) return `${selection.length} Selected`;
227
- const formatted = selection.map(d => format(d, template)).join(', ');
228
- return formatted;
229
- } else if (selection instanceof Date) {
230
- return [selection].map(d => format(d, template)).join(', ');
231
- } else if (isRangeSelection(selection)) {
232
- return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
233
- } else {
234
- return 'Invalid Selection';
235
- }
236
- }
237
-
238
- case 'range':
239
- {
240
- if (isRangeSelection(selection)) {
241
- return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
242
- } else if (selection instanceof Date) {
243
- return Object.entries({
244
- from: selection,
245
- to: null
246
- }).map(([_, date]) => date ? format(date, template) : '').join(' - ');
247
- } else if (Array.isArray(selection)) {
248
- return Object.entries({
249
- from: selection[0],
250
- to: selection[1]
251
- }) // to date can still be null
252
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
253
- .map(([_, date]) => date ? format(date, template) : '').join(' - ');
254
- } else {
255
- return 'Invalid Selection';
256
- }
257
- }
258
-
259
- default:
260
- {
261
- return 'Invalid Configuration';
262
- }
263
- }
264
- }, [configuration, selection]);
265
- const saveValue = useCallback(updatedSelection => {
266
- setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
267
- setIsDirty(false);
268
- closePicker === null || closePicker === void 0 ? void 0 : closePicker();
269
- }, [closePicker, selection]);
270
- const revertValue = useCallback(() => {
271
- setSelection(previousSelection);
272
- setIsDirty(false);
273
- }, [previousSelection]);
274
- const handleClose = useCallback(async () => {
275
- if (configuration.confirmUnsavedClose) {
276
- if (isDirty) {
277
- const result = await confirm({
278
- title: 'Save Changes?',
279
- content: 'You have unsaved changes, would you like to save them?',
280
- confirmButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CheckIcon, null), /*#__PURE__*/React.createElement(Text, {
281
- sx: {
282
- ml: 1
283
- }
284
- }, "Save")),
285
- cancelButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TrashIcon, null), /*#__PURE__*/React.createElement(Text, {
286
- sx: {
287
- ml: 1
288
- }
289
- }, "Discard"))
290
- });
291
-
292
- if (result) {
293
- saveValue();
294
- } else {
295
- revertValue();
296
- }
297
- }
298
- } else if (isDirty) revertValue();
299
- }, [configuration.confirmUnsavedClose, confirm, isDirty, revertValue, saveValue]);
300
- const inputHandler = useCallback(updatedSelection => {
301
- // validate date falls within range
302
- setSelection(updatedSelection);
303
- }, []);
304
- const selectionHandler = useCallback(date => {
305
- setIsDirty(true);
306
-
307
- if (configuration.variant === 'multi') {
308
- const selections = [...selection];
309
- const existingIndex = selections.findIndex(s => isEqual(s, date));
310
-
311
- if (existingIndex > -1) {
312
- selections.splice(existingIndex, 1);
313
- setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
314
- } else {
315
- if (configuration.maxSelections && selections.length + 1 > configuration.maxSelections) return;
316
- setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
317
- }
318
- } else if (configuration.variant === 'range') {
319
- if (selection && isRangeSelection(selection) && !selection.to) {
320
- let toDate = date;
321
-
322
- if (configuration.maxRangeSize && Math.abs(differenceInDays(selection.from, date)) >= configuration.maxRangeSize) {
323
- toDate = isBefore(date, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
324
- }
325
-
326
- const updatedSelection = isBefore(toDate, selection.from) ? {
327
- from: toDate,
328
- to: selection.from
329
- } : {
330
- from: selection.from,
331
- to: toDate
332
- };
333
- setSelection(updatedSelection);
334
- setHoverRange(null);
335
-
336
- if (!configuration.confirmation) {
337
- saveValue(updatedSelection);
338
- }
339
- } else {
340
- setHoverRange({
341
- from: date,
342
- to: date
343
- });
344
- setSelection({
345
- from: date,
346
- to: null
347
- });
348
- }
349
- } else {
350
- setSelection(date);
351
-
352
- if (!configuration.confirmation) {
353
- saveValue(date);
354
- }
355
- }
356
- }, [configuration.confirmation, configuration.maxRangeSize, configuration.maxSelections, configuration.variant, saveValue, selection]);
357
- const focusHnadler = useCallback(date => {
358
- if (!selection) return;
359
- const {
360
- minDate,
361
- maxDate,
362
- maxRangeSize,
363
- variant
364
- } = configuration;
365
-
366
- if (variant === 'range' && isRangeSelection(selection) && hoverRange) {
367
- let hoverDate = date;
368
- if (minDate) hoverDate = isBefore(date, minDate) ? minDate : hoverDate;
369
- if (maxDate) hoverDate = isAfter(date, maxDate) ? maxDate : hoverDate;
370
-
371
- if (maxRangeSize && Math.abs(differenceInDays(selection.from, hoverDate)) >= maxRangeSize) {
372
- hoverDate = isBefore(hoverDate, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
373
- }
374
-
375
- setHoverRange(isBefore(hoverDate, selection.from) ? {
376
- from: hoverDate,
377
- to: selection.from
378
- } : {
379
- from: selection.from,
380
- to: hoverDate
381
- });
382
- }
383
- }, [configuration, hoverRange, selection]);
384
- const datePickerCtx = useMemo(() => {
385
- return {
386
- configuration,
387
- currentViewingDate,
388
- disabled: false,
389
- formattedDate: getFormattedDate,
390
- goToMonth,
391
- hoverRange,
392
- nextMonth,
393
- onClose: handleClose,
394
- onDateInput: inputHandler,
395
- onDayFocus: focusHnadler,
396
- onSelection: selectionHandler,
397
- previousMonth,
398
- revertValue,
399
- saveValue,
400
- selectionActive: false,
401
- selection
402
- };
403
- }, [configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, handleClose, hoverRange, inputHandler, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
404
- return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
405
- value: datePickerCtx
406
- }, children);
407
- };
408
- 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;