@mui/x-date-pickers 6.9.0 → 6.9.2
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 +136 -8
- package/DateField/DateField.js +3 -1
- package/DateTimeField/DateTimeField.js +3 -1
- package/DigitalClock/DigitalClock.js +28 -8
- package/MonthCalendar/MonthCalendar.js +1 -1
- package/MonthCalendar/MonthCalendar.types.d.ts +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +31 -18
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +7 -1
- package/README.md +2 -2
- package/TimeClock/TimeClock.js +35 -20
- package/TimeField/TimeField.js +3 -1
- package/YearCalendar/YearCalendar.js +1 -1
- package/YearCalendar/YearCalendar.types.d.ts +1 -1
- package/index.js +1 -1
- package/internals/hooks/useClockReferenceDate.d.ts +8 -0
- package/internals/hooks/useClockReferenceDate.js +26 -0
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +2 -0
- package/internals/models/props/clock.d.ts +6 -1
- package/internals/utils/getDefaultReferenceDate.d.ts +5 -2
- package/internals/utils/getDefaultReferenceDate.js +7 -2
- package/legacy/DateField/DateField.js +3 -1
- package/legacy/DateTimeField/DateTimeField.js +3 -1
- package/legacy/DigitalClock/DigitalClock.js +28 -10
- package/legacy/MonthCalendar/MonthCalendar.js +1 -1
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +31 -20
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +7 -1
- package/legacy/TimeClock/TimeClock.js +35 -22
- package/legacy/TimeField/TimeField.js +3 -1
- package/legacy/YearCalendar/YearCalendar.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useClockReferenceDate.js +29 -0
- package/legacy/internals/utils/getDefaultReferenceDate.js +9 -2
- package/legacy/locales/index.js +1 -0
- package/legacy/locales/roRO.js +22 -10
- package/legacy/locales/zhHK.js +93 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/locales/roRO.js +8 -10
- package/locales/zhHK.d.ts +53 -0
- package/locales/zhHK.js +57 -0
- package/modern/DateField/DateField.js +3 -1
- package/modern/DateTimeField/DateTimeField.js +3 -1
- package/modern/DigitalClock/DigitalClock.js +28 -8
- package/modern/MonthCalendar/MonthCalendar.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +31 -18
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +7 -1
- package/modern/TimeClock/TimeClock.js +35 -20
- package/modern/TimeField/TimeField.js +3 -1
- package/modern/YearCalendar/YearCalendar.js +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useClockReferenceDate.js +26 -0
- package/modern/internals/utils/getDefaultReferenceDate.js +4 -2
- package/modern/locales/index.js +1 -0
- package/modern/locales/roRO.js +8 -10
- package/modern/locales/zhHK.js +57 -0
- package/node/DateField/DateField.js +3 -1
- package/node/DateTimeField/DateTimeField.js +3 -1
- package/node/DigitalClock/DigitalClock.js +28 -8
- package/node/MonthCalendar/MonthCalendar.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +31 -18
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +7 -1
- package/node/TimeClock/TimeClock.js +35 -20
- package/node/TimeField/TimeField.js +3 -1
- package/node/YearCalendar/YearCalendar.js +1 -1
- package/node/index.js +1 -1
- package/node/internals/hooks/useClockReferenceDate.js +35 -0
- package/node/internals/utils/getDefaultReferenceDate.js +6 -3
- package/node/locales/index.js +11 -0
- package/node/locales/roRO.js +8 -10
- package/node/locales/zhHK.js +64 -0
- package/package.json +2 -2
package/TimeClock/TimeClock.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["ampm", "ampmInClock", "autoFocus", "components", "componentsProps", "slots", "slotProps", "value", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableClock", "shouldDisableTime", "showViewSwitcher", "onChange", "
|
|
3
|
+
const _excluded = ["ampm", "ampmInClock", "autoFocus", "components", "componentsProps", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableClock", "shouldDisableTime", "showViewSwitcher", "onChange", "view", "views", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "disabled", "readOnly", "timezone"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -18,6 +18,7 @@ import { getHourNumbers, getMinutesNumbers } from './ClockNumbers';
|
|
|
18
18
|
import { useControlledValueWithTimezone } from '../internals/hooks/useValueWithTimezone';
|
|
19
19
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
20
20
|
import { uncapitalizeObjectKeys } from '../internals/utils/slots-migration';
|
|
21
|
+
import { useClockReferenceDate } from '../internals/hooks/useClockReferenceDate';
|
|
21
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
23
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
24
|
const useUtilityClasses = ownerState => {
|
|
@@ -48,6 +49,8 @@ const TimeClockArrowSwitcher = styled(PickersArrowSwitcher, {
|
|
|
48
49
|
right: 12,
|
|
49
50
|
top: 15
|
|
50
51
|
});
|
|
52
|
+
const TIME_CLOCK_DEFAULT_VIEWS = ['hours', 'minutes'];
|
|
53
|
+
|
|
51
54
|
/**
|
|
52
55
|
*
|
|
53
56
|
* API:
|
|
@@ -69,6 +72,8 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
69
72
|
slots: innerSlots,
|
|
70
73
|
slotProps: innerSlotProps,
|
|
71
74
|
value: valueProp,
|
|
75
|
+
defaultValue,
|
|
76
|
+
referenceDate: referenceDateProp,
|
|
72
77
|
disableIgnoringDatePartForTimeValidation = false,
|
|
73
78
|
maxTime,
|
|
74
79
|
minTime,
|
|
@@ -79,9 +84,8 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
79
84
|
shouldDisableTime,
|
|
80
85
|
showViewSwitcher,
|
|
81
86
|
onChange,
|
|
82
|
-
defaultValue,
|
|
83
87
|
view: inView,
|
|
84
|
-
views =
|
|
88
|
+
views = TIME_CLOCK_DEFAULT_VIEWS,
|
|
85
89
|
openTo,
|
|
86
90
|
onViewChange,
|
|
87
91
|
focusedView,
|
|
@@ -106,6 +110,13 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
106
110
|
onChange,
|
|
107
111
|
valueManager: singleItemValueManager
|
|
108
112
|
});
|
|
113
|
+
const valueOrReferenceDate = useClockReferenceDate({
|
|
114
|
+
value,
|
|
115
|
+
referenceDate: referenceDateProp,
|
|
116
|
+
utils,
|
|
117
|
+
props,
|
|
118
|
+
timezone
|
|
119
|
+
});
|
|
109
120
|
const localeText = useLocaleText();
|
|
110
121
|
const now = useNow(timezone);
|
|
111
122
|
const {
|
|
@@ -123,11 +134,10 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
123
134
|
focusedView,
|
|
124
135
|
onFocusedViewChange
|
|
125
136
|
});
|
|
126
|
-
const selectedTimeOrMidnight = React.useMemo(() => value || utils.setSeconds(utils.setMinutes(utils.setHours(now, 0), 0), 0), [value, now, utils]);
|
|
127
137
|
const {
|
|
128
138
|
meridiemMode,
|
|
129
139
|
handleMeridiemChange
|
|
130
|
-
} = useMeridiemMode(
|
|
140
|
+
} = useMeridiemMode(valueOrReferenceDate, ampm, setValueAndGoToNextView);
|
|
131
141
|
const isTimeDisabled = React.useCallback((rawValue, viewType) => {
|
|
132
142
|
const isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation, utils);
|
|
133
143
|
const shouldCheckPastEnd = viewType === 'hours' || viewType === 'minutes' && views.includes('seconds');
|
|
@@ -159,11 +169,11 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
159
169
|
if (shouldDisableTime) {
|
|
160
170
|
switch (viewType) {
|
|
161
171
|
case 'hours':
|
|
162
|
-
return !shouldDisableTime(utils.setHours(
|
|
172
|
+
return !shouldDisableTime(utils.setHours(valueOrReferenceDate, timeValue), 'hours');
|
|
163
173
|
case 'minutes':
|
|
164
|
-
return !shouldDisableTime(utils.setMinutes(
|
|
174
|
+
return !shouldDisableTime(utils.setMinutes(valueOrReferenceDate, timeValue), 'minutes');
|
|
165
175
|
case 'seconds':
|
|
166
|
-
return !shouldDisableTime(utils.setSeconds(
|
|
176
|
+
return !shouldDisableTime(utils.setSeconds(valueOrReferenceDate, timeValue), 'seconds');
|
|
167
177
|
default:
|
|
168
178
|
return false;
|
|
169
179
|
}
|
|
@@ -174,7 +184,7 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
174
184
|
case 'hours':
|
|
175
185
|
{
|
|
176
186
|
const valueWithMeridiem = convertValueToMeridiem(rawValue, meridiemMode, ampm);
|
|
177
|
-
const dateWithNewHours = utils.setHours(
|
|
187
|
+
const dateWithNewHours = utils.setHours(valueOrReferenceDate, valueWithMeridiem);
|
|
178
188
|
const start = utils.setSeconds(utils.setMinutes(dateWithNewHours, 0), 0);
|
|
179
189
|
const end = utils.setSeconds(utils.setMinutes(dateWithNewHours, 59), 59);
|
|
180
190
|
return !containsValidTime({
|
|
@@ -184,7 +194,7 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
184
194
|
}
|
|
185
195
|
case 'minutes':
|
|
186
196
|
{
|
|
187
|
-
const dateWithNewMinutes = utils.setMinutes(
|
|
197
|
+
const dateWithNewMinutes = utils.setMinutes(valueOrReferenceDate, rawValue);
|
|
188
198
|
const start = utils.setSeconds(dateWithNewMinutes, 0);
|
|
189
199
|
const end = utils.setSeconds(dateWithNewMinutes, 59);
|
|
190
200
|
return !containsValidTime({
|
|
@@ -194,7 +204,7 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
194
204
|
}
|
|
195
205
|
case 'seconds':
|
|
196
206
|
{
|
|
197
|
-
const dateWithNewSeconds = utils.setSeconds(
|
|
207
|
+
const dateWithNewSeconds = utils.setSeconds(valueOrReferenceDate, rawValue);
|
|
198
208
|
const start = dateWithNewSeconds;
|
|
199
209
|
const end = dateWithNewSeconds;
|
|
200
210
|
return !containsValidTime({
|
|
@@ -205,7 +215,7 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
205
215
|
default:
|
|
206
216
|
throw new Error('not supported');
|
|
207
217
|
}
|
|
208
|
-
}, [ampm,
|
|
218
|
+
}, [ampm, valueOrReferenceDate, disableIgnoringDatePartForTimeValidation, maxTime, meridiemMode, minTime, minutesStep, shouldDisableClock, shouldDisableTime, utils, disableFuture, disablePast, now, views]);
|
|
209
219
|
const selectedId = useId();
|
|
210
220
|
const viewProps = React.useMemo(() => {
|
|
211
221
|
switch (view) {
|
|
@@ -213,11 +223,11 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
213
223
|
{
|
|
214
224
|
const handleHoursChange = (hourValue, isFinish) => {
|
|
215
225
|
const valueWithMeridiem = convertValueToMeridiem(hourValue, meridiemMode, ampm);
|
|
216
|
-
setValueAndGoToNextView(utils.setHours(
|
|
226
|
+
setValueAndGoToNextView(utils.setHours(valueOrReferenceDate, valueWithMeridiem), isFinish);
|
|
217
227
|
};
|
|
218
228
|
return {
|
|
219
229
|
onChange: handleHoursChange,
|
|
220
|
-
viewValue: utils.getHours(
|
|
230
|
+
viewValue: utils.getHours(valueOrReferenceDate),
|
|
221
231
|
children: getHourNumbers({
|
|
222
232
|
value,
|
|
223
233
|
utils,
|
|
@@ -231,9 +241,9 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
231
241
|
}
|
|
232
242
|
case 'minutes':
|
|
233
243
|
{
|
|
234
|
-
const minutesValue = utils.getMinutes(
|
|
244
|
+
const minutesValue = utils.getMinutes(valueOrReferenceDate);
|
|
235
245
|
const handleMinutesChange = (minuteValue, isFinish) => {
|
|
236
|
-
setValueAndGoToNextView(utils.setMinutes(
|
|
246
|
+
setValueAndGoToNextView(utils.setMinutes(valueOrReferenceDate, minuteValue), isFinish);
|
|
237
247
|
};
|
|
238
248
|
return {
|
|
239
249
|
viewValue: minutesValue,
|
|
@@ -250,9 +260,9 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
250
260
|
}
|
|
251
261
|
case 'seconds':
|
|
252
262
|
{
|
|
253
|
-
const secondsValue = utils.getSeconds(
|
|
263
|
+
const secondsValue = utils.getSeconds(valueOrReferenceDate);
|
|
254
264
|
const handleSecondsChange = (secondValue, isFinish) => {
|
|
255
|
-
setValueAndGoToNextView(utils.setSeconds(
|
|
265
|
+
setValueAndGoToNextView(utils.setSeconds(valueOrReferenceDate, secondValue), isFinish);
|
|
256
266
|
};
|
|
257
267
|
return {
|
|
258
268
|
viewValue: secondsValue,
|
|
@@ -270,7 +280,7 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
270
280
|
default:
|
|
271
281
|
throw new Error('You must provide the type for ClockView');
|
|
272
282
|
}
|
|
273
|
-
}, [view, utils, value, ampm, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode, setValueAndGoToNextView,
|
|
283
|
+
}, [view, utils, value, ampm, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode, setValueAndGoToNextView, valueOrReferenceDate, isTimeDisabled, selectedId, disabled]);
|
|
274
284
|
const ownerState = props;
|
|
275
285
|
const classes = useUtilityClasses(ownerState);
|
|
276
286
|
return /*#__PURE__*/_jsxs(TimeClockRoot, _extends({
|
|
@@ -390,7 +400,7 @@ process.env.NODE_ENV !== "production" ? TimeClock.propTypes = {
|
|
|
390
400
|
minutesStep: PropTypes.number,
|
|
391
401
|
/**
|
|
392
402
|
* Callback fired when the value changes.
|
|
393
|
-
* @template TDate
|
|
403
|
+
* @template TDate, TView
|
|
394
404
|
* @param {TDate | null} value The new value.
|
|
395
405
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
396
406
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
@@ -420,6 +430,11 @@ process.env.NODE_ENV !== "production" ? TimeClock.propTypes = {
|
|
|
420
430
|
* @default false
|
|
421
431
|
*/
|
|
422
432
|
readOnly: PropTypes.bool,
|
|
433
|
+
/**
|
|
434
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
435
|
+
* @default The closest valid time using the validation props, except callbacks such as `shouldDisableTime`.
|
|
436
|
+
*/
|
|
437
|
+
referenceDate: PropTypes.any,
|
|
423
438
|
/**
|
|
424
439
|
* Disable specific clock time.
|
|
425
440
|
* @param {number} clockValue The value to check.
|
package/TimeField/TimeField.js
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["slots", "slotProps", "components", "componentsProps", "InputProps", "inputProps"],
|
|
4
4
|
_excluded2 = ["inputRef"],
|
|
5
|
-
_excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
|
|
5
|
+
_excluded3 = ["ref", "onPaste", "onKeyDown", "inputMode", "readOnly"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
@@ -48,6 +48,7 @@ const TimeField = /*#__PURE__*/React.forwardRef(function TimeField(inProps, ref)
|
|
|
48
48
|
{
|
|
49
49
|
ref: inputRef,
|
|
50
50
|
onPaste,
|
|
51
|
+
onKeyDown,
|
|
51
52
|
inputMode,
|
|
52
53
|
readOnly
|
|
53
54
|
} = _useTimeField,
|
|
@@ -61,6 +62,7 @@ const TimeField = /*#__PURE__*/React.forwardRef(function TimeField(inProps, ref)
|
|
|
61
62
|
inputProps: _extends({}, fieldProps.inputProps, {
|
|
62
63
|
inputMode,
|
|
63
64
|
onPaste,
|
|
65
|
+
onKeyDown,
|
|
64
66
|
ref: inputRef
|
|
65
67
|
})
|
|
66
68
|
}));
|
|
@@ -303,7 +303,7 @@ process.env.NODE_ENV !== "production" ? YearCalendar.propTypes = {
|
|
|
303
303
|
readOnly: PropTypes.bool,
|
|
304
304
|
/**
|
|
305
305
|
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
306
|
-
* @default The closest valid year using the validation props, except callbacks such as `
|
|
306
|
+
* @default The closest valid year using the validation props, except callbacks such as `shouldDisableYear`.
|
|
307
307
|
*/
|
|
308
308
|
referenceDate: PropTypes.any,
|
|
309
309
|
/**
|
|
@@ -38,7 +38,7 @@ export interface YearCalendarProps<TDate> extends ExportedYearCalendarProps, Yea
|
|
|
38
38
|
defaultValue?: TDate | null;
|
|
39
39
|
/**
|
|
40
40
|
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
41
|
-
* @default The closest valid year using the validation props, except callbacks such as `
|
|
41
|
+
* @default The closest valid year using the validation props, except callbacks such as `shouldDisableYear`.
|
|
42
42
|
*/
|
|
43
43
|
referenceDate?: TDate;
|
|
44
44
|
/**
|
package/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MuiPickersAdapter, PickersTimezone } from '../../models';
|
|
2
|
+
export declare const useClockReferenceDate: <TDate, TProps extends {}>({ value, referenceDate: referenceDateProp, utils, props, timezone, }: {
|
|
3
|
+
value: TDate;
|
|
4
|
+
referenceDate: TDate | undefined;
|
|
5
|
+
utils: MuiPickersAdapter<TDate, any>;
|
|
6
|
+
props: TProps;
|
|
7
|
+
timezone: PickersTimezone;
|
|
8
|
+
}) => any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { singleItemValueManager } from '../utils/valueManagers';
|
|
3
|
+
import { getTodayDate } from '../utils/date-utils';
|
|
4
|
+
import { SECTION_TYPE_GRANULARITY } from '../utils/getDefaultReferenceDate';
|
|
5
|
+
export const useClockReferenceDate = ({
|
|
6
|
+
value,
|
|
7
|
+
referenceDate: referenceDateProp,
|
|
8
|
+
utils,
|
|
9
|
+
props,
|
|
10
|
+
timezone
|
|
11
|
+
}) => {
|
|
12
|
+
const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
|
|
13
|
+
value,
|
|
14
|
+
utils,
|
|
15
|
+
props,
|
|
16
|
+
referenceDate: referenceDateProp,
|
|
17
|
+
granularity: SECTION_TYPE_GRANULARITY.day,
|
|
18
|
+
timezone,
|
|
19
|
+
getTodayDate: () => getTodayDate(utils, timezone, 'date')
|
|
20
|
+
}),
|
|
21
|
+
// We only want to compute the reference date on mount.
|
|
22
|
+
[] // eslint-disable-line react-hooks/exhaustive-deps
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return value != null ? value : referenceDate;
|
|
26
|
+
};
|
|
@@ -38,6 +38,7 @@ export interface PickerValueManager<TValue, TDate, TError> {
|
|
|
38
38
|
* @param {MuiPickersAdapter<TDate>} params.utils The adapter.
|
|
39
39
|
* @param {number} params.granularity The granularity of the selection possible on this component.
|
|
40
40
|
* @param {PickersTimezone} params.timezone The current timezone.
|
|
41
|
+
* @param {() => TDate} params.getTodayDate The reference date to use if no reference date is passed to the component.
|
|
41
42
|
* @returns {TValue} The reference value to use for non-provided dates.
|
|
42
43
|
*/
|
|
43
44
|
getInitialReferenceValue: (params: {
|
|
@@ -47,6 +48,7 @@ export interface PickerValueManager<TValue, TDate, TError> {
|
|
|
47
48
|
utils: MuiPickersAdapter<TDate>;
|
|
48
49
|
granularity: number;
|
|
49
50
|
timezone: PickersTimezone;
|
|
51
|
+
getTodayDate?: () => TDate;
|
|
50
52
|
}) => TValue;
|
|
51
53
|
/**
|
|
52
54
|
* Method parsing the input value to replace all invalid dates by `null`.
|
|
@@ -31,7 +31,7 @@ export interface BaseClockProps<TDate, TView extends TimeViewWithMeridiem> exten
|
|
|
31
31
|
defaultValue?: TDate | null;
|
|
32
32
|
/**
|
|
33
33
|
* Callback fired when the value changes.
|
|
34
|
-
* @template TDate
|
|
34
|
+
* @template TDate, TView
|
|
35
35
|
* @param {TDate | null} value The new value.
|
|
36
36
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
37
37
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
@@ -47,6 +47,11 @@ export interface BaseClockProps<TDate, TView extends TimeViewWithMeridiem> exten
|
|
|
47
47
|
* @default false
|
|
48
48
|
*/
|
|
49
49
|
readOnly?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
52
|
+
* @default The closest valid time using the validation props, except callbacks such as `shouldDisableTime`.
|
|
53
|
+
*/
|
|
54
|
+
referenceDate?: TDate;
|
|
50
55
|
}
|
|
51
56
|
export interface DesktopOnlyTimePickerProps<TDate> extends Omit<ExportedDigitalClockProps<TDate>, 'timeStep'>, Omit<ExportedMultiSectionDigitalClockProps<TDate>, 'timeSteps'> {
|
|
52
57
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTodayDate } from './date-utils';
|
|
2
|
+
import { DateOrTimeView, FieldSection, MuiPickersAdapter, PickersTimezone } from '../../models';
|
|
2
3
|
export interface GetDefaultReferenceDateProps<TDate> {
|
|
3
4
|
maxDate?: TDate;
|
|
4
5
|
minDate?: TDate;
|
|
@@ -16,9 +17,11 @@ export declare const SECTION_TYPE_GRANULARITY: {
|
|
|
16
17
|
milliseconds: number;
|
|
17
18
|
};
|
|
18
19
|
export declare const getSectionTypeGranularity: (sections: FieldSection[]) => number;
|
|
19
|
-
export declare const
|
|
20
|
+
export declare const getViewsGranularity: (views: readonly DateOrTimeView[]) => number;
|
|
21
|
+
export declare const getDefaultReferenceDate: <TDate>({ props, utils, granularity, timezone, getTodayDate: inGetTodayDate, }: {
|
|
20
22
|
props: GetDefaultReferenceDateProps<TDate>;
|
|
21
23
|
utils: MuiPickersAdapter<TDate, any>;
|
|
22
24
|
granularity: number;
|
|
23
25
|
timezone: PickersTimezone;
|
|
26
|
+
getTodayDate?: (() => TDate) | undefined;
|
|
24
27
|
}) => TDate;
|
|
@@ -13,6 +13,10 @@ export const getSectionTypeGranularity = sections => Math.max(...sections.map(se
|
|
|
13
13
|
var _SECTION_TYPE_GRANULA;
|
|
14
14
|
return (_SECTION_TYPE_GRANULA = SECTION_TYPE_GRANULARITY[section.type]) != null ? _SECTION_TYPE_GRANULA : 1;
|
|
15
15
|
}));
|
|
16
|
+
export const getViewsGranularity = views => Math.max(...views.map(view => {
|
|
17
|
+
var _SECTION_TYPE_GRANULA2;
|
|
18
|
+
return (_SECTION_TYPE_GRANULA2 = SECTION_TYPE_GRANULARITY[view]) != null ? _SECTION_TYPE_GRANULA2 : 1;
|
|
19
|
+
}));
|
|
16
20
|
const roundDate = (utils, granularity, date) => {
|
|
17
21
|
if (granularity === SECTION_TYPE_GRANULARITY.year) {
|
|
18
22
|
return utils.startOfYear(date);
|
|
@@ -41,10 +45,11 @@ export const getDefaultReferenceDate = ({
|
|
|
41
45
|
props,
|
|
42
46
|
utils,
|
|
43
47
|
granularity,
|
|
44
|
-
timezone
|
|
48
|
+
timezone,
|
|
49
|
+
getTodayDate: inGetTodayDate
|
|
45
50
|
}) => {
|
|
46
51
|
var _props$disableIgnorin;
|
|
47
|
-
let referenceDate = roundDate(utils, granularity, getTodayDate(utils, timezone));
|
|
52
|
+
let referenceDate = inGetTodayDate ? inGetTodayDate() : roundDate(utils, granularity, getTodayDate(utils, timezone));
|
|
48
53
|
if (props.minDate != null && utils.isAfterDay(props.minDate, referenceDate)) {
|
|
49
54
|
referenceDate = roundDate(utils, granularity, props.minDate);
|
|
50
55
|
}
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["components", "componentsProps", "slots", "slotProps", "InputProps", "inputProps"],
|
|
4
4
|
_excluded2 = ["inputRef"],
|
|
5
|
-
_excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
|
|
5
|
+
_excluded3 = ["ref", "onPaste", "onKeyDown", "inputMode", "readOnly"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
@@ -43,6 +43,7 @@ var DateField = /*#__PURE__*/React.forwardRef(function DateField(inProps, ref) {
|
|
|
43
43
|
}),
|
|
44
44
|
inputRef = _useDateField.ref,
|
|
45
45
|
onPaste = _useDateField.onPaste,
|
|
46
|
+
onKeyDown = _useDateField.onKeyDown,
|
|
46
47
|
inputMode = _useDateField.inputMode,
|
|
47
48
|
readOnly = _useDateField.readOnly,
|
|
48
49
|
fieldProps = _objectWithoutProperties(_useDateField, _excluded3);
|
|
@@ -55,6 +56,7 @@ var DateField = /*#__PURE__*/React.forwardRef(function DateField(inProps, ref) {
|
|
|
55
56
|
inputProps: _extends({}, fieldProps.inputProps, {
|
|
56
57
|
inputMode: inputMode,
|
|
57
58
|
onPaste: onPaste,
|
|
59
|
+
onKeyDown: onKeyDown,
|
|
58
60
|
ref: inputRef
|
|
59
61
|
})
|
|
60
62
|
}));
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["components", "componentsProps", "slots", "slotProps", "InputProps", "inputProps"],
|
|
4
4
|
_excluded2 = ["inputRef"],
|
|
5
|
-
_excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
|
|
5
|
+
_excluded3 = ["ref", "onPaste", "onKeyDown", "inputMode", "readOnly"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
@@ -43,6 +43,7 @@ var DateTimeField = /*#__PURE__*/React.forwardRef(function DateTimeField(inProps
|
|
|
43
43
|
}),
|
|
44
44
|
inputRef = _useDateTimeField.ref,
|
|
45
45
|
onPaste = _useDateTimeField.onPaste,
|
|
46
|
+
onKeyDown = _useDateTimeField.onKeyDown,
|
|
46
47
|
inputMode = _useDateTimeField.inputMode,
|
|
47
48
|
readOnly = _useDateTimeField.readOnly,
|
|
48
49
|
fieldProps = _objectWithoutProperties(_useDateTimeField, _excluded3);
|
|
@@ -55,6 +56,7 @@ var DateTimeField = /*#__PURE__*/React.forwardRef(function DateTimeField(inProps
|
|
|
55
56
|
inputProps: _extends({}, fieldProps.inputProps, {
|
|
56
57
|
inputMode: inputMode,
|
|
57
58
|
onPaste: onPaste,
|
|
59
|
+
onKeyDown: onKeyDown,
|
|
58
60
|
ref: inputRef
|
|
59
61
|
})
|
|
60
62
|
}));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["ampm", "timeStep", "autoFocus", "components", "componentsProps", "slots", "slotProps", "value", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableClock", "shouldDisableTime", "onChange", "
|
|
4
|
+
var _excluded = ["ampm", "timeStep", "autoFocus", "components", "componentsProps", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableClock", "shouldDisableTime", "onChange", "view", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "disabled", "readOnly", "views", "skipDisabled", "timezone"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
8
9
|
import { alpha, styled, useThemeProps } from '@mui/material/styles';
|
|
9
10
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
10
11
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -19,6 +20,7 @@ import { useViews } from '../internals/hooks/useViews';
|
|
|
19
20
|
import { DIGITAL_CLOCK_VIEW_HEIGHT } from '../internals/constants/dimensions';
|
|
20
21
|
import { useControlledValueWithTimezone } from '../internals/hooks/useValueWithTimezone';
|
|
21
22
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
23
|
+
import { useClockReferenceDate } from '../internals/hooks/useClockReferenceDate';
|
|
22
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
25
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
24
26
|
var classes = ownerState.classes;
|
|
@@ -101,6 +103,8 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
101
103
|
slots = props.slots,
|
|
102
104
|
slotProps = props.slotProps,
|
|
103
105
|
valueProp = props.value,
|
|
106
|
+
defaultValue = props.defaultValue,
|
|
107
|
+
referenceDateProp = props.referenceDate,
|
|
104
108
|
_props$disableIgnorin = props.disableIgnoringDatePartForTimeValidation,
|
|
105
109
|
disableIgnoringDatePartForTimeValidation = _props$disableIgnorin === void 0 ? false : _props$disableIgnorin,
|
|
106
110
|
maxTime = props.maxTime,
|
|
@@ -112,7 +116,6 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
112
116
|
shouldDisableClock = props.shouldDisableClock,
|
|
113
117
|
shouldDisableTime = props.shouldDisableTime,
|
|
114
118
|
onChange = props.onChange,
|
|
115
|
-
defaultValue = props.defaultValue,
|
|
116
119
|
inView = props.view,
|
|
117
120
|
openTo = props.openTo,
|
|
118
121
|
onViewChange = props.onViewChange,
|
|
@@ -147,7 +150,19 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
147
150
|
}, [props]);
|
|
148
151
|
var classes = useUtilityClasses(ownerState);
|
|
149
152
|
var ClockItem = (_ref3 = (_slots$digitalClockIt = slots == null ? void 0 : slots.digitalClockItem) != null ? _slots$digitalClockIt : components == null ? void 0 : components.DigitalClockItem) != null ? _ref3 : DigitalClockItem;
|
|
150
|
-
var clockItemProps = (
|
|
153
|
+
var clockItemProps = useSlotProps({
|
|
154
|
+
elementType: ClockItem,
|
|
155
|
+
externalSlotProps: (_slotProps$digitalClo = slotProps == null ? void 0 : slotProps.digitalClockItem) != null ? _slotProps$digitalClo : componentsProps == null ? void 0 : componentsProps.digitalClockItem,
|
|
156
|
+
ownerState: {},
|
|
157
|
+
className: classes.item
|
|
158
|
+
});
|
|
159
|
+
var valueOrReferenceDate = useClockReferenceDate({
|
|
160
|
+
value: value,
|
|
161
|
+
referenceDate: referenceDateProp,
|
|
162
|
+
utils: utils,
|
|
163
|
+
props: props,
|
|
164
|
+
timezone: timezone
|
|
165
|
+
});
|
|
151
166
|
var handleValueChange = useEventCallback(function (newValue) {
|
|
152
167
|
return handleRawValueChange(newValue, 'finish');
|
|
153
168
|
});
|
|
@@ -177,9 +192,6 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
177
192
|
// Subtracting the 4px of extra margin intended for the first visible section item
|
|
178
193
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
179
194
|
});
|
|
180
|
-
var selectedTimeOrMidnight = React.useMemo(function () {
|
|
181
|
-
return value || utils.setSeconds(utils.setMinutes(utils.setHours(now, 0), 0), 0);
|
|
182
|
-
}, [value, now, utils]);
|
|
183
195
|
var isTimeDisabled = React.useCallback(function (valueToCheck) {
|
|
184
196
|
var isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation, utils);
|
|
185
197
|
var containsValidTime = function containsValidTime() {
|
|
@@ -212,13 +224,13 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
212
224
|
return !containsValidTime() || !isValidValue();
|
|
213
225
|
}, [disableIgnoringDatePartForTimeValidation, utils, minTime, maxTime, disableFuture, now, disablePast, minutesStep, shouldDisableClock, shouldDisableTime]);
|
|
214
226
|
var timeOptions = React.useMemo(function () {
|
|
215
|
-
var startOfDay = utils.startOfDay(
|
|
227
|
+
var startOfDay = utils.startOfDay(valueOrReferenceDate);
|
|
216
228
|
return [startOfDay].concat(_toConsumableArray(Array.from({
|
|
217
229
|
length: Math.ceil(24 * 60 / timeStep) - 1
|
|
218
230
|
}, function (_, index) {
|
|
219
231
|
return utils.addMinutes(startOfDay, timeStep * (index + 1));
|
|
220
|
-
})), [utils.endOfDay(
|
|
221
|
-
}, [
|
|
232
|
+
})), [utils.endOfDay(valueOrReferenceDate)]);
|
|
233
|
+
}, [valueOrReferenceDate, timeStep, utils]);
|
|
222
234
|
return /*#__PURE__*/_jsx(DigitalClockRoot, _extends({
|
|
223
235
|
ref: handleRef,
|
|
224
236
|
className: clsx(classes.root, className),
|
|
@@ -228,6 +240,7 @@ export var DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(in
|
|
|
228
240
|
autoFocusItem: autoFocus || !!focusedView,
|
|
229
241
|
role: "listbox",
|
|
230
242
|
"aria-label": localeText.timePickerToolbarTitle,
|
|
243
|
+
className: classes.list,
|
|
231
244
|
children: timeOptions.map(function (option) {
|
|
232
245
|
if (skipDisabled && isTimeDisabled(option)) {
|
|
233
246
|
return null;
|
|
@@ -332,7 +345,7 @@ process.env.NODE_ENV !== "production" ? DigitalClock.propTypes = {
|
|
|
332
345
|
minutesStep: PropTypes.number,
|
|
333
346
|
/**
|
|
334
347
|
* Callback fired when the value changes.
|
|
335
|
-
* @template TDate
|
|
348
|
+
* @template TDate, TView
|
|
336
349
|
* @param {TDate | null} value The new value.
|
|
337
350
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
338
351
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
@@ -362,6 +375,11 @@ process.env.NODE_ENV !== "production" ? DigitalClock.propTypes = {
|
|
|
362
375
|
* @default false
|
|
363
376
|
*/
|
|
364
377
|
readOnly: PropTypes.bool,
|
|
378
|
+
/**
|
|
379
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
380
|
+
* @default The closest valid time using the validation props, except callbacks such as `shouldDisableTime`.
|
|
381
|
+
*/
|
|
382
|
+
referenceDate: PropTypes.any,
|
|
365
383
|
/**
|
|
366
384
|
* Disable specific clock time.
|
|
367
385
|
* @param {number} clockValue The value to check.
|
|
@@ -297,7 +297,7 @@ process.env.NODE_ENV !== "production" ? MonthCalendar.propTypes = {
|
|
|
297
297
|
readOnly: PropTypes.bool,
|
|
298
298
|
/**
|
|
299
299
|
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
300
|
-
* @default The closest valid month using the validation props, except callbacks such as `
|
|
300
|
+
* @default The closest valid month using the validation props, except callbacks such as `shouldDisableMonth`.
|
|
301
301
|
*/
|
|
302
302
|
referenceDate: PropTypes.any,
|
|
303
303
|
/**
|