@primer/components 0.0.0-202192822657 → 0.0.0-2021929142717
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.
- package/CHANGELOG.md +23 -1
- package/dist/browser.esm.js +53 -49
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +50 -46
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.d.ts +6 -0
- package/lib/ActionList/Item.js +5 -1
- package/lib/ActionList2/Description.d.ts +6 -0
- package/lib/ActionList2/Description.js +53 -0
- package/lib/ActionList2/Divider.d.ts +5 -0
- package/lib/ActionList2/Divider.js +33 -0
- package/lib/ActionList2/Group.d.ts +11 -0
- package/lib/ActionList2/Group.js +55 -0
- package/lib/ActionList2/Header.d.ts +26 -0
- package/lib/ActionList2/Header.js +55 -0
- package/lib/ActionList2/Item.d.ts +48 -0
- package/lib/ActionList2/Item.js +204 -0
- package/lib/ActionList2/List.d.ts +26 -0
- package/lib/ActionList2/List.js +56 -0
- package/lib/ActionList2/Selection.d.ts +5 -0
- package/lib/ActionList2/Selection.js +73 -0
- package/lib/ActionList2/Visuals.d.ts +11 -0
- package/lib/ActionList2/Visuals.js +90 -0
- package/lib/ActionList2/hacks.d.ts +30 -0
- package/lib/ActionList2/hacks.js +38 -0
- package/lib/ActionList2/index.d.ts +28 -0
- package/lib/ActionList2/index.js +42 -0
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib/Autocomplete/Autocomplete.d.ts +6 -8
- package/lib/Autocomplete/AutocompleteInput.d.ts +6 -8
- package/lib/Button/Button.d.ts +4 -4
- package/lib/Button/ButtonClose.d.ts +21 -21
- package/lib/Button/ButtonDanger.d.ts +4 -4
- package/lib/Button/ButtonInvisible.d.ts +4 -4
- package/lib/Button/ButtonOutline.d.ts +4 -4
- package/lib/Button/ButtonPrimary.d.ts +4 -4
- package/lib/CircleOcticon.d.ts +19 -19
- package/lib/Dialog.d.ts +21 -21
- package/lib/Dropdown.d.ts +82 -82
- package/lib/DropdownMenu/DropdownButton.d.ts +23 -23
- package/lib/FilterList.d.ts +19 -19
- package/lib/Position.d.ts +4 -4
- package/lib/SelectMenu/SelectMenu.d.ts +105 -107
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +10 -8
- package/lib/TextInputWithTokens.js +102 -29
- package/lib/Timeline.d.ts +19 -19
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/Token/Token.js +13 -2
- package/lib/Token/TokenBase.js +0 -4
- package/lib/Token/_RemoveTokenButton.js +15 -2
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/experiments.d.ts +1 -0
- package/lib/experiments.js +18 -0
- package/lib/sx.d.ts +2 -0
- package/lib/sx.js +8 -0
- package/lib/theme-preval.js +2 -2
- package/lib/utils/create-slots.d.ts +17 -0
- package/lib/utils/create-slots.js +105 -0
- package/lib/utils/testing.d.ts +1 -1
- package/lib/utils/use-force-update.d.ts +1 -0
- package/lib/utils/use-force-update.js +19 -0
- package/lib-esm/ActionList/Item.d.ts +6 -0
- package/lib-esm/ActionList/Item.js +5 -1
- package/lib-esm/ActionList2/Description.d.ts +6 -0
- package/lib-esm/ActionList2/Description.js +37 -0
- package/lib-esm/ActionList2/Divider.d.ts +5 -0
- package/lib-esm/ActionList2/Divider.js +21 -0
- package/lib-esm/ActionList2/Group.d.ts +11 -0
- package/lib-esm/ActionList2/Group.js +38 -0
- package/lib-esm/ActionList2/Header.d.ts +26 -0
- package/lib-esm/ActionList2/Header.js +45 -0
- package/lib-esm/ActionList2/Item.d.ts +48 -0
- package/lib-esm/ActionList2/Item.js +176 -0
- package/lib-esm/ActionList2/List.d.ts +26 -0
- package/lib-esm/ActionList2/List.js +38 -0
- package/lib-esm/ActionList2/Selection.d.ts +5 -0
- package/lib-esm/ActionList2/Selection.js +55 -0
- package/lib-esm/ActionList2/Visuals.d.ts +11 -0
- package/lib-esm/ActionList2/Visuals.js +68 -0
- package/lib-esm/ActionList2/hacks.d.ts +30 -0
- package/lib-esm/ActionList2/hacks.js +30 -0
- package/lib-esm/ActionList2/index.d.ts +28 -0
- package/lib-esm/ActionList2/index.js +29 -0
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib-esm/Autocomplete/Autocomplete.d.ts +6 -8
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +6 -8
- package/lib-esm/Button/Button.d.ts +4 -4
- package/lib-esm/Button/ButtonClose.d.ts +21 -21
- package/lib-esm/Button/ButtonDanger.d.ts +4 -4
- package/lib-esm/Button/ButtonInvisible.d.ts +4 -4
- package/lib-esm/Button/ButtonOutline.d.ts +4 -4
- package/lib-esm/Button/ButtonPrimary.d.ts +4 -4
- package/lib-esm/CircleOcticon.d.ts +19 -19
- package/lib-esm/Dialog.d.ts +21 -21
- package/lib-esm/Dropdown.d.ts +82 -82
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +23 -23
- package/lib-esm/FilterList.d.ts +19 -19
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/SelectMenu/SelectMenu.d.ts +105 -107
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +10 -8
- package/lib-esm/TextInputWithTokens.js +101 -30
- package/lib-esm/Timeline.d.ts +19 -19
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/Token/Token.js +13 -2
- package/lib-esm/Token/TokenBase.js +0 -4
- package/lib-esm/Token/_RemoveTokenButton.js +11 -2
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/experiments.d.ts +1 -0
- package/lib-esm/experiments.js +2 -0
- package/lib-esm/sx.d.ts +2 -0
- package/lib-esm/sx.js +3 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/create-slots.d.ts +17 -0
- package/lib-esm/utils/create-slots.js +84 -0
- package/lib-esm/utils/testing.d.ts +1 -1
- package/lib-esm/utils/use-force-update.d.ts +1 -0
- package/lib-esm/utils/use-force-update.js +6 -0
- package/package.json +16 -14
- package/lib/DatePicker/DatePicker.d.ts +0 -48
- package/lib/DatePicker/DatePicker.js +0 -106
- package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib/DatePicker/DatePickerAnchor.js +0 -194
- package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib/DatePicker/DatePickerOverlay.js +0 -48
- package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib/DatePicker/DatePickerPanel.js +0 -126
- package/lib/DatePicker/Day.d.ts +0 -14
- package/lib/DatePicker/Day.js +0 -190
- package/lib/DatePicker/Month.d.ts +0 -9
- package/lib/DatePicker/Month.js +0 -120
- package/lib/DatePicker/dateParser.d.ts +0 -11
- package/lib/DatePicker/dateParser.js +0 -188
- package/lib/DatePicker/index.d.ts +0 -2
- package/lib/DatePicker/index.js +0 -13
- package/lib/DatePicker/useDatePicker.d.ts +0 -89
- package/lib/DatePicker/useDatePicker.js +0 -370
- package/lib/hooks/useDebounce.d.ts +0 -2
- package/lib/hooks/useDebounce.js +0 -24
- package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
- package/lib-esm/DatePicker/DatePicker.js +0 -89
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib-esm/DatePicker/DatePickerAnchor.js +0 -167
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
- package/lib-esm/DatePicker/Day.d.ts +0 -14
- package/lib-esm/DatePicker/Day.js +0 -167
- package/lib-esm/DatePicker/Month.d.ts +0 -9
- package/lib-esm/DatePicker/Month.js +0 -96
- package/lib-esm/DatePicker/dateParser.d.ts +0 -11
- package/lib-esm/DatePicker/dateParser.js +0 -174
- package/lib-esm/DatePicker/index.d.ts +0 -2
- package/lib-esm/DatePicker/index.js +0 -1
- package/lib-esm/DatePicker/useDatePicker.d.ts +0 -89
- package/lib-esm/DatePicker/useDatePicker.js +0 -339
- package/lib-esm/hooks/useDebounce.d.ts +0 -2
- package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,339 +0,0 @@
|
|
1
|
-
import { CheckIcon, TrashIcon } from '@primer/octicons-react';
|
2
|
-
import { 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
|
-
import { formatDate } from './dateParser';
|
7
|
-
const DatePickerContext = /*#__PURE__*/createContext(null);
|
8
|
-
|
9
|
-
const useDatePicker = date => {
|
10
|
-
const value = useContext(DatePickerContext);
|
11
|
-
const [selected, setSelected] = useState(false);
|
12
|
-
const today = date ? isToday(date) : false;
|
13
|
-
|
14
|
-
if (!value) {
|
15
|
-
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
16
|
-
}
|
17
|
-
|
18
|
-
useEffect(() => {
|
19
|
-
if (date) {
|
20
|
-
if (value.hoverRange) {
|
21
|
-
if (isRangeSelection(value.hoverRange)) {
|
22
|
-
if (isEqual(date, value.hoverRange.from)) {
|
23
|
-
setSelected('start');
|
24
|
-
} else if (value.hoverRange.to && isEqual(date, value.hoverRange.to)) {
|
25
|
-
setSelected('end');
|
26
|
-
} else if (isAfter(date, value.hoverRange.from) && value.hoverRange.to && isBefore(date, value.hoverRange.to)) {
|
27
|
-
setSelected('middle');
|
28
|
-
} else {
|
29
|
-
setSelected(false);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
} else if (value.selection) {
|
33
|
-
if (isMultiSelection(value.selection)) {
|
34
|
-
setSelected(!!value.selection.find(d => isEqual(d, date)));
|
35
|
-
} else if (isRangeSelection(value.selection)) {
|
36
|
-
if (isEqual(date, value.selection.from)) {
|
37
|
-
setSelected('start');
|
38
|
-
} else if (value.selection.to && isEqual(date, value.selection.to)) {
|
39
|
-
setSelected('end');
|
40
|
-
} else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
|
41
|
-
setSelected('middle');
|
42
|
-
} else {
|
43
|
-
setSelected(false);
|
44
|
-
}
|
45
|
-
} else {
|
46
|
-
setSelected(isEqual(date, value.selection));
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}, [date, value.hoverRange, value.selection, today]);
|
51
|
-
let blocked,
|
52
|
-
disabled = false;
|
53
|
-
|
54
|
-
if (date) {
|
55
|
-
// Determine if date is blocked out
|
56
|
-
if (value.configuration.blockedDates) {
|
57
|
-
blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
|
58
|
-
} // Determine if date is disabled
|
59
|
-
|
60
|
-
|
61
|
-
if (value.configuration.minDate || value.configuration.maxDate || value.configuration.disableWeekends) {
|
62
|
-
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);
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
return { ...value,
|
67
|
-
blocked,
|
68
|
-
disabled,
|
69
|
-
selected,
|
70
|
-
today
|
71
|
-
};
|
72
|
-
};
|
73
|
-
|
74
|
-
export default useDatePicker;
|
75
|
-
export function isSingleSelection(selection) {
|
76
|
-
return selection instanceof Date;
|
77
|
-
}
|
78
|
-
export function isMultiSelection(selection) {
|
79
|
-
return Array.isArray(selection);
|
80
|
-
}
|
81
|
-
export function isRangeSelection(selection) {
|
82
|
-
return !!selection.from;
|
83
|
-
}
|
84
|
-
export function isStringRangeSelection(selection) {
|
85
|
-
return !!selection.from;
|
86
|
-
}
|
87
|
-
|
88
|
-
function parseSelection(selection, variant) {
|
89
|
-
if (!selection) return;
|
90
|
-
|
91
|
-
if (variant === 'multi') {
|
92
|
-
if (isMultiSelection(selection)) {
|
93
|
-
const parsedSelection = [];
|
94
|
-
|
95
|
-
for (const d of selection) {
|
96
|
-
parsedSelection.push(new Date(new Date(d).toDateString()));
|
97
|
-
}
|
98
|
-
|
99
|
-
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
100
|
-
} else if (selection instanceof Date) {
|
101
|
-
return [new Date(new Date(selection).toDateString())];
|
102
|
-
} else if (isRangeSelection(selection)) {
|
103
|
-
const parsedSelection = [];
|
104
|
-
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
105
|
-
|
106
|
-
if (selection.to) {
|
107
|
-
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
108
|
-
}
|
109
|
-
|
110
|
-
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
111
|
-
}
|
112
|
-
} else if (variant === 'range') {
|
113
|
-
if (isRangeSelection(selection)) {
|
114
|
-
return {
|
115
|
-
from: new Date(new Date(selection.from).toDateString()),
|
116
|
-
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
117
|
-
};
|
118
|
-
} else if (isMultiSelection(selection)) {
|
119
|
-
return {
|
120
|
-
from: new Date(new Date(selection[0]).toDateString()),
|
121
|
-
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
122
|
-
};
|
123
|
-
} else if (selection instanceof Date) {
|
124
|
-
return {
|
125
|
-
from: new Date(new Date(selection).toDateString()),
|
126
|
-
to: null
|
127
|
-
};
|
128
|
-
}
|
129
|
-
} else {
|
130
|
-
if (selection instanceof Date) {
|
131
|
-
return new Date(new Date(selection).toDateString());
|
132
|
-
} else if (isMultiSelection(selection)) {
|
133
|
-
return new Date(new Date(selection[0]).toDateString());
|
134
|
-
} else if (isRangeSelection(selection)) {
|
135
|
-
return new Date(new Date(selection.from).toDateString());
|
136
|
-
} else {
|
137
|
-
return;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
const defaultConfiguration = {
|
143
|
-
anchorVariant: 'button',
|
144
|
-
confirmation: false,
|
145
|
-
confirmUnsavedClose: false,
|
146
|
-
disableWeekends: false,
|
147
|
-
iconPlacement: 'start',
|
148
|
-
placeholder: 'Select a Date...',
|
149
|
-
showInputPrompt: false,
|
150
|
-
variant: 'single',
|
151
|
-
view: '2-month',
|
152
|
-
weekStartsOn: 'Sunday'
|
153
|
-
};
|
154
|
-
export const DatePickerProvider = ({
|
155
|
-
configuration: externalConfig = {},
|
156
|
-
children,
|
157
|
-
closePicker,
|
158
|
-
value
|
159
|
-
}) => {
|
160
|
-
const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
|
161
|
-
const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.variant));
|
162
|
-
const [isDirty, setIsDirty] = useState(false);
|
163
|
-
const [selection, setSelection] = useState(parseSelection(value, configuration.variant));
|
164
|
-
const [hoverRange, setHoverRange] = useState(null);
|
165
|
-
const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
|
166
|
-
const confirm = useConfirm();
|
167
|
-
useEffect(() => {
|
168
|
-
setConfiguration(deepmerge(defaultConfiguration, externalConfig));
|
169
|
-
setSelection(parseSelection(selection, configuration.variant)); // Don't want this to run every time selection gets updated
|
170
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
171
|
-
}, [configuration.variant, externalConfig]);
|
172
|
-
const goToMonth = useCallback(date => {
|
173
|
-
setCurrentViewingDate(new Date(new Date(date).toDateString()));
|
174
|
-
}, []);
|
175
|
-
const nextMonth = useCallback(() => {
|
176
|
-
setCurrentViewingDate(addMonths(currentViewingDate, 1));
|
177
|
-
}, [currentViewingDate]);
|
178
|
-
const previousMonth = useCallback(() => {
|
179
|
-
setCurrentViewingDate(subMonths(currentViewingDate, 1));
|
180
|
-
}, [currentViewingDate]);
|
181
|
-
const getFormattedDate = useMemo(() => {
|
182
|
-
const {
|
183
|
-
anchorVariant,
|
184
|
-
dateFormat,
|
185
|
-
placeholder,
|
186
|
-
variant
|
187
|
-
} = configuration;
|
188
|
-
return formatDate({
|
189
|
-
selection,
|
190
|
-
anchorVariant,
|
191
|
-
dateFormat,
|
192
|
-
placeholder,
|
193
|
-
variant
|
194
|
-
});
|
195
|
-
}, [configuration, selection]);
|
196
|
-
const saveValue = useCallback(updatedSelection => {
|
197
|
-
setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
|
198
|
-
setIsDirty(false);
|
199
|
-
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
200
|
-
}, [closePicker, selection]);
|
201
|
-
const revertValue = useCallback(() => {
|
202
|
-
setSelection(previousSelection);
|
203
|
-
setIsDirty(false);
|
204
|
-
}, [previousSelection]);
|
205
|
-
const handleClose = useCallback(async () => {
|
206
|
-
if (configuration.confirmUnsavedClose) {
|
207
|
-
if (isDirty) {
|
208
|
-
const result = await confirm({
|
209
|
-
title: 'Save Changes?',
|
210
|
-
content: 'You have unsaved changes, would you like to save them?',
|
211
|
-
confirmButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CheckIcon, null), /*#__PURE__*/React.createElement(Text, {
|
212
|
-
sx: {
|
213
|
-
ml: 1
|
214
|
-
}
|
215
|
-
}, "Save")),
|
216
|
-
cancelButtonContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TrashIcon, null), /*#__PURE__*/React.createElement(Text, {
|
217
|
-
sx: {
|
218
|
-
ml: 1
|
219
|
-
}
|
220
|
-
}, "Discard"))
|
221
|
-
});
|
222
|
-
|
223
|
-
if (result) {
|
224
|
-
saveValue();
|
225
|
-
} else {
|
226
|
-
revertValue();
|
227
|
-
}
|
228
|
-
}
|
229
|
-
} else if (isDirty) revertValue();
|
230
|
-
}, [configuration.confirmUnsavedClose, confirm, isDirty, revertValue, saveValue]);
|
231
|
-
const inputHandler = useCallback(updatedSelection => {
|
232
|
-
// validate date falls within range
|
233
|
-
setSelection(updatedSelection);
|
234
|
-
}, []);
|
235
|
-
const selectionHandler = useCallback(date => {
|
236
|
-
setIsDirty(true);
|
237
|
-
|
238
|
-
if (configuration.variant === 'multi') {
|
239
|
-
const selections = [...selection];
|
240
|
-
const existingIndex = selections.findIndex(s => isEqual(s, date));
|
241
|
-
|
242
|
-
if (existingIndex > -1) {
|
243
|
-
selections.splice(existingIndex, 1);
|
244
|
-
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
245
|
-
} else {
|
246
|
-
if (configuration.maxSelections && selections.length + 1 > configuration.maxSelections) return;
|
247
|
-
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
248
|
-
}
|
249
|
-
} else if (configuration.variant === 'range') {
|
250
|
-
if (selection && isRangeSelection(selection) && !selection.to) {
|
251
|
-
let toDate = date;
|
252
|
-
|
253
|
-
if (configuration.maxRangeSize && Math.abs(differenceInDays(selection.from, date)) >= configuration.maxRangeSize) {
|
254
|
-
toDate = isBefore(date, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
|
255
|
-
}
|
256
|
-
|
257
|
-
const updatedSelection = isBefore(toDate, selection.from) ? {
|
258
|
-
from: toDate,
|
259
|
-
to: selection.from
|
260
|
-
} : {
|
261
|
-
from: selection.from,
|
262
|
-
to: toDate
|
263
|
-
};
|
264
|
-
setSelection(updatedSelection);
|
265
|
-
setHoverRange(null);
|
266
|
-
|
267
|
-
if (!configuration.confirmation) {
|
268
|
-
saveValue(updatedSelection);
|
269
|
-
}
|
270
|
-
} else {
|
271
|
-
setHoverRange({
|
272
|
-
from: date,
|
273
|
-
to: date
|
274
|
-
});
|
275
|
-
setSelection({
|
276
|
-
from: date,
|
277
|
-
to: null
|
278
|
-
});
|
279
|
-
}
|
280
|
-
} else {
|
281
|
-
setSelection(date);
|
282
|
-
|
283
|
-
if (!configuration.confirmation) {
|
284
|
-
saveValue(date);
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}, [configuration.confirmation, configuration.maxRangeSize, configuration.maxSelections, configuration.variant, saveValue, selection]);
|
288
|
-
const focusHnadler = useCallback(date => {
|
289
|
-
if (!selection) return;
|
290
|
-
const {
|
291
|
-
minDate,
|
292
|
-
maxDate,
|
293
|
-
maxRangeSize,
|
294
|
-
variant
|
295
|
-
} = configuration;
|
296
|
-
|
297
|
-
if (variant === 'range' && isRangeSelection(selection) && hoverRange) {
|
298
|
-
let hoverDate = date;
|
299
|
-
if (minDate) hoverDate = isBefore(date, minDate) ? minDate : hoverDate;
|
300
|
-
if (maxDate) hoverDate = isAfter(date, maxDate) ? maxDate : hoverDate;
|
301
|
-
|
302
|
-
if (maxRangeSize && Math.abs(differenceInDays(selection.from, hoverDate)) >= maxRangeSize) {
|
303
|
-
hoverDate = isBefore(hoverDate, selection.from) ? subDays(selection.from, configuration.maxRangeSize - 1) : addDays(selection.from, configuration.maxRangeSize - 1);
|
304
|
-
}
|
305
|
-
|
306
|
-
setHoverRange(isBefore(hoverDate, selection.from) ? {
|
307
|
-
from: hoverDate,
|
308
|
-
to: selection.from
|
309
|
-
} : {
|
310
|
-
from: selection.from,
|
311
|
-
to: hoverDate
|
312
|
-
});
|
313
|
-
}
|
314
|
-
}, [configuration, hoverRange, selection]);
|
315
|
-
const datePickerCtx = useMemo(() => {
|
316
|
-
return {
|
317
|
-
configuration,
|
318
|
-
currentViewingDate,
|
319
|
-
disabled: false,
|
320
|
-
formattedDate: getFormattedDate,
|
321
|
-
goToMonth,
|
322
|
-
hoverRange,
|
323
|
-
nextMonth,
|
324
|
-
onClose: handleClose,
|
325
|
-
onDateInput: inputHandler,
|
326
|
-
onDayFocus: focusHnadler,
|
327
|
-
onSelection: selectionHandler,
|
328
|
-
previousMonth,
|
329
|
-
revertValue,
|
330
|
-
saveValue,
|
331
|
-
selectionActive: false,
|
332
|
-
selection
|
333
|
-
};
|
334
|
-
}, [configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, handleClose, hoverRange, inputHandler, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
|
335
|
-
return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
|
336
|
-
value: datePickerCtx
|
337
|
-
}, children);
|
338
|
-
};
|
339
|
-
DatePickerProvider.displayName = "DatePickerProvider";
|
@@ -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;
|