@primer/components 0.0.0-202192515932 → 0.0.0-202192522854
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 +8 -4
- package/dist/browser.esm.js +616 -616
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +177 -177
- package/dist/browser.umd.js.map +1 -1
- 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 +92 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +137 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +39 -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 +174 -0
- package/lib/DatePicker/Month.d.ts +9 -0
- package/lib/DatePicker/Month.js +107 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +83 -0
- package/lib/DatePicker/useDatePicker.js +375 -0
- package/lib/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib/TextInputWithTokens.d.ts +4 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -8
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- 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 +75 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +111 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +24 -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 +151 -0
- package/lib-esm/DatePicker/Month.d.ts +9 -0
- package/lib-esm/DatePicker/Month.js +83 -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 +83 -0
- package/lib-esm/DatePicker/useDatePicker.js +347 -0
- package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib-esm/TextInputWithTokens.d.ts +4 -2
- package/lib-esm/index.d.ts +0 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -8
- package/lib/ActionList2/Description.d.ts +0 -6
- package/lib/ActionList2/Description.js +0 -53
- package/lib/ActionList2/Divider.d.ts +0 -8
- package/lib/ActionList2/Divider.js +0 -42
- package/lib/ActionList2/Group.d.ts +0 -8
- package/lib/ActionList2/Group.js +0 -39
- package/lib/ActionList2/Header.d.ts +0 -26
- package/lib/ActionList2/Header.js +0 -55
- package/lib/ActionList2/Item.d.ts +0 -48
- package/lib/ActionList2/Item.js +0 -189
- package/lib/ActionList2/List.d.ts +0 -18
- package/lib/ActionList2/List.js +0 -52
- package/lib/ActionList2/Selection.d.ts +0 -5
- package/lib/ActionList2/Selection.js +0 -67
- package/lib/ActionList2/Visuals.d.ts +0 -11
- package/lib/ActionList2/Visuals.js +0 -91
- package/lib/ActionList2/hacks.d.ts +0 -30
- package/lib/ActionList2/hacks.js +0 -38
- package/lib/ActionList2/index.d.ts +0 -26
- package/lib/ActionList2/index.js +0 -36
- package/lib/utils/create-slots.d.ts +0 -17
- package/lib/utils/create-slots.js +0 -105
- package/lib/utils/use-force-update.d.ts +0 -1
- package/lib/utils/use-force-update.js +0 -19
- package/lib-esm/ActionList2/Description.d.ts +0 -6
- package/lib-esm/ActionList2/Description.js +0 -38
- package/lib-esm/ActionList2/Divider.d.ts +0 -8
- package/lib-esm/ActionList2/Divider.js +0 -30
- package/lib-esm/ActionList2/Group.d.ts +0 -8
- package/lib-esm/ActionList2/Group.js +0 -29
- package/lib-esm/ActionList2/Header.d.ts +0 -26
- package/lib-esm/ActionList2/Header.js +0 -45
- package/lib-esm/ActionList2/Item.d.ts +0 -48
- package/lib-esm/ActionList2/Item.js +0 -182
- package/lib-esm/ActionList2/List.d.ts +0 -18
- package/lib-esm/ActionList2/List.js +0 -42
- package/lib-esm/ActionList2/Selection.d.ts +0 -5
- package/lib-esm/ActionList2/Selection.js +0 -50
- package/lib-esm/ActionList2/Visuals.d.ts +0 -11
- package/lib-esm/ActionList2/Visuals.js +0 -70
- package/lib-esm/ActionList2/hacks.d.ts +0 -30
- package/lib-esm/ActionList2/hacks.js +0 -30
- package/lib-esm/ActionList2/index.d.ts +0 -26
- package/lib-esm/ActionList2/index.js +0 -23
- package/lib-esm/utils/create-slots.d.ts +0 -17
- package/lib-esm/utils/create-slots.js +0 -84
- package/lib-esm/utils/use-force-update.d.ts +0 -1
- package/lib-esm/utils/use-force-update.js +0 -6
@@ -0,0 +1,375 @@
|
|
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 _dateFns = require("date-fns");
|
13
|
+
|
14
|
+
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
15
|
+
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
17
|
+
|
18
|
+
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); }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
const DatePickerContext = /*#__PURE__*/(0, _react.createContext)(null);
|
25
|
+
|
26
|
+
const useDatePicker = date => {
|
27
|
+
const value = (0, _react.useContext)(DatePickerContext);
|
28
|
+
const [selected, setSelected] = (0, _react.useState)(false);
|
29
|
+
|
30
|
+
if (!value) {
|
31
|
+
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
32
|
+
}
|
33
|
+
|
34
|
+
(0, _react.useEffect)(() => {
|
35
|
+
if (date) {
|
36
|
+
if (value.hoverRange) {
|
37
|
+
if (isRangeSelection(value.hoverRange)) {
|
38
|
+
if ((0, _dateFns.isEqual)(date, value.hoverRange.from)) {
|
39
|
+
setSelected('start');
|
40
|
+
} else if (value.hoverRange.to && (0, _dateFns.isEqual)(date, value.hoverRange.to)) {
|
41
|
+
setSelected('end');
|
42
|
+
} else if ((0, _dateFns.isAfter)(date, value.hoverRange.from) && value.hoverRange.to && (0, _dateFns.isBefore)(date, value.hoverRange.to)) {
|
43
|
+
setSelected('middle');
|
44
|
+
} else {
|
45
|
+
setSelected(false);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
} else if (value.selection) {
|
49
|
+
if (isMultiSelection(value.selection)) {
|
50
|
+
setSelected(!!value.selection.find(d => (0, _dateFns.isEqual)(d, date)));
|
51
|
+
} else if (isRangeSelection(value.selection)) {
|
52
|
+
if ((0, _dateFns.isEqual)(date, value.selection.from)) {
|
53
|
+
setSelected('start');
|
54
|
+
} else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
|
55
|
+
setSelected('end');
|
56
|
+
} else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
|
57
|
+
setSelected('middle');
|
58
|
+
} else {
|
59
|
+
setSelected(false);
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
setSelected((0, _dateFns.isEqual)(date, value.selection));
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}, [date, value.hoverRange, value.selection]);
|
67
|
+
let blocked,
|
68
|
+
disabled = false;
|
69
|
+
|
70
|
+
if (date) {
|
71
|
+
// Determine if date is blocked out
|
72
|
+
if (value.configuration.blockedDates) {
|
73
|
+
blocked = !!value.configuration.blockedDates.find(d => (0, _dateFns.isEqual)(d, date));
|
74
|
+
} // Determine if date is disabled
|
75
|
+
|
76
|
+
|
77
|
+
if (value.configuration.minDate || value.configuration.maxDate) {
|
78
|
+
disabled = (value.configuration.minDate ? (0, _dateFns.isBefore)(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? (0, _dateFns.isAfter)(date, value.configuration.maxDate) : false);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
return { ...value,
|
83
|
+
blocked,
|
84
|
+
disabled,
|
85
|
+
selected
|
86
|
+
};
|
87
|
+
};
|
88
|
+
|
89
|
+
var _default = useDatePicker;
|
90
|
+
exports.default = _default;
|
91
|
+
|
92
|
+
function isSingleSelection(selection) {
|
93
|
+
return selection instanceof Date;
|
94
|
+
}
|
95
|
+
|
96
|
+
function isMultiSelection(selection) {
|
97
|
+
return Array.isArray(selection);
|
98
|
+
}
|
99
|
+
|
100
|
+
function isRangeSelection(selection) {
|
101
|
+
return !!selection.from;
|
102
|
+
}
|
103
|
+
|
104
|
+
function isStringRangeSelection(selection) {
|
105
|
+
return !!selection.from;
|
106
|
+
}
|
107
|
+
|
108
|
+
function parseSelection(selection, variant) {
|
109
|
+
if (!selection) return;
|
110
|
+
|
111
|
+
if (variant === 'multi') {
|
112
|
+
if (isMultiSelection(selection)) {
|
113
|
+
const parsedSelection = [];
|
114
|
+
|
115
|
+
for (const d of selection) {
|
116
|
+
parsedSelection.push(new Date(new Date(d).toDateString()));
|
117
|
+
}
|
118
|
+
|
119
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
120
|
+
} else if (selection instanceof Date) {
|
121
|
+
return [new Date(new Date(selection).toDateString())];
|
122
|
+
} else if (isRangeSelection(selection)) {
|
123
|
+
const parsedSelection = [];
|
124
|
+
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
125
|
+
|
126
|
+
if (selection.to) {
|
127
|
+
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
128
|
+
}
|
129
|
+
|
130
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
131
|
+
}
|
132
|
+
} else if (variant === 'range') {
|
133
|
+
if (isRangeSelection(selection)) {
|
134
|
+
return {
|
135
|
+
from: new Date(new Date(selection.from).toDateString()),
|
136
|
+
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
137
|
+
};
|
138
|
+
} else if (isMultiSelection(selection)) {
|
139
|
+
return {
|
140
|
+
from: new Date(new Date(selection[0]).toDateString()),
|
141
|
+
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
142
|
+
};
|
143
|
+
} else if (selection instanceof Date) {
|
144
|
+
return {
|
145
|
+
from: new Date(new Date(selection).toDateString()),
|
146
|
+
to: null
|
147
|
+
};
|
148
|
+
}
|
149
|
+
} else {
|
150
|
+
if (selection instanceof Date) {
|
151
|
+
return new Date(new Date(selection).toDateString());
|
152
|
+
} else if (isMultiSelection(selection)) {
|
153
|
+
return new Date(new Date(selection[0]).toDateString());
|
154
|
+
} else if (isRangeSelection(selection)) {
|
155
|
+
return new Date(new Date(selection.from).toDateString());
|
156
|
+
} else {
|
157
|
+
return;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
const defaultConfiguration = {
|
163
|
+
anchorVariant: 'button',
|
164
|
+
confirmation: false,
|
165
|
+
contiguousSelection: false,
|
166
|
+
dimWeekends: false,
|
167
|
+
iconPlacement: 'start',
|
168
|
+
placeholder: 'Select a Date...',
|
169
|
+
selection: 'single',
|
170
|
+
view: '2-month',
|
171
|
+
weekStartsOn: 'Sunday'
|
172
|
+
};
|
173
|
+
|
174
|
+
const DatePickerProvider = ({
|
175
|
+
configuration: externalConfig = {},
|
176
|
+
children,
|
177
|
+
closePicker,
|
178
|
+
value
|
179
|
+
}) => {
|
180
|
+
const [configuration, setConfiguration] = (0, _react.useState)((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
181
|
+
const [previousSelection, setPreviousSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
|
182
|
+
const [selection, setSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
|
183
|
+
const [hoverRange, setHoverRange] = (0, _react.useState)(null);
|
184
|
+
const [currentViewingDate, setCurrentViewingDate] = (0, _react.useState)(new Date());
|
185
|
+
(0, _react.useEffect)(() => {
|
186
|
+
setConfiguration((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
187
|
+
setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
|
188
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
189
|
+
}, [configuration.selection, externalConfig]);
|
190
|
+
const goToMonth = (0, _react.useCallback)(date => {
|
191
|
+
setCurrentViewingDate(new Date(new Date(date).toDateString()));
|
192
|
+
}, []);
|
193
|
+
const nextMonth = (0, _react.useCallback)(() => {
|
194
|
+
setCurrentViewingDate((0, _dateFns.addMonths)(currentViewingDate, 1));
|
195
|
+
}, [currentViewingDate]);
|
196
|
+
const previousMonth = (0, _react.useCallback)(() => {
|
197
|
+
setCurrentViewingDate((0, _dateFns.subMonths)(currentViewingDate, 1));
|
198
|
+
}, [currentViewingDate]);
|
199
|
+
const getFormattedDate = (0, _react.useMemo)(() => {
|
200
|
+
if (!selection) {
|
201
|
+
return configuration.placeholder;
|
202
|
+
}
|
203
|
+
|
204
|
+
let template = 'MMM d';
|
205
|
+
|
206
|
+
if (configuration.anchorVariant !== 'input' && configuration.dateFormat) {
|
207
|
+
switch (configuration.dateFormat) {
|
208
|
+
case 'short':
|
209
|
+
template = 'MMM d';
|
210
|
+
break;
|
211
|
+
|
212
|
+
case 'long':
|
213
|
+
template = 'MMM d, yyyy';
|
214
|
+
break;
|
215
|
+
|
216
|
+
default:
|
217
|
+
template = configuration.dateFormat;
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
} else {
|
221
|
+
template = 'MM/dd/yyyy';
|
222
|
+
}
|
223
|
+
|
224
|
+
switch (configuration.selection) {
|
225
|
+
case 'single':
|
226
|
+
{
|
227
|
+
if (selection instanceof Date) {
|
228
|
+
return (0, _dateFns.format)(selection, template);
|
229
|
+
} else if (Array.isArray(selection)) {
|
230
|
+
return (0, _dateFns.format)(selection[0], template);
|
231
|
+
} else if (isRangeSelection(selection)) {
|
232
|
+
return (0, _dateFns.format)(selection.from, template);
|
233
|
+
} else {
|
234
|
+
return 'Invalid Selection';
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
case 'multi':
|
239
|
+
{
|
240
|
+
if (Array.isArray(selection)) {
|
241
|
+
if (selection.length > 3) return `${selection.length} Selected`;
|
242
|
+
const formatted = selection.map(d => (0, _dateFns.format)(d, template)).join(', ');
|
243
|
+
return formatted;
|
244
|
+
} else if (selection instanceof Date) {
|
245
|
+
return [selection].map(d => (0, _dateFns.format)(d, template)).join(', ');
|
246
|
+
} else if (isRangeSelection(selection)) {
|
247
|
+
return [selection.to, selection.from].map(d => d ? (0, _dateFns.format)(d, template) : '').join(', ');
|
248
|
+
} else {
|
249
|
+
return 'Invalid Selection';
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
case 'range':
|
254
|
+
{
|
255
|
+
if (isRangeSelection(selection)) {
|
256
|
+
return Object.entries(selection).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
257
|
+
} else if (selection instanceof Date) {
|
258
|
+
return Object.entries({
|
259
|
+
from: selection,
|
260
|
+
to: null
|
261
|
+
}).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
262
|
+
} else if (Array.isArray(selection)) {
|
263
|
+
return Object.entries({
|
264
|
+
from: selection[0],
|
265
|
+
to: selection[1]
|
266
|
+
}) // to date can still be null
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
268
|
+
.map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
269
|
+
} else {
|
270
|
+
return 'Invalid Selection';
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
default:
|
275
|
+
{
|
276
|
+
return 'Invalid Configuration';
|
277
|
+
}
|
278
|
+
}
|
279
|
+
}, [configuration.anchorVariant, configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
|
280
|
+
const saveValue = (0, _react.useCallback)(updatedSelection => {
|
281
|
+
setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
|
282
|
+
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
283
|
+
}, [closePicker, selection]);
|
284
|
+
const selectionHandler = (0, _react.useCallback)(date => {
|
285
|
+
if (configuration.selection === 'multi') {
|
286
|
+
const selections = [...selection];
|
287
|
+
const existingIndex = selections.findIndex(s => (0, _dateFns.isEqual)(s, date));
|
288
|
+
|
289
|
+
if (existingIndex > -1) {
|
290
|
+
selections.splice(existingIndex, 1);
|
291
|
+
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
292
|
+
} else {
|
293
|
+
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
294
|
+
}
|
295
|
+
} else if (configuration.selection === 'range') {
|
296
|
+
if (selection && isRangeSelection(selection) && !selection.to) {
|
297
|
+
const updatedSelection = (0, _dateFns.isBefore)(date, selection.from) ? {
|
298
|
+
from: date,
|
299
|
+
to: selection.from
|
300
|
+
} : {
|
301
|
+
from: selection.from,
|
302
|
+
to: date
|
303
|
+
};
|
304
|
+
setSelection(updatedSelection);
|
305
|
+
setHoverRange(null);
|
306
|
+
|
307
|
+
if (!configuration.confirmation) {
|
308
|
+
saveValue(updatedSelection);
|
309
|
+
}
|
310
|
+
} else {
|
311
|
+
setHoverRange({
|
312
|
+
from: date,
|
313
|
+
to: date
|
314
|
+
});
|
315
|
+
setSelection({
|
316
|
+
from: date,
|
317
|
+
to: null
|
318
|
+
});
|
319
|
+
}
|
320
|
+
} else {
|
321
|
+
setSelection(date);
|
322
|
+
|
323
|
+
if (!configuration.confirmation) {
|
324
|
+
saveValue(date);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
}, [configuration.confirmation, configuration.selection, saveValue, selection]);
|
328
|
+
const focusHnadler = (0, _react.useCallback)(date => {
|
329
|
+
if (!selection) return;
|
330
|
+
|
331
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
|
332
|
+
setHoverRange((0, _dateFns.isBefore)(date, selection.from) ? {
|
333
|
+
from: date,
|
334
|
+
to: selection.from
|
335
|
+
} : {
|
336
|
+
from: selection.from,
|
337
|
+
to: date
|
338
|
+
});
|
339
|
+
}
|
340
|
+
}, [configuration.selection, hoverRange, selection]);
|
341
|
+
const blurHnadler = (0, _react.useCallback)(date => {
|
342
|
+
if (!selection || !hoverRange) return;
|
343
|
+
|
344
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
|
345
|
+
}
|
346
|
+
}, [configuration.selection, hoverRange, selection]);
|
347
|
+
const revertValue = (0, _react.useCallback)(() => {
|
348
|
+
setSelection(previousSelection);
|
349
|
+
}, [previousSelection]);
|
350
|
+
const datePickerCtx = (0, _react.useMemo)(() => {
|
351
|
+
return {
|
352
|
+
configuration,
|
353
|
+
currentViewingDate,
|
354
|
+
disabled: false,
|
355
|
+
formattedDate: getFormattedDate,
|
356
|
+
goToMonth,
|
357
|
+
hoverRange,
|
358
|
+
nextMonth,
|
359
|
+
onDayBlur: blurHnadler,
|
360
|
+
onDayFocus: focusHnadler,
|
361
|
+
onSelection: selectionHandler,
|
362
|
+
previousMonth,
|
363
|
+
revertValue,
|
364
|
+
saveValue,
|
365
|
+
selectionActive: false,
|
366
|
+
selection
|
367
|
+
};
|
368
|
+
}, [blurHnadler, configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, hoverRange, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
|
369
|
+
return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
|
370
|
+
value: datePickerCtx
|
371
|
+
}, children);
|
372
|
+
};
|
373
|
+
|
374
|
+
exports.DatePickerProvider = DatePickerProvider;
|
375
|
+
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"> & {
|
package/lib/index.d.ts
CHANGED
@@ -22,7 +22,6 @@ export { useOnEscapePress } from './hooks/useOnEscapePress';
|
|
22
22
|
export { useOverlay } from './hooks/useOverlay';
|
23
23
|
export { useConfirm } from './Dialog/ConfirmationDialog';
|
24
24
|
export { ActionList } from './ActionList';
|
25
|
-
export { ActionList as ActionList2 } from './ActionList2';
|
26
25
|
export { ActionMenu } from './ActionMenu';
|
27
26
|
export type { ActionMenuProps } from './ActionMenu';
|
28
27
|
export { default as Autocomplete } from './Autocomplete';
|
package/lib/index.js
CHANGED
@@ -147,12 +147,6 @@ Object.defineProperty(exports, "ActionList", {
|
|
147
147
|
return _ActionList.ActionList;
|
148
148
|
}
|
149
149
|
});
|
150
|
-
Object.defineProperty(exports, "ActionList2", {
|
151
|
-
enumerable: true,
|
152
|
-
get: function () {
|
153
|
-
return _ActionList2.ActionList;
|
154
|
-
}
|
155
|
-
});
|
156
150
|
Object.defineProperty(exports, "ActionMenu", {
|
157
151
|
enumerable: true,
|
158
152
|
get: function () {
|
@@ -542,8 +536,6 @@ var _ConfirmationDialog = require("./Dialog/ConfirmationDialog");
|
|
542
536
|
|
543
537
|
var _ActionList = require("./ActionList");
|
544
538
|
|
545
|
-
var _ActionList2 = require("./ActionList2");
|
546
|
-
|
547
539
|
var _ActionMenu = require("./ActionMenu");
|
548
540
|
|
549
541
|
var _Autocomplete = _interopRequireDefault(require("./Autocomplete"));
|
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;
|
@@ -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 {};
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
2
|
+
import { DatePickerAnchor } from './DatePickerAnchor';
|
3
|
+
import { DatePickerProvider } from './useDatePicker';
|
4
|
+
import { DatePickerOverlay } from './DatePickerOverlay';
|
5
|
+
export const DatePicker = ({
|
6
|
+
anchorVariant,
|
7
|
+
anchorRef: externalAnchorRef,
|
8
|
+
confirmation,
|
9
|
+
dateFormat,
|
10
|
+
focusTrapSettings,
|
11
|
+
focusZoneSettings,
|
12
|
+
maxDate,
|
13
|
+
minDate,
|
14
|
+
onOpen: onOpenExternal,
|
15
|
+
onClose: onCloseExternal,
|
16
|
+
open,
|
17
|
+
overlayProps,
|
18
|
+
renderAnchor,
|
19
|
+
selection,
|
20
|
+
value,
|
21
|
+
view,
|
22
|
+
weekStartsOn
|
23
|
+
}) => {
|
24
|
+
const buttonRef = useRef(null);
|
25
|
+
const [isOpen, setIsOpen] = useState(false);
|
26
|
+
const datePickerConfiguration = {
|
27
|
+
anchorVariant,
|
28
|
+
confirmation,
|
29
|
+
dateFormat,
|
30
|
+
maxDate,
|
31
|
+
minDate,
|
32
|
+
selection,
|
33
|
+
view,
|
34
|
+
weekStartsOn
|
35
|
+
};
|
36
|
+
|
37
|
+
const onOpen = gesture => {
|
38
|
+
setIsOpen(true);
|
39
|
+
onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
|
40
|
+
};
|
41
|
+
|
42
|
+
const onClose = gesture => {
|
43
|
+
setIsOpen(false);
|
44
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
|
45
|
+
};
|
46
|
+
|
47
|
+
const toggleIsOpen = () => {
|
48
|
+
if (isOpen) {
|
49
|
+
setIsOpen(false);
|
50
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
|
51
|
+
} else {
|
52
|
+
setIsOpen(true);
|
53
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
return /*#__PURE__*/React.createElement(DatePickerProvider, {
|
58
|
+
configuration: datePickerConfiguration,
|
59
|
+
value: value,
|
60
|
+
closePicker: () => setIsOpen(false)
|
61
|
+
}, /*#__PURE__*/React.createElement(DatePickerAnchor, {
|
62
|
+
ref: buttonRef,
|
63
|
+
onAction: toggleIsOpen
|
64
|
+
}), /*#__PURE__*/React.createElement(DatePickerOverlay, {
|
65
|
+
anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : buttonRef,
|
66
|
+
renderAnchor: renderAnchor,
|
67
|
+
open: open !== null && open !== void 0 ? open : isOpen,
|
68
|
+
onOpen: onOpen,
|
69
|
+
onClose: onClose,
|
70
|
+
overlayProps: overlayProps,
|
71
|
+
focusTrapSettings: focusTrapSettings,
|
72
|
+
focusZoneSettings: focusZoneSettings
|
73
|
+
}));
|
74
|
+
};
|
75
|
+
DatePicker.displayName = "DatePicker";
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface DatePickerAnchorProps {
|
3
|
+
onAction?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
4
|
+
}
|
5
|
+
export declare const DatePickerAnchor: React.ForwardRefExoticComponent<DatePickerAnchorProps & React.RefAttributes<HTMLDivElement>>;
|