@mui/x-date-pickers 7.19.0 → 7.21.0
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/AdapterDayjs/AdapterDayjs.js +2 -0
- package/CHANGELOG.md +224 -43
- package/DateCalendar/DateCalendar.js +1 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateField/DateField.types.d.ts +2 -7
- package/DateField/index.d.ts +1 -1
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +8 -1
- package/DatePicker/index.d.ts +1 -1
- package/DateTimeField/DateTimeField.types.d.ts +2 -7
- package/DateTimeField/index.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.js +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +9 -1
- package/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/DateTimePicker/index.d.ts +1 -1
- package/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/DigitalClock/DigitalClock.js +33 -0
- package/MobileDatePicker/MobileDatePicker.js +1 -1
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/PickersSectionList/PickersSectionList.d.ts +9 -0
- package/PickersSectionList/PickersSectionList.js +30 -9
- package/StaticDatePicker/StaticDatePicker.js +1 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/TimeClock/Clock.js +8 -0
- package/TimeField/TimeField.types.d.ts +2 -7
- package/TimeField/index.d.ts +1 -1
- package/TimePicker/TimePicker.types.d.ts +9 -1
- package/TimePicker/index.d.ts +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useParsedFormat.d.ts +15 -0
- package/hooks/useParsedFormat.js +43 -0
- package/hooks/usePickersContext.d.ts +4 -0
- package/hooks/usePickersContext.js +15 -0
- package/index.js +1 -1
- package/internals/components/PickersProvider.d.ts +34 -0
- package/internals/components/PickersProvider.js +26 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -5
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -2
- package/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/internals/hooks/useField/useField.js +1 -1
- package/internals/hooks/useField/useField.utils.d.ts +3 -3
- package/internals/hooks/useField/useField.utils.js +13 -13
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.js +3 -5
- package/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/internals/hooks/usePicker/usePicker.js +10 -1
- package/internals/hooks/usePicker/usePicker.types.d.ts +2 -1
- package/internals/hooks/usePicker/usePickerOwnerState.d.ts +9 -0
- package/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
- package/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +2 -0
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/internals/utils/utils.d.ts +7 -0
- package/internals/utils/utils.js +11 -0
- package/models/pickers.d.ts +19 -1
- package/modern/AdapterDayjs/AdapterDayjs.js +2 -0
- package/modern/DateCalendar/DateCalendar.js +1 -1
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/modern/DigitalClock/DigitalClock.js +33 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/modern/PickersSectionList/PickersSectionList.js +30 -9
- package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/modern/TimeClock/Clock.js +8 -0
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useParsedFormat.js +43 -0
- package/modern/hooks/usePickersContext.js +15 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersProvider.js +26 -0
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/modern/internals/hooks/useField/useField.js +1 -1
- package/modern/internals/hooks/useField/useField.utils.js +13 -13
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.js +3 -5
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/modern/internals/hooks/usePicker/usePicker.js +10 -1
- package/modern/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
- package/modern/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/modern/internals/index.js +1 -0
- package/modern/internals/utils/utils.js +11 -0
- package/node/AdapterDayjs/AdapterDayjs.js +2 -0
- package/node/DateCalendar/DateCalendar.js +1 -1
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DateTimePicker/DateTimePicker.js +1 -1
- package/node/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/node/DigitalClock/DigitalClock.js +33 -0
- package/node/MobileDatePicker/MobileDatePicker.js +1 -1
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/node/PickersSectionList/PickersSectionList.js +30 -9
- package/node/StaticDatePicker/StaticDatePicker.js +1 -1
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/node/TimeClock/Clock.js +8 -0
- package/node/hooks/index.js +15 -1
- package/node/hooks/useParsedFormat.js +50 -0
- package/node/hooks/usePickersContext.js +21 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickersProvider.js +34 -0
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +7 -9
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/node/internals/hooks/useField/useField.js +1 -1
- package/node/internals/hooks/useField/useField.utils.js +13 -13
- package/node/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/node/internals/hooks/useField/useFieldState.js +3 -5
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +5 -3
- package/node/internals/hooks/usePicker/usePicker.js +10 -1
- package/node/internals/hooks/usePicker/usePickerOwnerState.js +20 -0
- package/node/internals/hooks/usePicker/usePickerValue.js +7 -1
- package/node/internals/index.js +7 -0
- package/node/internals/utils/utils.js +13 -1
- package/package.json +4 -4
|
@@ -32,4 +32,15 @@ export const getActiveElement = (root = document) => {
|
|
|
32
32
|
}
|
|
33
33
|
return activeEl;
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the index of the focused list item in a given ul list element.
|
|
38
|
+
*
|
|
39
|
+
* @param {HTMLUListElement} listElement - The list element to search within.
|
|
40
|
+
* @returns {number} The index of the focused list item, or -1 if none is focused.
|
|
41
|
+
*/
|
|
42
|
+
export const getFocusedListItemIndex = listElement => {
|
|
43
|
+
const children = Array.from(listElement.children);
|
|
44
|
+
return children.indexOf(getActiveElement(document));
|
|
45
|
+
};
|
|
35
46
|
export const DEFAULT_DESKTOP_MODE_MEDIA_QUERY = '@media (pointer: fine)';
|
|
@@ -262,6 +262,8 @@ class AdapterDayjs {
|
|
|
262
262
|
const timezone = this.getTimezone(value);
|
|
263
263
|
if (timezone !== 'UTC') {
|
|
264
264
|
const fixedValue = value.tz(this.cleanTimezone(timezone), true);
|
|
265
|
+
// TODO: Simplify the case when we raise the `dayjs` peer dep to 1.11.12 (https://github.com/iamkun/dayjs/releases/tag/v1.11.12)
|
|
266
|
+
/* istanbul ignore next */
|
|
265
267
|
// @ts-ignore
|
|
266
268
|
if (fixedValue.$offset === (value.$offset ?? 0)) {
|
|
267
269
|
return value;
|
|
@@ -494,7 +494,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
494
494
|
/**
|
|
495
495
|
* Component displaying when passed `loading` true.
|
|
496
496
|
* @returns {React.ReactNode} The node to render when loading.
|
|
497
|
-
* @default () => <span
|
|
497
|
+
* @default () => <span>...</span>
|
|
498
498
|
*/
|
|
499
499
|
renderLoading: _propTypes.default.func,
|
|
500
500
|
/**
|
|
@@ -263,7 +263,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
|
|
|
263
263
|
/**
|
|
264
264
|
* Component displaying when passed `loading` true.
|
|
265
265
|
* @returns {React.ReactNode} The node to render when loading.
|
|
266
|
-
* @default () => <span
|
|
266
|
+
* @default () => <span>...</span>
|
|
267
267
|
*/
|
|
268
268
|
renderLoading: _propTypes.default.func,
|
|
269
269
|
/**
|
|
@@ -301,7 +301,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
301
301
|
/**
|
|
302
302
|
* Component displaying when passed `loading` true.
|
|
303
303
|
* @returns {React.ReactNode} The node to render when loading.
|
|
304
|
-
* @default () => <span
|
|
304
|
+
* @default () => <span>...</span>
|
|
305
305
|
*/
|
|
306
306
|
renderLoading: _propTypes.default.func,
|
|
307
307
|
/**
|
|
@@ -94,7 +94,7 @@ const DateTimePickerTabs = exports.DateTimePickerTabs = function DateTimePickerT
|
|
|
94
94
|
variant: "fullWidth",
|
|
95
95
|
value: viewToTab(view),
|
|
96
96
|
onChange: handleChange,
|
|
97
|
-
className: (0, _clsx.default)(classes.root
|
|
97
|
+
className: (0, _clsx.default)(className, classes.root),
|
|
98
98
|
sx: sx,
|
|
99
99
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tab.default, {
|
|
100
100
|
value: "date",
|
|
@@ -284,7 +284,7 @@ DesktopDatePicker.propTypes = {
|
|
|
284
284
|
/**
|
|
285
285
|
* Component displaying when passed `loading` true.
|
|
286
286
|
* @returns {React.ReactNode} The node to render when loading.
|
|
287
|
-
* @default () => <span
|
|
287
|
+
* @default () => <span>...</span>
|
|
288
288
|
*/
|
|
289
289
|
renderLoading: _propTypes.default.func,
|
|
290
290
|
/**
|
|
@@ -409,7 +409,7 @@ DesktopDateTimePicker.propTypes = {
|
|
|
409
409
|
/**
|
|
410
410
|
* Component displaying when passed `loading` true.
|
|
411
411
|
* @returns {React.ReactNode} The node to render when loading.
|
|
412
|
-
* @default () => <span
|
|
412
|
+
* @default () => <span>...</span>
|
|
413
413
|
*/
|
|
414
414
|
renderLoading: _propTypes.default.func,
|
|
415
415
|
/**
|
|
@@ -29,6 +29,7 @@ var _dimensions = require("../internals/constants/dimensions");
|
|
|
29
29
|
var _useValueWithTimezone = require("../internals/hooks/useValueWithTimezone");
|
|
30
30
|
var _valueManagers = require("../internals/utils/valueManagers");
|
|
31
31
|
var _useClockReferenceDate = require("../internals/hooks/useClockReferenceDate");
|
|
32
|
+
var _utils = require("../internals/utils/utils");
|
|
32
33
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
34
|
const _excluded = ["ampm", "timeStep", "autoFocus", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableTime", "onChange", "view", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "disabled", "readOnly", "views", "skipDisabled", "timezone"];
|
|
34
35
|
const useUtilityClasses = ownerState => {
|
|
@@ -111,6 +112,7 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
|
|
|
111
112
|
const utils = (0, _useUtils.useUtils)();
|
|
112
113
|
const containerRef = React.useRef(null);
|
|
113
114
|
const handleRef = (0, _useForkRef.default)(ref, containerRef);
|
|
115
|
+
const listRef = React.useRef(null);
|
|
114
116
|
const props = (0, _styles.useThemeProps)({
|
|
115
117
|
props: inProps,
|
|
116
118
|
name: 'MuiDigitalClock'
|
|
@@ -243,15 +245,46 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
|
|
|
243
245
|
}, (_, index) => utils.addMinutes(startOfDay, timeStep * (index + 1)))];
|
|
244
246
|
}, [valueOrReferenceDate, timeStep, utils]);
|
|
245
247
|
const focusedOptionIndex = timeOptions.findIndex(option => utils.isEqual(option, valueOrReferenceDate));
|
|
248
|
+
const handleKeyDown = event => {
|
|
249
|
+
switch (event.key) {
|
|
250
|
+
case 'PageUp':
|
|
251
|
+
{
|
|
252
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) - 5;
|
|
253
|
+
const children = listRef.current.children;
|
|
254
|
+
const newFocusedIndex = Math.max(0, newIndex);
|
|
255
|
+
const childToFocus = children[newFocusedIndex];
|
|
256
|
+
if (childToFocus) {
|
|
257
|
+
childToFocus.focus();
|
|
258
|
+
}
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case 'PageDown':
|
|
263
|
+
{
|
|
264
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) + 5;
|
|
265
|
+
const children = listRef.current.children;
|
|
266
|
+
const newFocusedIndex = Math.min(children.length - 1, newIndex);
|
|
267
|
+
const childToFocus = children[newFocusedIndex];
|
|
268
|
+
if (childToFocus) {
|
|
269
|
+
childToFocus.focus();
|
|
270
|
+
}
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
default:
|
|
275
|
+
}
|
|
276
|
+
};
|
|
246
277
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DigitalClockRoot, (0, _extends2.default)({
|
|
247
278
|
ref: handleRef,
|
|
248
279
|
className: (0, _clsx.default)(classes.root, className),
|
|
249
280
|
ownerState: ownerState
|
|
250
281
|
}, other, {
|
|
251
282
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DigitalClockList, {
|
|
283
|
+
ref: listRef,
|
|
252
284
|
role: "listbox",
|
|
253
285
|
"aria-label": translations.timePickerToolbarTitle,
|
|
254
286
|
className: classes.list,
|
|
287
|
+
onKeyDown: handleKeyDown,
|
|
255
288
|
children: timeOptions.map((option, index) => {
|
|
256
289
|
if (skipDisabled && isTimeDisabled(option)) {
|
|
257
290
|
return null;
|
|
@@ -281,7 +281,7 @@ MobileDatePicker.propTypes = {
|
|
|
281
281
|
/**
|
|
282
282
|
* Component displaying when passed `loading` true.
|
|
283
283
|
* @returns {React.ReactNode} The node to render when loading.
|
|
284
|
-
* @default () => <span
|
|
284
|
+
* @default () => <span>...</span>
|
|
285
285
|
*/
|
|
286
286
|
renderLoading: _propTypes.default.func,
|
|
287
287
|
/**
|
|
@@ -329,7 +329,7 @@ MobileDateTimePicker.propTypes = {
|
|
|
329
329
|
/**
|
|
330
330
|
* Component displaying when passed `loading` true.
|
|
331
331
|
* @returns {React.ReactNode} The node to render when loading.
|
|
332
|
-
* @default () => <span
|
|
332
|
+
* @default () => <span>...</span>
|
|
333
333
|
*/
|
|
334
334
|
renderLoading: _propTypes.default.func,
|
|
335
335
|
/**
|
|
@@ -17,6 +17,7 @@ var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
|
|
|
17
17
|
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
18
18
|
var _multiSectionDigitalClockSectionClasses = require("./multiSectionDigitalClockSectionClasses");
|
|
19
19
|
var _dimensions = require("../internals/constants/dimensions");
|
|
20
|
+
var _utils = require("../internals/utils/utils");
|
|
20
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
22
|
const _excluded = ["autoFocus", "onChange", "className", "disabled", "readOnly", "items", "active", "slots", "slotProps", "skipDisabled"];
|
|
22
23
|
const useUtilityClasses = ownerState => {
|
|
@@ -146,12 +147,42 @@ const MultiSectionDigitalClockSection = exports.MultiSectionDigitalClockSection
|
|
|
146
147
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
147
148
|
});
|
|
148
149
|
const focusedOptionIndex = items.findIndex(item => item.isFocused(item.value));
|
|
150
|
+
const handleKeyDown = event => {
|
|
151
|
+
switch (event.key) {
|
|
152
|
+
case 'PageUp':
|
|
153
|
+
{
|
|
154
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) - 5;
|
|
155
|
+
const children = containerRef.current.children;
|
|
156
|
+
const newFocusedIndex = Math.max(0, newIndex);
|
|
157
|
+
const childToFocus = children[newFocusedIndex];
|
|
158
|
+
if (childToFocus) {
|
|
159
|
+
childToFocus.focus();
|
|
160
|
+
}
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case 'PageDown':
|
|
165
|
+
{
|
|
166
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) + 5;
|
|
167
|
+
const children = containerRef.current.children;
|
|
168
|
+
const newFocusedIndex = Math.min(children.length - 1, newIndex);
|
|
169
|
+
const childToFocus = children[newFocusedIndex];
|
|
170
|
+
if (childToFocus) {
|
|
171
|
+
childToFocus.focus();
|
|
172
|
+
}
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
}
|
|
178
|
+
};
|
|
149
179
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MultiSectionDigitalClockSectionRoot, (0, _extends2.default)({
|
|
150
180
|
ref: handleRef,
|
|
151
181
|
className: (0, _clsx.default)(classes.root, className),
|
|
152
182
|
ownerState: ownerState,
|
|
153
183
|
autoFocusItem: autoFocus && active,
|
|
154
|
-
role: "listbox"
|
|
184
|
+
role: "listbox",
|
|
185
|
+
onKeyDown: handleKeyDown
|
|
155
186
|
}, other, {
|
|
156
187
|
children: items.map((option, index) => {
|
|
157
188
|
const isItemDisabled = option.isDisabled?.(option.value);
|
|
@@ -56,15 +56,6 @@ const useUtilityClasses = ownerState => {
|
|
|
56
56
|
};
|
|
57
57
|
return (0, _composeClasses.default)(slots, _pickersSectionListClasses.getPickersSectionListUtilityClass, classes);
|
|
58
58
|
};
|
|
59
|
-
/**
|
|
60
|
-
* Demos:
|
|
61
|
-
*
|
|
62
|
-
* - [Custom field](https://mui.com/x/react-date-pickers/custom-field/)
|
|
63
|
-
*
|
|
64
|
-
* API:
|
|
65
|
-
*
|
|
66
|
-
* - [PickersSectionList API](https://mui.com/x/api/date-pickers/pickers-section-list/)
|
|
67
|
-
*/
|
|
68
59
|
function PickersSection(props) {
|
|
69
60
|
const {
|
|
70
61
|
slots,
|
|
@@ -112,6 +103,36 @@ function PickersSection(props) {
|
|
|
112
103
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SectionSeparator, (0, _extends2.default)({}, sectionSeparatorBeforeProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionContent, (0, _extends2.default)({}, sectionContentProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionSeparator, (0, _extends2.default)({}, sectionSeparatorAfterProps))]
|
|
113
104
|
}));
|
|
114
105
|
}
|
|
106
|
+
process.env.NODE_ENV !== "production" ? PickersSection.propTypes = {
|
|
107
|
+
// ----------------------------- Warning --------------------------------
|
|
108
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
109
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
110
|
+
// ----------------------------------------------------------------------
|
|
111
|
+
classes: _propTypes.default.object.isRequired,
|
|
112
|
+
element: _propTypes.default.shape({
|
|
113
|
+
after: _propTypes.default.object.isRequired,
|
|
114
|
+
before: _propTypes.default.object.isRequired,
|
|
115
|
+
container: _propTypes.default.object.isRequired,
|
|
116
|
+
content: _propTypes.default.object.isRequired
|
|
117
|
+
}).isRequired,
|
|
118
|
+
/**
|
|
119
|
+
* The props used for each component slot.
|
|
120
|
+
*/
|
|
121
|
+
slotProps: _propTypes.default.object,
|
|
122
|
+
/**
|
|
123
|
+
* Overridable component slots.
|
|
124
|
+
*/
|
|
125
|
+
slots: _propTypes.default.object
|
|
126
|
+
} : void 0;
|
|
127
|
+
/**
|
|
128
|
+
* Demos:
|
|
129
|
+
*
|
|
130
|
+
* - [Custom field](https://mui.com/x/react-date-pickers/custom-field/)
|
|
131
|
+
*
|
|
132
|
+
* API:
|
|
133
|
+
*
|
|
134
|
+
* - [PickersSectionList API](https://mui.com/x/api/date-pickers/pickers-section-list/)
|
|
135
|
+
*/
|
|
115
136
|
const PickersSectionList = exports.PickersSectionList = /*#__PURE__*/React.forwardRef(function PickersSectionList(inProps, ref) {
|
|
116
137
|
const props = (0, _styles.useThemeProps)({
|
|
117
138
|
props: inProps,
|
|
@@ -215,7 +215,7 @@ StaticDatePicker.propTypes = {
|
|
|
215
215
|
/**
|
|
216
216
|
* Component displaying when passed `loading` true.
|
|
217
217
|
* @returns {React.ReactNode} The node to render when loading.
|
|
218
|
-
* @default () => <span
|
|
218
|
+
* @default () => <span>...</span>
|
|
219
219
|
*/
|
|
220
220
|
renderLoading: _propTypes.default.func,
|
|
221
221
|
/**
|
|
@@ -263,7 +263,7 @@ StaticDateTimePicker.propTypes = {
|
|
|
263
263
|
/**
|
|
264
264
|
* Component displaying when passed `loading` true.
|
|
265
265
|
* @returns {React.ReactNode} The node to render when loading.
|
|
266
|
-
* @default () => <span
|
|
266
|
+
* @default () => <span>...</span>
|
|
267
267
|
*/
|
|
268
268
|
renderLoading: _propTypes.default.func,
|
|
269
269
|
/**
|
package/node/TimeClock/Clock.js
CHANGED
|
@@ -282,6 +282,14 @@ function Clock(inProps) {
|
|
|
282
282
|
handleValueChange(viewValue - keyboardControlStep, 'partial');
|
|
283
283
|
event.preventDefault();
|
|
284
284
|
break;
|
|
285
|
+
case 'PageUp':
|
|
286
|
+
handleValueChange(viewValue + 5, 'partial');
|
|
287
|
+
event.preventDefault();
|
|
288
|
+
break;
|
|
289
|
+
case 'PageDown':
|
|
290
|
+
handleValueChange(viewValue - 5, 'partial');
|
|
291
|
+
event.preventDefault();
|
|
292
|
+
break;
|
|
285
293
|
case 'Enter':
|
|
286
294
|
case ' ':
|
|
287
295
|
handleValueChange(viewValue, 'finish');
|
package/node/hooks/index.js
CHANGED
|
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "useClearableField", {
|
|
|
9
9
|
return _useClearableField.useClearableField;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "useParsedFormat", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useParsedFormat.useParsedFormat;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "usePickersContext", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _usePickersContext.usePickersContext;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
Object.defineProperty(exports, "usePickersTranslations", {
|
|
13
25
|
enumerable: true,
|
|
14
26
|
get: function () {
|
|
@@ -23,4 +35,6 @@ Object.defineProperty(exports, "useSplitFieldProps", {
|
|
|
23
35
|
});
|
|
24
36
|
var _useClearableField = require("./useClearableField");
|
|
25
37
|
var _usePickersTranslations = require("./usePickersTranslations");
|
|
26
|
-
var _useSplitFieldProps = require("./useSplitFieldProps");
|
|
38
|
+
var _useSplitFieldProps = require("./useSplitFieldProps");
|
|
39
|
+
var _useParsedFormat = require("./useParsedFormat");
|
|
40
|
+
var _usePickersContext = require("./usePickersContext");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useParsedFormat = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _RtlProvider = require("@mui/system/RtlProvider");
|
|
11
|
+
var _useUtils = require("../internals/hooks/useUtils");
|
|
12
|
+
var _buildSectionsFromFormat = require("../internals/hooks/useField/buildSectionsFromFormat");
|
|
13
|
+
var _useField = require("../internals/hooks/useField/useField.utils");
|
|
14
|
+
var _usePickersTranslations = require("./usePickersTranslations");
|
|
15
|
+
/**
|
|
16
|
+
* Returns the parsed format to be rendered in the field when there is no value or in other parts of the Picker.
|
|
17
|
+
* This format is localized (e.g: `AAAA` for the year with the French locale) and cannot be parsed by your date library.
|
|
18
|
+
* @param {object} The parameters needed to build the placeholder.
|
|
19
|
+
* @param {string} params.format Format of the date to use.
|
|
20
|
+
* @param {'dense' | 'spacious'} params.formatDensity Density of the format (setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character).
|
|
21
|
+
* @param {boolean} params.shouldRespectLeadingZeros If `true`, the format will respect the leading zeroes, if `false`, the format will always add leading zeroes.
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
const useParsedFormat = parameters => {
|
|
25
|
+
const {
|
|
26
|
+
format,
|
|
27
|
+
formatDensity = 'dense',
|
|
28
|
+
shouldRespectLeadingZeros = false
|
|
29
|
+
} = parameters;
|
|
30
|
+
const utils = (0, _useUtils.useUtils)();
|
|
31
|
+
const isRtl = (0, _RtlProvider.useRtl)();
|
|
32
|
+
const translations = (0, _usePickersTranslations.usePickersTranslations)();
|
|
33
|
+
const localizedDigits = React.useMemo(() => (0, _useField.getLocalizedDigits)(utils), [utils]);
|
|
34
|
+
return React.useMemo(() => {
|
|
35
|
+
const sections = (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
|
|
36
|
+
utils,
|
|
37
|
+
format,
|
|
38
|
+
formatDensity,
|
|
39
|
+
isRtl,
|
|
40
|
+
shouldRespectLeadingZeros,
|
|
41
|
+
localeText: translations,
|
|
42
|
+
localizedDigits,
|
|
43
|
+
date: null,
|
|
44
|
+
// TODO v9: Make sure we still don't reverse in `buildSectionsFromFormat` when using `useParsedFormat`.
|
|
45
|
+
enableAccessibleFieldDOMStructure: false
|
|
46
|
+
});
|
|
47
|
+
return sections.map(section => `${section.startSeparator}${section.placeholder}${section.endSeparator}`).join('');
|
|
48
|
+
}, [utils, isRtl, translations, localizedDigits, format, formatDensity, shouldRespectLeadingZeros]);
|
|
49
|
+
};
|
|
50
|
+
exports.useParsedFormat = useParsedFormat;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.usePickersContext = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _PickersProvider = require("../internals/components/PickersProvider");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the context passed by the picker that wraps the current component.
|
|
13
|
+
*/
|
|
14
|
+
const usePickersContext = () => {
|
|
15
|
+
const value = React.useContext(_PickersProvider.PickersContext);
|
|
16
|
+
if (value == null) {
|
|
17
|
+
throw new Error(['MUI X: The `usePickersContext` can only be called in fields that are used as a slot of a picker component'].join('\n'));
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
exports.usePickersContext = usePickersContext;
|
package/node/index.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PickersContext = void 0;
|
|
8
|
+
exports.PickersProvider = PickersProvider;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _LocalizationProvider = require("../../LocalizationProvider");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
const PickersContext = exports.PickersContext = /*#__PURE__*/React.createContext(null);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Provides the context for the various parts of a picker component:
|
|
16
|
+
* - contextValue: the context for the picker sub-components.
|
|
17
|
+
* - localizationProvider: the translations passed through the props and through a parent LocalizationProvider.
|
|
18
|
+
*
|
|
19
|
+
* @ignore - do not document.
|
|
20
|
+
*/
|
|
21
|
+
function PickersProvider(props) {
|
|
22
|
+
const {
|
|
23
|
+
contextValue,
|
|
24
|
+
localeText,
|
|
25
|
+
children
|
|
26
|
+
} = props;
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersContext.Provider, {
|
|
28
|
+
value: contextValue,
|
|
29
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LocalizationProvider.LocalizationProvider, {
|
|
30
|
+
localeText: localeText,
|
|
31
|
+
children: children
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -16,8 +16,8 @@ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
|
16
16
|
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
17
17
|
var _PickersPopper = require("../../components/PickersPopper");
|
|
18
18
|
var _usePicker = require("../usePicker");
|
|
19
|
-
var _LocalizationProvider = require("../../../LocalizationProvider");
|
|
20
19
|
var _PickersLayout = require("../../../PickersLayout");
|
|
20
|
+
var _PickersProvider = require("../../components/PickersProvider");
|
|
21
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _excluded = ["props", "getOpenDialogAriaText"],
|
|
23
23
|
_excluded2 = ["ownerState"],
|
|
@@ -65,7 +65,9 @@ const useDesktopPicker = _ref => {
|
|
|
65
65
|
layoutProps,
|
|
66
66
|
renderCurrentView,
|
|
67
67
|
shouldRestoreFocus,
|
|
68
|
-
fieldProps: pickerFieldProps
|
|
68
|
+
fieldProps: pickerFieldProps,
|
|
69
|
+
contextValue,
|
|
70
|
+
ownerState
|
|
69
71
|
} = (0, _usePicker.usePicker)((0, _extends2.default)({}, pickerParams, {
|
|
70
72
|
props,
|
|
71
73
|
fieldRef,
|
|
@@ -73,11 +75,6 @@ const useDesktopPicker = _ref => {
|
|
|
73
75
|
additionalViewProps: {},
|
|
74
76
|
wrapperVariant: 'desktop'
|
|
75
77
|
}));
|
|
76
|
-
|
|
77
|
-
// TODO v8: Apply this ownerState to all the slots in this hook.
|
|
78
|
-
const ownerStateV8 = {
|
|
79
|
-
open
|
|
80
|
-
};
|
|
81
78
|
const InputAdornment = slots.inputAdornment ?? _InputAdornment.default;
|
|
82
79
|
const _useSlotProps = (0, _useSlotProps3.default)({
|
|
83
80
|
elementType: InputAdornment,
|
|
@@ -105,7 +102,7 @@ const useDesktopPicker = _ref => {
|
|
|
105
102
|
const openPickerIconProps = (0, _useSlotProps3.default)({
|
|
106
103
|
elementType: OpenPickerIcon,
|
|
107
104
|
externalSlotProps: innerSlotProps?.openPickerIcon,
|
|
108
|
-
ownerState
|
|
105
|
+
ownerState
|
|
109
106
|
});
|
|
110
107
|
const Field = slots.field;
|
|
111
108
|
const fieldProps = (0, _useSlotProps3.default)({
|
|
@@ -169,7 +166,8 @@ const useDesktopPicker = _ref => {
|
|
|
169
166
|
}, innerSlotProps?.popper)
|
|
170
167
|
});
|
|
171
168
|
const handleFieldRef = (0, _useForkRef.default)(fieldRef, fieldProps.unstableFieldRef);
|
|
172
|
-
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
|
169
|
+
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_PickersProvider.PickersProvider, {
|
|
170
|
+
contextValue: contextValue,
|
|
173
171
|
localeText: localeText,
|
|
174
172
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, fieldProps, {
|
|
175
173
|
slots: slotsForField,
|
|
@@ -45,12 +45,12 @@ const getEscapedPartsFromFormat = ({
|
|
|
45
45
|
}
|
|
46
46
|
return escapedParts;
|
|
47
47
|
};
|
|
48
|
-
const getSectionPlaceholder = (utils,
|
|
48
|
+
const getSectionPlaceholder = (utils, localeText, sectionConfig, sectionFormat) => {
|
|
49
49
|
switch (sectionConfig.type) {
|
|
50
50
|
case 'year':
|
|
51
51
|
{
|
|
52
52
|
return localeText.fieldYearPlaceholder({
|
|
53
|
-
digitAmount: utils.formatByString(utils.date(undefined,
|
|
53
|
+
digitAmount: utils.formatByString(utils.date(undefined, 'default'), sectionFormat).length,
|
|
54
54
|
format: sectionFormat
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -106,7 +106,6 @@ const getSectionPlaceholder = (utils, timezone, localeText, sectionConfig, secti
|
|
|
106
106
|
};
|
|
107
107
|
const createSection = ({
|
|
108
108
|
utils,
|
|
109
|
-
timezone,
|
|
110
109
|
date,
|
|
111
110
|
shouldRespectLeadingZeros,
|
|
112
111
|
localeText,
|
|
@@ -119,7 +118,7 @@ const createSection = ({
|
|
|
119
118
|
throw new Error('MUI X: Should not call `commitToken` with an empty token');
|
|
120
119
|
}
|
|
121
120
|
const sectionConfig = (0, _useField.getDateSectionConfigFromFormatToken)(utils, token);
|
|
122
|
-
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils,
|
|
121
|
+
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils, sectionConfig.contentType, sectionConfig.type, token);
|
|
123
122
|
const hasLeadingZerosInInput = shouldRespectLeadingZeros ? hasLeadingZerosInFormat : sectionConfig.contentType === 'digit';
|
|
124
123
|
const isValidDate = date != null && utils.isValid(date);
|
|
125
124
|
let sectionValue = isValidDate ? utils.formatByString(date, token) : '';
|
|
@@ -141,7 +140,7 @@ const createSection = ({
|
|
|
141
140
|
format: token,
|
|
142
141
|
maxLength,
|
|
143
142
|
value: sectionValue,
|
|
144
|
-
placeholder: getSectionPlaceholder(utils,
|
|
143
|
+
placeholder: getSectionPlaceholder(utils, localeText, sectionConfig, token),
|
|
145
144
|
hasLeadingZerosInFormat,
|
|
146
145
|
hasLeadingZerosInInput,
|
|
147
146
|
startSeparator,
|
|
@@ -83,7 +83,7 @@ const useField = params => {
|
|
|
83
83
|
// eslint-disable-next-line default-case
|
|
84
84
|
switch (true) {
|
|
85
85
|
// Select all
|
|
86
|
-
case (event.ctrlKey || event.metaKey) && event.
|
|
86
|
+
case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
|
|
87
87
|
{
|
|
88
88
|
// prevent default to make sure that the next line "select all" while updating
|
|
89
89
|
// the internal state at the same time.
|
|
@@ -38,9 +38,9 @@ const getDeltaFromKeyCode = keyCode => {
|
|
|
38
38
|
return 0;
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
const getDaysInWeekStr = (utils,
|
|
41
|
+
const getDaysInWeekStr = (utils, format) => {
|
|
42
42
|
const elements = [];
|
|
43
|
-
const now = utils.date(undefined,
|
|
43
|
+
const now = utils.date(undefined, 'default');
|
|
44
44
|
const startDate = utils.startOfWeek(now);
|
|
45
45
|
const endDate = utils.endOfWeek(now);
|
|
46
46
|
let current = startDate;
|
|
@@ -59,7 +59,7 @@ const getLetterEditingOptions = (utils, timezone, sectionType, format) => {
|
|
|
59
59
|
}
|
|
60
60
|
case 'weekDay':
|
|
61
61
|
{
|
|
62
|
-
return getDaysInWeekStr(utils,
|
|
62
|
+
return getDaysInWeekStr(utils, format);
|
|
63
63
|
}
|
|
64
64
|
case 'meridiem':
|
|
65
65
|
{
|
|
@@ -252,17 +252,17 @@ const changeSectionValueFormat = (utils, valueStr, currentFormat, newFormat) =>
|
|
|
252
252
|
return utils.formatByString(utils.parse(valueStr, currentFormat), newFormat);
|
|
253
253
|
};
|
|
254
254
|
exports.changeSectionValueFormat = changeSectionValueFormat;
|
|
255
|
-
const isFourDigitYearFormat = (utils,
|
|
256
|
-
const doesSectionFormatHaveLeadingZeros = (utils,
|
|
255
|
+
const isFourDigitYearFormat = (utils, format) => utils.formatByString(utils.date(undefined, 'system'), format).length === 4;
|
|
256
|
+
const doesSectionFormatHaveLeadingZeros = (utils, contentType, sectionType, format) => {
|
|
257
257
|
if (contentType !== 'digit') {
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
|
-
const now = utils.date(undefined,
|
|
260
|
+
const now = utils.date(undefined, 'default');
|
|
261
261
|
switch (sectionType) {
|
|
262
262
|
// We can't use `changeSectionValueFormat`, because `utils.parse('1', 'YYYY')` returns `1971` instead of `1`.
|
|
263
263
|
case 'year':
|
|
264
264
|
{
|
|
265
|
-
if (isFourDigitYearFormat(utils,
|
|
265
|
+
if (isFourDigitYearFormat(utils, format)) {
|
|
266
266
|
const formatted0001 = utils.formatByString(utils.setYear(now, 1), format);
|
|
267
267
|
return formatted0001 === '0001';
|
|
268
268
|
}
|
|
@@ -372,7 +372,7 @@ const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
372
372
|
format
|
|
373
373
|
}) => ({
|
|
374
374
|
minimum: 0,
|
|
375
|
-
maximum: isFourDigitYearFormat(utils,
|
|
375
|
+
maximum: isFourDigitYearFormat(utils, format) ? 9999 : 99
|
|
376
376
|
}),
|
|
377
377
|
month: () => ({
|
|
378
378
|
minimum: 1,
|
|
@@ -391,7 +391,7 @@ const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
391
391
|
contentType
|
|
392
392
|
}) => {
|
|
393
393
|
if (contentType === 'digit') {
|
|
394
|
-
const daysInWeek = getDaysInWeekStr(utils,
|
|
394
|
+
const daysInWeek = getDaysInWeekStr(utils, format).map(Number);
|
|
395
395
|
return {
|
|
396
396
|
minimum: Math.min(...daysInWeek),
|
|
397
397
|
maximum: Math.max(...daysInWeek)
|
|
@@ -459,7 +459,7 @@ const validateSections = (sections, valueType) => {
|
|
|
459
459
|
}
|
|
460
460
|
};
|
|
461
461
|
exports.validateSections = validateSections;
|
|
462
|
-
const transferDateSectionValue = (utils,
|
|
462
|
+
const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTransferTo) => {
|
|
463
463
|
switch (section.type) {
|
|
464
464
|
case 'year':
|
|
465
465
|
{
|
|
@@ -471,7 +471,7 @@ const transferDateSectionValue = (utils, timezone, section, dateToTransferFrom,
|
|
|
471
471
|
}
|
|
472
472
|
case 'weekDay':
|
|
473
473
|
{
|
|
474
|
-
const formattedDaysInWeek = getDaysInWeekStr(utils,
|
|
474
|
+
const formattedDaysInWeek = getDaysInWeekStr(utils, section.format);
|
|
475
475
|
const dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
|
|
476
476
|
const dayInWeekOfActiveDate = formattedDaysInWeek.indexOf(dayInWeekStrOfActiveDate);
|
|
477
477
|
const dayInWeekOfNewSectionValue = formattedDaysInWeek.indexOf(section.value);
|
|
@@ -523,11 +523,11 @@ const reliableSectionModificationOrder = {
|
|
|
523
523
|
meridiem: 8,
|
|
524
524
|
empty: 9
|
|
525
525
|
};
|
|
526
|
-
const mergeDateIntoReferenceDate = (utils,
|
|
526
|
+
const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) =>
|
|
527
527
|
// cloning sections before sort to avoid mutating it
|
|
528
528
|
[...sections].sort((a, b) => reliableSectionModificationOrder[a.type] - reliableSectionModificationOrder[b.type]).reduce((mergedDate, section) => {
|
|
529
529
|
if (!shouldLimitToEditedSections || section.modified) {
|
|
530
|
-
return transferDateSectionValue(utils,
|
|
530
|
+
return transferDateSectionValue(utils, section, dateToTransferFrom, mergedDate);
|
|
531
531
|
}
|
|
532
532
|
return mergedDate;
|
|
533
533
|
}, referenceDate);
|