@primer/components 0.0.0-20219273337 → 0.0.0-202192801738
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 +1 -7
- package/dist/browser.esm.js +22 -22
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +3 -3
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.d.ts +0 -6
- package/lib/ActionList/Item.js +1 -5
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib/DatePicker/DatePicker.d.ts +48 -0
- package/lib/DatePicker/DatePicker.js +104 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +182 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +48 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +126 -0
- package/lib/DatePicker/Day.d.ts +14 -0
- package/lib/DatePicker/Day.js +190 -0
- package/lib/DatePicker/Month.d.ts +9 -0
- package/lib/DatePicker/Month.js +120 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +88 -0
- package/lib/DatePicker/useDatePicker.js +438 -0
- package/lib/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib/TextInputWithTokens.d.ts +4 -2
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/ActionList/Item.d.ts +0 -6
- package/lib-esm/ActionList/Item.js +1 -5
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
- package/lib-esm/DatePicker/DatePicker.js +87 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +155 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +29 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +100 -0
- package/lib-esm/DatePicker/Day.d.ts +14 -0
- package/lib-esm/DatePicker/Day.js +167 -0
- package/lib-esm/DatePicker/Month.d.ts +9 -0
- package/lib-esm/DatePicker/Month.js +96 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +88 -0
- package/lib-esm/DatePicker/useDatePicker.js +408 -0
- package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib-esm/TextInputWithTokens.d.ts +4 -2
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +14 -14
@@ -0,0 +1,438 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isSingleSelection = isSingleSelection;
|
7
|
+
exports.isMultiSelection = isMultiSelection;
|
8
|
+
exports.isRangeSelection = isRangeSelection;
|
9
|
+
exports.isStringRangeSelection = isStringRangeSelection;
|
10
|
+
exports.DatePickerProvider = exports.default = void 0;
|
11
|
+
|
12
|
+
var _octiconsReact = require("@primer/octicons-react");
|
13
|
+
|
14
|
+
var _dateFns = require("date-fns");
|
15
|
+
|
16
|
+
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
17
|
+
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
19
|
+
|
20
|
+
var _2 = require("..");
|
21
|
+
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
23
|
+
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
25
|
+
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
27
|
+
|
28
|
+
const DatePickerContext = /*#__PURE__*/(0, _react.createContext)(null);
|
29
|
+
|
30
|
+
const useDatePicker = date => {
|
31
|
+
const value = (0, _react.useContext)(DatePickerContext);
|
32
|
+
const [selected, setSelected] = (0, _react.useState)(false);
|
33
|
+
const today = date ? (0, _dateFns.isToday)(date) : false;
|
34
|
+
|
35
|
+
if (!value) {
|
36
|
+
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
37
|
+
}
|
38
|
+
|
39
|
+
(0, _react.useEffect)(() => {
|
40
|
+
if (date) {
|
41
|
+
if (value.hoverRange) {
|
42
|
+
if (isRangeSelection(value.hoverRange)) {
|
43
|
+
if ((0, _dateFns.isEqual)(date, value.hoverRange.from)) {
|
44
|
+
setSelected('start');
|
45
|
+
} else if (value.hoverRange.to && (0, _dateFns.isEqual)(date, value.hoverRange.to)) {
|
46
|
+
setSelected('end');
|
47
|
+
} else if ((0, _dateFns.isAfter)(date, value.hoverRange.from) && value.hoverRange.to && (0, _dateFns.isBefore)(date, value.hoverRange.to)) {
|
48
|
+
setSelected('middle');
|
49
|
+
} else {
|
50
|
+
setSelected(false);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
} else if (value.selection) {
|
54
|
+
if (isMultiSelection(value.selection)) {
|
55
|
+
setSelected(!!value.selection.find(d => (0, _dateFns.isEqual)(d, date)));
|
56
|
+
} else if (isRangeSelection(value.selection)) {
|
57
|
+
if ((0, _dateFns.isEqual)(date, value.selection.from)) {
|
58
|
+
setSelected('start');
|
59
|
+
} else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
|
60
|
+
setSelected('end');
|
61
|
+
} else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
|
62
|
+
setSelected('middle');
|
63
|
+
} else {
|
64
|
+
setSelected(false);
|
65
|
+
}
|
66
|
+
} else {
|
67
|
+
setSelected((0, _dateFns.isEqual)(date, value.selection));
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}, [date, value.hoverRange, value.selection, today]);
|
72
|
+
let blocked,
|
73
|
+
disabled = false;
|
74
|
+
|
75
|
+
if (date) {
|
76
|
+
// Determine if date is blocked out
|
77
|
+
if (value.configuration.blockedDates) {
|
78
|
+
blocked = !!value.configuration.blockedDates.find(d => (0, _dateFns.isEqual)(d, date));
|
79
|
+
} // Determine if date is disabled
|
80
|
+
|
81
|
+
|
82
|
+
if (value.configuration.minDate || value.configuration.maxDate || value.configuration.disableWeekends) {
|
83
|
+
disabled = (value.configuration.minDate ? (0, _dateFns.isBefore)(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? (0, _dateFns.isAfter)(date, value.configuration.maxDate) : false) || (value.configuration.disableWeekends ? (0, _dateFns.isWeekend)(date) : false);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
return { ...value,
|
88
|
+
blocked,
|
89
|
+
disabled,
|
90
|
+
selected,
|
91
|
+
today
|
92
|
+
};
|
93
|
+
};
|
94
|
+
|
95
|
+
var _default = useDatePicker;
|
96
|
+
exports.default = _default;
|
97
|
+
|
98
|
+
function isSingleSelection(selection) {
|
99
|
+
return selection instanceof Date;
|
100
|
+
}
|
101
|
+
|
102
|
+
function isMultiSelection(selection) {
|
103
|
+
return Array.isArray(selection);
|
104
|
+
}
|
105
|
+
|
106
|
+
function isRangeSelection(selection) {
|
107
|
+
return !!selection.from;
|
108
|
+
}
|
109
|
+
|
110
|
+
function isStringRangeSelection(selection) {
|
111
|
+
return !!selection.from;
|
112
|
+
}
|
113
|
+
|
114
|
+
function parseSelection(selection, variant) {
|
115
|
+
if (!selection) return;
|
116
|
+
|
117
|
+
if (variant === 'multi') {
|
118
|
+
if (isMultiSelection(selection)) {
|
119
|
+
const parsedSelection = [];
|
120
|
+
|
121
|
+
for (const d of selection) {
|
122
|
+
parsedSelection.push(new Date(new Date(d).toDateString()));
|
123
|
+
}
|
124
|
+
|
125
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
126
|
+
} else if (selection instanceof Date) {
|
127
|
+
return [new Date(new Date(selection).toDateString())];
|
128
|
+
} else if (isRangeSelection(selection)) {
|
129
|
+
const parsedSelection = [];
|
130
|
+
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
131
|
+
|
132
|
+
if (selection.to) {
|
133
|
+
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
134
|
+
}
|
135
|
+
|
136
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
137
|
+
}
|
138
|
+
} else if (variant === 'range') {
|
139
|
+
if (isRangeSelection(selection)) {
|
140
|
+
return {
|
141
|
+
from: new Date(new Date(selection.from).toDateString()),
|
142
|
+
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
143
|
+
};
|
144
|
+
} else if (isMultiSelection(selection)) {
|
145
|
+
return {
|
146
|
+
from: new Date(new Date(selection[0]).toDateString()),
|
147
|
+
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
148
|
+
};
|
149
|
+
} else if (selection instanceof Date) {
|
150
|
+
return {
|
151
|
+
from: new Date(new Date(selection).toDateString()),
|
152
|
+
to: null
|
153
|
+
};
|
154
|
+
}
|
155
|
+
} else {
|
156
|
+
if (selection instanceof Date) {
|
157
|
+
return new Date(new Date(selection).toDateString());
|
158
|
+
} else if (isMultiSelection(selection)) {
|
159
|
+
return new Date(new Date(selection[0]).toDateString());
|
160
|
+
} else if (isRangeSelection(selection)) {
|
161
|
+
return new Date(new Date(selection.from).toDateString());
|
162
|
+
} else {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
const defaultConfiguration = {
|
169
|
+
anchorVariant: 'button',
|
170
|
+
confirmation: false,
|
171
|
+
confirmUnsavedClose: false,
|
172
|
+
disableWeekends: false,
|
173
|
+
iconPlacement: 'start',
|
174
|
+
placeholder: 'Select a Date...',
|
175
|
+
variant: 'single',
|
176
|
+
view: '2-month',
|
177
|
+
weekStartsOn: 'Sunday'
|
178
|
+
};
|
179
|
+
|
180
|
+
const DatePickerProvider = ({
|
181
|
+
configuration: externalConfig = {},
|
182
|
+
children,
|
183
|
+
closePicker,
|
184
|
+
value
|
185
|
+
}) => {
|
186
|
+
const [configuration, setConfiguration] = (0, _react.useState)((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
187
|
+
const [previousSelection, setPreviousSelection] = (0, _react.useState)(parseSelection(value, configuration.variant));
|
188
|
+
const [isDirty, setIsDirty] = (0, _react.useState)(false);
|
189
|
+
const [selection, setSelection] = (0, _react.useState)(parseSelection(value, configuration.variant));
|
190
|
+
const [hoverRange, setHoverRange] = (0, _react.useState)(null);
|
191
|
+
const [currentViewingDate, setCurrentViewingDate] = (0, _react.useState)(new Date());
|
192
|
+
const confirm = (0, _2.useConfirm)();
|
193
|
+
(0, _react.useEffect)(() => {
|
194
|
+
setConfiguration((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
195
|
+
setSelection(parseSelection(selection, configuration.variant)); // Don't want this to run every time selection gets updated
|
196
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
197
|
+
}, [configuration.variant, externalConfig]);
|
198
|
+
const goToMonth = (0, _react.useCallback)(date => {
|
199
|
+
setCurrentViewingDate(new Date(new Date(date).toDateString()));
|
200
|
+
}, []);
|
201
|
+
const nextMonth = (0, _react.useCallback)(() => {
|
202
|
+
setCurrentViewingDate((0, _dateFns.addMonths)(currentViewingDate, 1));
|
203
|
+
}, [currentViewingDate]);
|
204
|
+
const previousMonth = (0, _react.useCallback)(() => {
|
205
|
+
setCurrentViewingDate((0, _dateFns.subMonths)(currentViewingDate, 1));
|
206
|
+
}, [currentViewingDate]);
|
207
|
+
const getFormattedDate = (0, _react.useMemo)(() => {
|
208
|
+
if (!selection) {
|
209
|
+
return configuration.placeholder;
|
210
|
+
}
|
211
|
+
|
212
|
+
const {
|
213
|
+
anchorVariant,
|
214
|
+
dateFormat,
|
215
|
+
variant
|
216
|
+
} = configuration;
|
217
|
+
let template = 'MMM d';
|
218
|
+
|
219
|
+
if (anchorVariant !== 'input' && dateFormat) {
|
220
|
+
switch (dateFormat) {
|
221
|
+
case 'short':
|
222
|
+
template = 'MMM d';
|
223
|
+
break;
|
224
|
+
|
225
|
+
case 'long':
|
226
|
+
template = 'MMM d, yyyy';
|
227
|
+
break;
|
228
|
+
|
229
|
+
default:
|
230
|
+
template = dateFormat;
|
231
|
+
break;
|
232
|
+
}
|
233
|
+
} else {
|
234
|
+
template = 'MM/dd/yyyy';
|
235
|
+
}
|
236
|
+
|
237
|
+
switch (variant) {
|
238
|
+
case 'single':
|
239
|
+
{
|
240
|
+
if (selection instanceof Date) {
|
241
|
+
return (0, _dateFns.format)(selection, template);
|
242
|
+
} else if (Array.isArray(selection)) {
|
243
|
+
return (0, _dateFns.format)(selection[0], template);
|
244
|
+
} else if (isRangeSelection(selection)) {
|
245
|
+
return (0, _dateFns.format)(selection.from, template);
|
246
|
+
} else {
|
247
|
+
return 'Invalid Selection';
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
case 'multi':
|
252
|
+
{
|
253
|
+
if (Array.isArray(selection)) {
|
254
|
+
if (selection.length > 3) return `${selection.length} Selected`;
|
255
|
+
const formatted = selection.map(d => (0, _dateFns.format)(d, template)).join(', ');
|
256
|
+
return formatted;
|
257
|
+
} else if (selection instanceof Date) {
|
258
|
+
return [selection].map(d => (0, _dateFns.format)(d, template)).join(', ');
|
259
|
+
} else if (isRangeSelection(selection)) {
|
260
|
+
return [selection.to, selection.from].map(d => d ? (0, _dateFns.format)(d, template) : '').join(', ');
|
261
|
+
} else {
|
262
|
+
return 'Invalid Selection';
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
case 'range':
|
267
|
+
{
|
268
|
+
if (isRangeSelection(selection)) {
|
269
|
+
return Object.entries(selection).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
270
|
+
} else if (selection instanceof Date) {
|
271
|
+
return Object.entries({
|
272
|
+
from: selection,
|
273
|
+
to: null
|
274
|
+
}).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
275
|
+
} else if (Array.isArray(selection)) {
|
276
|
+
return Object.entries({
|
277
|
+
from: selection[0],
|
278
|
+
to: selection[1]
|
279
|
+
}) // to date can still be null
|
280
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
281
|
+
.map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
282
|
+
} else {
|
283
|
+
return 'Invalid Selection';
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
default:
|
288
|
+
{
|
289
|
+
return 'Invalid Configuration';
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}, [configuration, selection]);
|
293
|
+
const saveValue = (0, _react.useCallback)(updatedSelection => {
|
294
|
+
setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
|
295
|
+
setIsDirty(false);
|
296
|
+
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
297
|
+
}, [closePicker, selection]);
|
298
|
+
const revertValue = (0, _react.useCallback)(() => {
|
299
|
+
setSelection(previousSelection);
|
300
|
+
setIsDirty(false);
|
301
|
+
}, [previousSelection]);
|
302
|
+
const handleClose = (0, _react.useCallback)(async () => {
|
303
|
+
if (configuration.confirmUnsavedClose) {
|
304
|
+
if (isDirty) {
|
305
|
+
const result = await confirm({
|
306
|
+
title: 'Save Changes?',
|
307
|
+
content: 'You have unsaved changes, would you like to save them?',
|
308
|
+
confirmButtonContent: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_octiconsReact.CheckIcon, null), /*#__PURE__*/_react.default.createElement(_2.Text, {
|
309
|
+
sx: {
|
310
|
+
ml: 1
|
311
|
+
}
|
312
|
+
}, "Save")),
|
313
|
+
cancelButtonContent: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_octiconsReact.TrashIcon, null), /*#__PURE__*/_react.default.createElement(_2.Text, {
|
314
|
+
sx: {
|
315
|
+
ml: 1
|
316
|
+
}
|
317
|
+
}, "Discard"))
|
318
|
+
});
|
319
|
+
|
320
|
+
if (result) {
|
321
|
+
saveValue();
|
322
|
+
} else {
|
323
|
+
revertValue();
|
324
|
+
}
|
325
|
+
}
|
326
|
+
} else if (isDirty) revertValue();
|
327
|
+
}, [configuration.confirmUnsavedClose, confirm, isDirty, revertValue, saveValue]);
|
328
|
+
const inputHandler = (0, _react.useCallback)(updatedSelection => {
|
329
|
+
// validate date falls within range
|
330
|
+
setSelection(updatedSelection);
|
331
|
+
}, []);
|
332
|
+
const selectionHandler = (0, _react.useCallback)(date => {
|
333
|
+
setIsDirty(true);
|
334
|
+
|
335
|
+
if (configuration.variant === 'multi') {
|
336
|
+
const selections = [...selection];
|
337
|
+
const existingIndex = selections.findIndex(s => (0, _dateFns.isEqual)(s, date));
|
338
|
+
|
339
|
+
if (existingIndex > -1) {
|
340
|
+
selections.splice(existingIndex, 1);
|
341
|
+
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
342
|
+
} else {
|
343
|
+
if (configuration.maxSelections && selections.length + 1 > configuration.maxSelections) return;
|
344
|
+
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
345
|
+
}
|
346
|
+
} else if (configuration.variant === 'range') {
|
347
|
+
if (selection && isRangeSelection(selection) && !selection.to) {
|
348
|
+
let toDate = date;
|
349
|
+
|
350
|
+
if (configuration.maxRangeSize && Math.abs((0, _dateFns.differenceInDays)(selection.from, date)) >= configuration.maxRangeSize) {
|
351
|
+
toDate = (0, _dateFns.isBefore)(date, selection.from) ? (0, _dateFns.subDays)(selection.from, configuration.maxRangeSize - 1) : (0, _dateFns.addDays)(selection.from, configuration.maxRangeSize - 1);
|
352
|
+
}
|
353
|
+
|
354
|
+
const updatedSelection = (0, _dateFns.isBefore)(toDate, selection.from) ? {
|
355
|
+
from: toDate,
|
356
|
+
to: selection.from
|
357
|
+
} : {
|
358
|
+
from: selection.from,
|
359
|
+
to: toDate
|
360
|
+
};
|
361
|
+
setSelection(updatedSelection);
|
362
|
+
setHoverRange(null);
|
363
|
+
|
364
|
+
if (!configuration.confirmation) {
|
365
|
+
saveValue(updatedSelection);
|
366
|
+
}
|
367
|
+
} else {
|
368
|
+
setHoverRange({
|
369
|
+
from: date,
|
370
|
+
to: date
|
371
|
+
});
|
372
|
+
setSelection({
|
373
|
+
from: date,
|
374
|
+
to: null
|
375
|
+
});
|
376
|
+
}
|
377
|
+
} else {
|
378
|
+
setSelection(date);
|
379
|
+
|
380
|
+
if (!configuration.confirmation) {
|
381
|
+
saveValue(date);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}, [configuration.confirmation, configuration.maxRangeSize, configuration.maxSelections, configuration.variant, saveValue, selection]);
|
385
|
+
const focusHnadler = (0, _react.useCallback)(date => {
|
386
|
+
if (!selection) return;
|
387
|
+
const {
|
388
|
+
minDate,
|
389
|
+
maxDate,
|
390
|
+
maxRangeSize,
|
391
|
+
variant
|
392
|
+
} = configuration;
|
393
|
+
|
394
|
+
if (variant === 'range' && isRangeSelection(selection) && hoverRange) {
|
395
|
+
let hoverDate = date;
|
396
|
+
if (minDate) hoverDate = (0, _dateFns.isBefore)(date, minDate) ? minDate : hoverDate;
|
397
|
+
if (maxDate) hoverDate = (0, _dateFns.isAfter)(date, maxDate) ? maxDate : hoverDate;
|
398
|
+
|
399
|
+
if (maxRangeSize && Math.abs((0, _dateFns.differenceInDays)(selection.from, hoverDate)) >= maxRangeSize) {
|
400
|
+
hoverDate = (0, _dateFns.isBefore)(hoverDate, selection.from) ? (0, _dateFns.subDays)(selection.from, configuration.maxRangeSize - 1) : (0, _dateFns.addDays)(selection.from, configuration.maxRangeSize - 1);
|
401
|
+
}
|
402
|
+
|
403
|
+
setHoverRange((0, _dateFns.isBefore)(hoverDate, selection.from) ? {
|
404
|
+
from: hoverDate,
|
405
|
+
to: selection.from
|
406
|
+
} : {
|
407
|
+
from: selection.from,
|
408
|
+
to: hoverDate
|
409
|
+
});
|
410
|
+
}
|
411
|
+
}, [configuration, hoverRange, selection]);
|
412
|
+
const datePickerCtx = (0, _react.useMemo)(() => {
|
413
|
+
return {
|
414
|
+
configuration,
|
415
|
+
currentViewingDate,
|
416
|
+
disabled: false,
|
417
|
+
formattedDate: getFormattedDate,
|
418
|
+
goToMonth,
|
419
|
+
hoverRange,
|
420
|
+
nextMonth,
|
421
|
+
onClose: handleClose,
|
422
|
+
onDateInput: inputHandler,
|
423
|
+
onDayFocus: focusHnadler,
|
424
|
+
onSelection: selectionHandler,
|
425
|
+
previousMonth,
|
426
|
+
revertValue,
|
427
|
+
saveValue,
|
428
|
+
selectionActive: false,
|
429
|
+
selection
|
430
|
+
};
|
431
|
+
}, [configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, handleClose, hoverRange, inputHandler, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
|
432
|
+
return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
|
433
|
+
value: datePickerCtx
|
434
|
+
}, children);
|
435
|
+
};
|
436
|
+
|
437
|
+
exports.DatePickerProvider = DatePickerProvider;
|
438
|
+
DatePickerProvider.displayName = "DatePickerProvider";
|
@@ -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"> & {
|
@@ -32,12 +32,14 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
|
32
32
|
* Whether the remove buttons should be rendered in the tokens
|
33
33
|
*/
|
34
34
|
hideTokenRemoveButtons?: boolean | 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"> & {
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
function useDebounce(value, delay) {
|
11
|
+
const [debouncedValue, setDebouncedValue] = (0, _react.useState)(value);
|
12
|
+
(0, _react.useEffect)(() => {
|
13
|
+
const handler = setTimeout(() => {
|
14
|
+
setDebouncedValue(value);
|
15
|
+
}, delay);
|
16
|
+
return () => {
|
17
|
+
clearTimeout(handler);
|
18
|
+
};
|
19
|
+
}, [value, delay]);
|
20
|
+
return debouncedValue;
|
21
|
+
}
|
22
|
+
|
23
|
+
var _default = useDebounce;
|
24
|
+
exports.default = _default;
|
package/lib/theme-preval.js
CHANGED
@@ -515,7 +515,7 @@ module.exports = {
|
|
515
515
|
}
|
516
516
|
}
|
517
517
|
},
|
518
|
-
"
|
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
|
-
"
|
2459
|
+
"dark_colorblind": {
|
2460
2460
|
"colors": {
|
2461
2461
|
"canvasDefaultTransparent": "rgba(13,17,23,0)",
|
2462
2462
|
"marketingIcon": {
|
package/lib/utils/testing.d.ts
CHANGED
@@ -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" | "
|
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;
|
@@ -28,19 +28,13 @@ export interface ItemProps extends SxProp {
|
|
28
28
|
*/
|
29
29
|
leadingVisual?: React.FunctionComponent<IconProps>;
|
30
30
|
/**
|
31
|
-
* @deprecated Use `trailingVisual` instead
|
32
31
|
* Icon (or similar) positioned after `Item` text.
|
33
32
|
*/
|
34
33
|
trailingIcon?: React.FunctionComponent<IconProps>;
|
35
34
|
/**
|
36
|
-
* @deprecated Use `trailingVisual` instead
|
37
35
|
* Text positioned after `Item` text and optional trailing icon.
|
38
36
|
*/
|
39
37
|
trailingText?: string;
|
40
|
-
/**
|
41
|
-
* Icon or text positioned after `Item` text.
|
42
|
-
*/
|
43
|
-
trailingVisual?: React.ReactNode;
|
44
38
|
/**
|
45
39
|
* Style variations associated with various `Item` types.
|
46
40
|
*
|
@@ -154,7 +154,6 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
154
154
|
selectionVariant,
|
155
155
|
leadingVisual: LeadingVisual,
|
156
156
|
trailingIcon: TrailingIcon,
|
157
|
-
trailingVisual: TrailingVisual,
|
158
157
|
trailingText,
|
159
158
|
variant = 'default',
|
160
159
|
showDivider,
|
@@ -246,10 +245,7 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
246
245
|
title: description,
|
247
246
|
inline: true,
|
248
247
|
maxWidth: "100%"
|
249
|
-
}, description)) : null),
|
250
|
-
variant: variant,
|
251
|
-
disabled: disabled
|
252
|
-
}, typeof TrailingVisual === 'function' ? /*#__PURE__*/React.createElement(TrailingVisual, null) : TrailingVisual) : TrailingIcon || trailingText ? /*#__PURE__*/React.createElement(TrailingContent, {
|
248
|
+
}, description)) : null), TrailingIcon || trailingText ? /*#__PURE__*/React.createElement(TrailingContent, {
|
253
249
|
variant: variant,
|
254
250
|
disabled: disabled
|
255
251
|
}, trailingText, TrailingIcon && /*#__PURE__*/React.createElement(TrailingIcon, null)) : null));
|
@@ -26,6 +26,8 @@ interface AnchoredOverlayPropsWithoutAnchor {
|
|
26
26
|
*/
|
27
27
|
anchorRef: React.RefObject<HTMLElement>;
|
28
28
|
}
|
29
|
+
export declare type OverlayOpenGesture = 'anchor-click' | 'anchor-key-press';
|
30
|
+
export declare type OverlayCloseGesture = 'anchor-click' | 'click-outside' | 'escape';
|
29
31
|
export declare type AnchoredOverlayWrapperAnchorProps = Partial<AnchoredOverlayPropsWithAnchor> | AnchoredOverlayPropsWithoutAnchor;
|
30
32
|
interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'> {
|
31
33
|
/**
|
@@ -35,11 +37,11 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
|
|
35
37
|
/**
|
36
38
|
* A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
|
37
39
|
*/
|
38
|
-
onOpen?: (gesture:
|
40
|
+
onOpen?: (gesture: OverlayOpenGesture) => unknown;
|
39
41
|
/**
|
40
42
|
* A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
|
41
43
|
*/
|
42
|
-
onClose?: (gesture:
|
44
|
+
onClose?: (gesture: OverlayCloseGesture) => unknown;
|
43
45
|
/**
|
44
46
|
* Props to be spread on the internal `Overlay` component.
|
45
47
|
*/
|
@@ -12,12 +12,14 @@ export type { AutocompleteOverlayProps } from './AutocompleteOverlay';
|
|
12
12
|
declare const _default: React.FC<{
|
13
13
|
id?: string | undefined;
|
14
14
|
}> & {
|
15
|
-
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
|
15
|
+
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<({
|
16
16
|
[x: string]: any;
|
17
17
|
[x: number]: any;
|
18
18
|
} & {
|
19
19
|
theme?: any;
|
20
|
-
} & {
|
20
|
+
} & ({} | {
|
21
|
+
children?: React.ReactNode;
|
22
|
+
})) & {
|
21
23
|
as?: string | React.ComponentType<any> | undefined;
|
22
24
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
23
25
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -4,12 +4,14 @@ import { ComponentProps } from '../utils/types';
|
|
4
4
|
declare type InternalAutocompleteInputProps = {
|
5
5
|
as?: React.ComponentType<any>;
|
6
6
|
};
|
7
|
-
declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
|
7
|
+
declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<({
|
8
8
|
[x: string]: any;
|
9
9
|
[x: number]: any;
|
10
10
|
} & {
|
11
11
|
theme?: any;
|
12
|
-
} & {
|
12
|
+
} & ({} | {
|
13
|
+
children?: React.ReactNode;
|
14
|
+
})) & {
|
13
15
|
as?: string | React.ComponentType<any> | undefined;
|
14
16
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
15
17
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { OverlayProps } from '../Overlay';
|
3
|
+
import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
|
4
|
+
import { FocusZoneHookSettings } from '../hooks/useFocusZone';
|
5
|
+
import { DatePickerConfiguration, Selection } from './useDatePicker';
|
6
|
+
declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
|
7
|
+
declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
|
8
|
+
export interface DatePickerProps extends DatePickerConfiguration {
|
9
|
+
/**
|
10
|
+
* An override to the internal ref that will be spread on to the renderAnchor
|
11
|
+
*/
|
12
|
+
anchorRef?: React.RefObject<HTMLElement>;
|
13
|
+
/**
|
14
|
+
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
15
|
+
*/
|
16
|
+
focusTrapSettings?: Partial<FocusTrapHookSettings>;
|
17
|
+
/**
|
18
|
+
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
19
|
+
*/
|
20
|
+
focusZoneSettings?: Partial<FocusZoneHookSettings>;
|
21
|
+
initialValue?: 'today' | Date | string | null;
|
22
|
+
iconOnly?: boolean;
|
23
|
+
placeholder?: string;
|
24
|
+
/**
|
25
|
+
* Determines whether the overlay portion of the component should be shown or not
|
26
|
+
*/
|
27
|
+
open?: boolean;
|
28
|
+
/**
|
29
|
+
* A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
|
30
|
+
*/
|
31
|
+
onOpen?: (gesture: OpenGesture) => unknown;
|
32
|
+
/**
|
33
|
+
* A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
|
34
|
+
*/
|
35
|
+
onClose?: (gesture: CloseGesture) => unknown;
|
36
|
+
/**
|
37
|
+
* Props to be spread on the internal `Overlay` component.
|
38
|
+
*/
|
39
|
+
overlayProps?: Partial<OverlayProps>;
|
40
|
+
/**
|
41
|
+
* A custom function component used to render the anchor element.
|
42
|
+
* Will receive the selected text as `children` prop when an item is activated.
|
43
|
+
*/
|
44
|
+
renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
|
45
|
+
value?: Selection;
|
46
|
+
}
|
47
|
+
export declare const DatePicker: React.FC<DatePickerProps>;
|
48
|
+
export {};
|