@mui/x-date-pickers-pro 8.0.0-alpha.0 → 8.0.0-alpha.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 +651 -6
- package/DateRangeCalendar/DateRangeCalendar.js +3 -1
- package/DateRangePicker/DateRangePicker.types.d.ts +2 -2
- package/DateRangePicker/DateRangePickerToolbar.js +0 -12
- package/DateRangePicker/shared.d.ts +3 -2
- package/DateTimeRangePicker/DateTimeRangePicker.types.d.ts +2 -2
- package/DateTimeRangePicker/DateTimeRangePickerTabs.js +8 -7
- package/DateTimeRangePicker/DateTimeRangePickerToolbar.d.ts +2 -2
- package/DateTimeRangePicker/DateTimeRangePickerToolbar.js +6 -16
- package/DateTimeRangePicker/shared.d.ts +4 -3
- package/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -12
- package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +12 -10
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -12
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +11 -9
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -12
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +11 -9
- package/README.md +9 -6
- package/SingleInputDateRangeField/SingleInputDateRangeField.js +5 -5
- package/SingleInputDateRangeField/SingleInputDateRangeField.types.d.ts +11 -10
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +5 -5
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.d.ts +11 -10
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +5 -5
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.types.d.ts +10 -9
- package/index.js +1 -1
- package/internals/hooks/models/useRangePicker.d.ts +1 -2
- package/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +14 -4
- package/internals/hooks/useEnrichedRangePickerFieldProps.d.ts +14 -13
- package/internals/hooks/useEnrichedRangePickerFieldProps.js +17 -18
- package/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +15 -5
- package/internals/hooks/useMultiInputFieldSelectedSections.d.ts +6 -7
- package/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +2 -0
- package/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +2 -0
- package/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +3 -1
- package/internals/hooks/useRangePosition.d.ts +3 -2
- package/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +1 -1
- package/internals/hooks/useStaticRangePicker/useStaticRangePicker.types.d.ts +1 -2
- package/internals/models/dateTimeRange.d.ts +2 -2
- package/internals/models/fields.d.ts +6 -6
- package/internals/models/timeRange.d.ts +2 -2
- package/internals/utils/date-fields-utils.d.ts +6 -6
- package/internals/utils/date-range-manager.d.ts +2 -1
- package/internals/utils/date-range-manager.js +11 -9
- package/internals/utils/releaseInfo.js +1 -1
- package/internals/utils/valueManagers.d.ts +4 -3
- package/models/dateRange.d.ts +3 -3
- package/models/fields.d.ts +6 -9
- package/models/index.d.ts +1 -0
- package/models/index.js +2 -1
- package/models/range.d.ts +0 -1
- package/modern/DateRangeCalendar/DateRangeCalendar.js +3 -1
- package/modern/DateRangePicker/DateRangePickerToolbar.js +0 -12
- package/modern/DateTimeRangePicker/DateTimeRangePickerTabs.js +8 -7
- package/modern/DateTimeRangePicker/DateTimeRangePickerToolbar.js +6 -16
- package/modern/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -12
- package/modern/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -12
- package/modern/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -12
- package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +5 -5
- package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +5 -5
- package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +14 -4
- package/modern/internals/hooks/useEnrichedRangePickerFieldProps.js +17 -18
- package/modern/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +15 -5
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +2 -0
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +2 -0
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +3 -1
- package/modern/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +1 -1
- package/modern/internals/utils/date-range-manager.js +11 -9
- package/modern/internals/utils/releaseInfo.js +1 -1
- package/modern/models/index.js +2 -1
- package/modern/validation/validateDateRange.js +8 -0
- package/modern/validation/validateDateTimeRange.js +4 -0
- package/modern/validation/validateTimeRange.js +8 -0
- package/node/DateRangeCalendar/DateRangeCalendar.js +3 -1
- package/node/DateRangePicker/DateRangePickerToolbar.js +0 -12
- package/node/DateTimeRangePicker/DateTimeRangePickerTabs.js +7 -6
- package/node/DateTimeRangePicker/DateTimeRangePickerToolbar.js +5 -15
- package/node/MultiInputDateRangeField/MultiInputDateRangeField.js +9 -11
- package/node/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +9 -11
- package/node/MultiInputTimeRangeField/MultiInputTimeRangeField.js +9 -11
- package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +4 -4
- package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +4 -4
- package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +4 -4
- package/node/index.js +1 -1
- package/node/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +14 -4
- package/node/internals/hooks/useEnrichedRangePickerFieldProps.js +17 -18
- package/node/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +15 -5
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +2 -0
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +2 -0
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +3 -1
- package/node/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +1 -1
- package/node/internals/utils/date-range-manager.js +11 -9
- package/node/internals/utils/releaseInfo.js +1 -1
- package/node/validation/validateDateRange.js +8 -0
- package/node/validation/validateDateTimeRange.js +4 -0
- package/node/validation/validateTimeRange.js +8 -0
- package/package.json +6 -6
- package/validation/validateDateRange.d.ts +9 -1
- package/validation/validateDateRange.js +8 -0
- package/validation/validateDateTimeRange.d.ts +6 -2
- package/validation/validateDateTimeRange.js +4 -0
- package/validation/validateTimeRange.d.ts +9 -1
- package/validation/validateTimeRange.js +8 -0
|
@@ -6,7 +6,7 @@ const _excluded = ["slots", "slotProps", "InputProps", "inputProps"];
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
9
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
9
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
10
10
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
11
11
|
import { useThemeProps } from '@mui/material/styles';
|
|
12
12
|
import { refType } from '@mui/utils';
|
|
@@ -36,7 +36,7 @@ const SingleInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function Sin
|
|
|
36
36
|
inputProps
|
|
37
37
|
} = themeProps,
|
|
38
38
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
39
|
-
const ownerState = themeProps;
|
|
39
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
40
40
|
const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
41
41
|
const textFieldProps = useSlotProps({
|
|
42
42
|
elementType: TextField,
|
|
@@ -302,10 +302,10 @@ process.env.NODE_ENV !== "production" ? SingleInputDateTimeRangeField.propTypes
|
|
|
302
302
|
*/
|
|
303
303
|
shouldDisableTime: PropTypes.func,
|
|
304
304
|
/**
|
|
305
|
-
* If `true`, the format will respect the leading zeroes (
|
|
306
|
-
* If `false`, the format will always add leading zeroes (
|
|
305
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
306
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
307
307
|
*
|
|
308
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
308
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
309
309
|
*
|
|
310
310
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
311
311
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -7,7 +7,7 @@ import * as React from 'react';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
9
9
|
import { useClearableField } from '@mui/x-date-pickers/hooks';
|
|
10
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
10
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
11
11
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
12
12
|
import { useThemeProps } from '@mui/material/styles';
|
|
13
13
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
@@ -36,7 +36,7 @@ const SingleInputTimeRangeField = /*#__PURE__*/React.forwardRef(function SingleI
|
|
|
36
36
|
inputProps
|
|
37
37
|
} = themeProps,
|
|
38
38
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
39
|
-
const ownerState = themeProps;
|
|
39
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
40
40
|
const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
41
41
|
const textFieldProps = useSlotProps({
|
|
42
42
|
elementType: TextField,
|
|
@@ -274,10 +274,10 @@ process.env.NODE_ENV !== "production" ? SingleInputTimeRangeField.propTypes = {
|
|
|
274
274
|
*/
|
|
275
275
|
shouldDisableTime: PropTypes.func,
|
|
276
276
|
/**
|
|
277
|
-
* If `true`, the format will respect the leading zeroes (
|
|
278
|
-
* If `false`, the format will always add leading zeroes (
|
|
277
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
278
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
279
279
|
*
|
|
280
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
280
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
281
281
|
*
|
|
282
282
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
283
283
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
package/modern/index.js
CHANGED
|
@@ -43,12 +43,21 @@ export const useDesktopRangePicker = _ref => {
|
|
|
43
43
|
const popperRef = React.useRef(null);
|
|
44
44
|
const startFieldRef = React.useRef(null);
|
|
45
45
|
const endFieldRef = React.useRef(null);
|
|
46
|
+
const singleInputFieldRef = React.useRef(null);
|
|
46
47
|
const initialView = React.useRef(props.openTo ?? null);
|
|
47
48
|
const fieldType = slots.field.fieldType ?? 'multi-input';
|
|
48
49
|
const {
|
|
49
50
|
rangePosition,
|
|
50
51
|
onRangePositionChange
|
|
51
|
-
} = useRangePosition(props, fieldType === 'single-input' ?
|
|
52
|
+
} = useRangePosition(props, fieldType === 'single-input' ? singleInputFieldRef : undefined);
|
|
53
|
+
let fieldRef;
|
|
54
|
+
if (fieldType === 'single-input') {
|
|
55
|
+
fieldRef = singleInputFieldRef;
|
|
56
|
+
} else if (rangePosition === 'start') {
|
|
57
|
+
fieldRef = startFieldRef;
|
|
58
|
+
} else {
|
|
59
|
+
fieldRef = endFieldRef;
|
|
60
|
+
}
|
|
52
61
|
const {
|
|
53
62
|
open,
|
|
54
63
|
actions,
|
|
@@ -60,9 +69,9 @@ export const useDesktopRangePicker = _ref => {
|
|
|
60
69
|
ownerState
|
|
61
70
|
} = usePicker(_extends({}, pickerParams, {
|
|
62
71
|
props,
|
|
63
|
-
|
|
72
|
+
variant: 'desktop',
|
|
64
73
|
autoFocusView: false,
|
|
65
|
-
fieldRef
|
|
74
|
+
fieldRef,
|
|
66
75
|
localeText,
|
|
67
76
|
additionalViewProps: {
|
|
68
77
|
rangePosition,
|
|
@@ -113,7 +122,7 @@ export const useDesktopRangePicker = _ref => {
|
|
|
113
122
|
ownerState
|
|
114
123
|
});
|
|
115
124
|
const enrichedFieldProps = useEnrichedRangePickerFieldProps({
|
|
116
|
-
|
|
125
|
+
variant: 'desktop',
|
|
117
126
|
fieldType,
|
|
118
127
|
open,
|
|
119
128
|
actions,
|
|
@@ -130,6 +139,7 @@ export const useDesktopRangePicker = _ref => {
|
|
|
130
139
|
anchorRef,
|
|
131
140
|
startFieldRef,
|
|
132
141
|
endFieldRef,
|
|
142
|
+
singleInputFieldRef,
|
|
133
143
|
currentView: layoutProps.view !== props.openTo ? layoutProps.view : undefined,
|
|
134
144
|
initialView: initialView.current ?? undefined,
|
|
135
145
|
onViewChange: layoutProps.onViewChange
|
|
@@ -8,7 +8,7 @@ import useForkRef from '@mui/utils/useForkRef';
|
|
|
8
8
|
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
|
|
9
9
|
import { onSpaceOrEnter } from '@mui/x-date-pickers/internals';
|
|
10
10
|
const useMultiInputFieldSlotProps = ({
|
|
11
|
-
|
|
11
|
+
variant,
|
|
12
12
|
open,
|
|
13
13
|
actions,
|
|
14
14
|
readOnly,
|
|
@@ -33,7 +33,7 @@ const useMultiInputFieldSlotProps = ({
|
|
|
33
33
|
const handleEndFieldRef = useForkRef(fieldProps.unstableEndFieldRef, endFieldRef);
|
|
34
34
|
const previousRangePosition = React.useRef(rangePosition);
|
|
35
35
|
React.useEffect(() => {
|
|
36
|
-
if (!open) {
|
|
36
|
+
if (!open || variant === 'mobile') {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const currentFieldRef = rangePosition === 'start' ? startFieldRef : endFieldRef;
|
|
@@ -49,7 +49,7 @@ const useMultiInputFieldSlotProps = ({
|
|
|
49
49
|
// use the current view or `0` when the range position has just been swapped
|
|
50
50
|
previousRangePosition.current === rangePosition ? currentView : 0);
|
|
51
51
|
previousRangePosition.current = rangePosition;
|
|
52
|
-
}, [rangePosition, open, currentView, startFieldRef, endFieldRef]);
|
|
52
|
+
}, [rangePosition, open, currentView, startFieldRef, endFieldRef, variant]);
|
|
53
53
|
const openRangeStartSelection = event => {
|
|
54
54
|
event.stopPropagation();
|
|
55
55
|
onRangePositionChange('start');
|
|
@@ -98,7 +98,7 @@ const useMultiInputFieldSlotProps = ({
|
|
|
98
98
|
focused: open ? rangePosition === 'start' : undefined
|
|
99
99
|
}, !readOnly && !fieldProps.disabled && {
|
|
100
100
|
onClick: openRangeStartSelection
|
|
101
|
-
},
|
|
101
|
+
}, variant === 'mobile' && {
|
|
102
102
|
readOnly: true
|
|
103
103
|
});
|
|
104
104
|
if (anchorRef) {
|
|
@@ -114,7 +114,7 @@ const useMultiInputFieldSlotProps = ({
|
|
|
114
114
|
focused: open ? rangePosition === 'end' : undefined
|
|
115
115
|
}, !readOnly && !fieldProps.disabled && {
|
|
116
116
|
onClick: openRangeEndSelection
|
|
117
|
-
},
|
|
117
|
+
}, variant === 'mobile' && {
|
|
118
118
|
readOnly: true
|
|
119
119
|
});
|
|
120
120
|
InputProps = resolvedComponentProps?.InputProps;
|
|
@@ -146,7 +146,7 @@ const useMultiInputFieldSlotProps = ({
|
|
|
146
146
|
return enrichedFieldProps;
|
|
147
147
|
};
|
|
148
148
|
const useSingleInputFieldSlotProps = ({
|
|
149
|
-
|
|
149
|
+
variant,
|
|
150
150
|
open,
|
|
151
151
|
actions,
|
|
152
152
|
readOnly,
|
|
@@ -156,36 +156,35 @@ const useSingleInputFieldSlotProps = ({
|
|
|
156
156
|
onBlur,
|
|
157
157
|
rangePosition,
|
|
158
158
|
onRangePositionChange,
|
|
159
|
-
|
|
160
|
-
endFieldRef,
|
|
159
|
+
singleInputFieldRef,
|
|
161
160
|
pickerSlots,
|
|
162
161
|
pickerSlotProps,
|
|
163
162
|
fieldProps,
|
|
164
163
|
anchorRef,
|
|
165
164
|
currentView
|
|
166
165
|
}) => {
|
|
167
|
-
const handleFieldRef = useForkRef(fieldProps.unstableFieldRef,
|
|
166
|
+
const handleFieldRef = useForkRef(fieldProps.unstableFieldRef, singleInputFieldRef);
|
|
168
167
|
React.useEffect(() => {
|
|
169
|
-
if (!open || !
|
|
168
|
+
if (!open || !singleInputFieldRef.current || variant === 'mobile') {
|
|
170
169
|
return;
|
|
171
170
|
}
|
|
172
|
-
if (
|
|
171
|
+
if (singleInputFieldRef.current.isFieldFocused()) {
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
// bring back focus to the field with the current view section selected
|
|
177
176
|
if (currentView) {
|
|
178
|
-
const sections =
|
|
177
|
+
const sections = singleInputFieldRef.current.getSections().map(section => section.type);
|
|
179
178
|
const newSelectedSection = rangePosition === 'start' ? sections.indexOf(currentView) : sections.lastIndexOf(currentView);
|
|
180
|
-
|
|
179
|
+
singleInputFieldRef.current?.focusField(newSelectedSection);
|
|
181
180
|
}
|
|
182
|
-
}, [rangePosition, open, currentView,
|
|
181
|
+
}, [rangePosition, open, currentView, singleInputFieldRef, variant]);
|
|
183
182
|
const updateRangePosition = () => {
|
|
184
|
-
if (!
|
|
183
|
+
if (!singleInputFieldRef.current?.isFieldFocused()) {
|
|
185
184
|
return;
|
|
186
185
|
}
|
|
187
|
-
const sections =
|
|
188
|
-
const activeSectionIndex =
|
|
186
|
+
const sections = singleInputFieldRef.current.getSections();
|
|
187
|
+
const activeSectionIndex = singleInputFieldRef.current?.getActiveSectionIndex();
|
|
189
188
|
const domRangePosition = activeSectionIndex == null || activeSectionIndex < sections.length / 2 ? 'start' : 'end';
|
|
190
189
|
if (domRangePosition != null && domRangePosition !== rangePosition) {
|
|
191
190
|
onRangePositionChange(domRangePosition);
|
|
@@ -225,7 +224,7 @@ const useSingleInputFieldSlotProps = ({
|
|
|
225
224
|
focused: open ? true : undefined
|
|
226
225
|
}, labelId != null && {
|
|
227
226
|
id: labelId
|
|
228
|
-
},
|
|
227
|
+
}, variant === 'mobile' && {
|
|
229
228
|
readOnly: true
|
|
230
229
|
}, !readOnly && !fieldProps.disabled && {
|
|
231
230
|
onClick: openPicker
|
|
@@ -40,13 +40,22 @@ export const useMobileRangePicker = _ref => {
|
|
|
40
40
|
} = props;
|
|
41
41
|
const startFieldRef = React.useRef(null);
|
|
42
42
|
const endFieldRef = React.useRef(null);
|
|
43
|
+
const singleInputFieldRef = React.useRef(null);
|
|
43
44
|
const fieldType = slots.field.fieldType ?? 'multi-input';
|
|
44
45
|
const {
|
|
45
46
|
rangePosition,
|
|
46
47
|
onRangePositionChange
|
|
47
|
-
} = useRangePosition(props, fieldType === 'single-input' ?
|
|
48
|
+
} = useRangePosition(props, fieldType === 'single-input' ? singleInputFieldRef : undefined);
|
|
48
49
|
const labelId = useId();
|
|
49
50
|
const contextTranslations = usePickerTranslations();
|
|
51
|
+
let fieldRef;
|
|
52
|
+
if (fieldType === 'single-input') {
|
|
53
|
+
fieldRef = singleInputFieldRef;
|
|
54
|
+
} else if (rangePosition === 'start') {
|
|
55
|
+
fieldRef = startFieldRef;
|
|
56
|
+
} else {
|
|
57
|
+
fieldRef = endFieldRef;
|
|
58
|
+
}
|
|
50
59
|
const {
|
|
51
60
|
open,
|
|
52
61
|
actions,
|
|
@@ -57,9 +66,9 @@ export const useMobileRangePicker = _ref => {
|
|
|
57
66
|
ownerState
|
|
58
67
|
} = usePicker(_extends({}, pickerParams, {
|
|
59
68
|
props,
|
|
60
|
-
|
|
69
|
+
variant: 'mobile',
|
|
61
70
|
autoFocusView: true,
|
|
62
|
-
fieldRef
|
|
71
|
+
fieldRef,
|
|
63
72
|
localeText,
|
|
64
73
|
additionalViewProps: {
|
|
65
74
|
rangePosition,
|
|
@@ -95,7 +104,7 @@ export const useMobileRangePicker = _ref => {
|
|
|
95
104
|
});
|
|
96
105
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
97
106
|
const enrichedFieldProps = useEnrichedRangePickerFieldProps({
|
|
98
|
-
|
|
107
|
+
variant: 'mobile',
|
|
99
108
|
fieldType,
|
|
100
109
|
open,
|
|
101
110
|
actions,
|
|
@@ -110,7 +119,8 @@ export const useMobileRangePicker = _ref => {
|
|
|
110
119
|
pickerSlotProps: innerSlotProps,
|
|
111
120
|
fieldProps,
|
|
112
121
|
startFieldRef,
|
|
113
|
-
endFieldRef
|
|
122
|
+
endFieldRef,
|
|
123
|
+
singleInputFieldRef
|
|
114
124
|
});
|
|
115
125
|
const slotPropsForLayout = _extends({}, innerSlotProps, {
|
|
116
126
|
tabs: _extends({}, innerSlotProps?.tabs, {
|
|
@@ -18,6 +18,7 @@ export const useMultiInputDateRangeField = ({
|
|
|
18
18
|
const {
|
|
19
19
|
value: valueProp,
|
|
20
20
|
defaultValue,
|
|
21
|
+
referenceDate,
|
|
21
22
|
format,
|
|
22
23
|
formatDensity,
|
|
23
24
|
shouldRespectLeadingZeros,
|
|
@@ -39,6 +40,7 @@ export const useMultiInputDateRangeField = ({
|
|
|
39
40
|
timezone: timezoneProp,
|
|
40
41
|
value: valueProp,
|
|
41
42
|
defaultValue,
|
|
43
|
+
referenceDate,
|
|
42
44
|
onChange,
|
|
43
45
|
valueManager: rangeValueManager
|
|
44
46
|
});
|
|
@@ -18,6 +18,7 @@ export const useMultiInputDateTimeRangeField = ({
|
|
|
18
18
|
const {
|
|
19
19
|
value: valueProp,
|
|
20
20
|
defaultValue,
|
|
21
|
+
referenceDate,
|
|
21
22
|
format,
|
|
22
23
|
formatDensity,
|
|
23
24
|
shouldRespectLeadingZeros,
|
|
@@ -39,6 +40,7 @@ export const useMultiInputDateTimeRangeField = ({
|
|
|
39
40
|
timezone: timezoneProp,
|
|
40
41
|
value: valueProp,
|
|
41
42
|
defaultValue,
|
|
43
|
+
referenceDate,
|
|
42
44
|
onChange,
|
|
43
45
|
valueManager: rangeValueManager
|
|
44
46
|
});
|
|
@@ -18,6 +18,7 @@ export const useMultiInputTimeRangeField = ({
|
|
|
18
18
|
const {
|
|
19
19
|
value: valueProp,
|
|
20
20
|
defaultValue,
|
|
21
|
+
referenceDate,
|
|
21
22
|
format,
|
|
22
23
|
formatDensity,
|
|
23
24
|
shouldRespectLeadingZeros,
|
|
@@ -40,7 +41,8 @@ export const useMultiInputTimeRangeField = ({
|
|
|
40
41
|
value: valueProp,
|
|
41
42
|
defaultValue,
|
|
42
43
|
onChange,
|
|
43
|
-
valueManager: rangeValueManager
|
|
44
|
+
valueManager: rangeValueManager,
|
|
45
|
+
referenceDate
|
|
44
46
|
});
|
|
45
47
|
const {
|
|
46
48
|
validationError,
|
|
@@ -52,7 +52,7 @@ export const useStaticRangePicker = _ref => {
|
|
|
52
52
|
rangePosition,
|
|
53
53
|
onRangePositionChange
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
variant: displayStaticWrapperAs
|
|
56
56
|
}));
|
|
57
57
|
const Layout = slots?.layout ?? PickerStaticLayout;
|
|
58
58
|
const slotPropsForLayout = _extends({}, slotProps, {
|
|
@@ -5,7 +5,8 @@ export function calculateRangeChange({
|
|
|
5
5
|
newDate: selectedDate,
|
|
6
6
|
rangePosition,
|
|
7
7
|
allowRangeFlip = false,
|
|
8
|
-
shouldMergeDateAndTime = false
|
|
8
|
+
shouldMergeDateAndTime = false,
|
|
9
|
+
referenceDate
|
|
9
10
|
}) {
|
|
10
11
|
const [start, end] = range;
|
|
11
12
|
if (shouldMergeDateAndTime && selectedDate) {
|
|
@@ -17,29 +18,30 @@ export function calculateRangeChange({
|
|
|
17
18
|
selectedDate = mergeDateAndTime(utils, selectedDate, end);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
const newSelectedDate = referenceDate && selectedDate && shouldMergeDateAndTime ? mergeDateAndTime(utils, selectedDate, referenceDate) : selectedDate;
|
|
20
22
|
if (rangePosition === 'start') {
|
|
21
23
|
const truthyResult = allowRangeFlip ? {
|
|
22
24
|
nextSelection: 'start',
|
|
23
|
-
newRange: [end,
|
|
25
|
+
newRange: [end, newSelectedDate]
|
|
24
26
|
} : {
|
|
25
27
|
nextSelection: 'end',
|
|
26
|
-
newRange: [
|
|
28
|
+
newRange: [newSelectedDate, null]
|
|
27
29
|
};
|
|
28
|
-
return Boolean(end) && utils.isAfter(
|
|
30
|
+
return Boolean(end) && utils.isAfter(newSelectedDate, end) ? truthyResult : {
|
|
29
31
|
nextSelection: 'end',
|
|
30
|
-
newRange: [
|
|
32
|
+
newRange: [newSelectedDate, end]
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
const truthyResult = allowRangeFlip ? {
|
|
34
36
|
nextSelection: 'end',
|
|
35
|
-
newRange: [
|
|
37
|
+
newRange: [newSelectedDate, start]
|
|
36
38
|
} : {
|
|
37
39
|
nextSelection: 'end',
|
|
38
|
-
newRange: [
|
|
40
|
+
newRange: [newSelectedDate, null]
|
|
39
41
|
};
|
|
40
|
-
return Boolean(start) && utils.isBeforeDay(
|
|
42
|
+
return Boolean(start) && utils.isBeforeDay(newSelectedDate, start) ? truthyResult : {
|
|
41
43
|
nextSelection: 'start',
|
|
42
|
-
newRange: [start,
|
|
44
|
+
newRange: [start, newSelectedDate]
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
export function calculateRangePreview(options) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ponyfillGlobal } from '@mui/utils';
|
|
2
2
|
export const getReleaseInfo = () => {
|
|
3
|
-
const releaseInfo = "
|
|
3
|
+
const releaseInfo = "MTczMjgzNDgwMDAwMA==";
|
|
4
4
|
if (process.env.NODE_ENV !== 'production') {
|
|
5
5
|
// A simple hack to set the value in the test environment (has no build step).
|
|
6
6
|
// eslint-disable-next-line no-useless-concat
|
package/modern/models/index.js
CHANGED
|
@@ -9,6 +9,14 @@ import { rangeValueManager } from "../internals/utils/valueManagers.js";
|
|
|
9
9
|
* Validation props used by the Date Range Picker, Date Range Field and Date Range Calendar components.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Validation props as received by the validateDateRange method.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Name of the props that should be defaulted before being passed to the validateDateRange method.
|
|
18
|
+
*/
|
|
19
|
+
|
|
12
20
|
export const validateDateRange = ({
|
|
13
21
|
adapter,
|
|
14
22
|
value,
|
|
@@ -9,6 +9,10 @@ import { rangeValueManager } from "../internals/utils/valueManagers.js";
|
|
|
9
9
|
* Validation props used by the Date Time Range Picker and Date Time Range Field.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Validation props as received by the validateDateTimeRange method.
|
|
14
|
+
*/
|
|
15
|
+
|
|
12
16
|
export const validateDateTimeRange = ({
|
|
13
17
|
adapter,
|
|
14
18
|
value,
|
|
@@ -6,6 +6,14 @@ import { rangeValueManager } from "../internals/utils/valueManagers.js";
|
|
|
6
6
|
* Validation props used by the Time Range Picker and Time Range Field.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Validation props as received by the validateTimeRange method.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Name of the props that should be defaulted before being passed to the validateTimeRange method.
|
|
15
|
+
*/
|
|
16
|
+
|
|
9
17
|
export const validateTimeRange = ({
|
|
10
18
|
adapter,
|
|
11
19
|
value,
|
|
@@ -176,6 +176,7 @@ const DateRangeCalendar = exports.DateRangeCalendar = /*#__PURE__*/React.forward
|
|
|
176
176
|
name: 'DateRangeCalendar',
|
|
177
177
|
timezone: timezoneProp,
|
|
178
178
|
value: valueProp,
|
|
179
|
+
referenceDate,
|
|
179
180
|
defaultValue,
|
|
180
181
|
onChange,
|
|
181
182
|
valueManager: _valueManagers.rangeValueManager
|
|
@@ -217,7 +218,8 @@ const DateRangeCalendar = exports.DateRangeCalendar = /*#__PURE__*/React.forward
|
|
|
217
218
|
range: value,
|
|
218
219
|
rangePosition,
|
|
219
220
|
allowRangeFlip,
|
|
220
|
-
shouldMergeDateAndTime: true
|
|
221
|
+
shouldMergeDateAndTime: true,
|
|
222
|
+
referenceDate
|
|
221
223
|
});
|
|
222
224
|
const isNextSectionAvailable = availableRangePositions.includes(nextSelection);
|
|
223
225
|
if (isNextSectionAvailable) {
|
|
@@ -106,12 +106,6 @@ process.env.NODE_ENV !== "production" ? DateRangePickerToolbar.propTypes = {
|
|
|
106
106
|
*/
|
|
107
107
|
classes: _propTypes.default.object,
|
|
108
108
|
className: _propTypes.default.string,
|
|
109
|
-
/**
|
|
110
|
-
* If `true`, the component is disabled.
|
|
111
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
112
|
-
* @default false
|
|
113
|
-
*/
|
|
114
|
-
disabled: _propTypes.default.bool,
|
|
115
109
|
/**
|
|
116
110
|
* If `true`, show the toolbar even in desktop mode.
|
|
117
111
|
* @default `true` for Desktop, `false` for Mobile.
|
|
@@ -125,12 +119,6 @@ process.env.NODE_ENV !== "production" ? DateRangePickerToolbar.propTypes = {
|
|
|
125
119
|
*/
|
|
126
120
|
onViewChange: _propTypes.default.func.isRequired,
|
|
127
121
|
rangePosition: _propTypes.default.oneOf(['end', 'start']).isRequired,
|
|
128
|
-
/**
|
|
129
|
-
* If `true`, the component is read-only.
|
|
130
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
131
|
-
* @default false
|
|
132
|
-
*/
|
|
133
|
-
readOnly: _propTypes.default.bool,
|
|
134
122
|
/**
|
|
135
123
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
136
124
|
*/
|
|
@@ -32,10 +32,7 @@ const tabToView = tab => {
|
|
|
32
32
|
}
|
|
33
33
|
return 'hours';
|
|
34
34
|
};
|
|
35
|
-
const useUtilityClasses =
|
|
36
|
-
const {
|
|
37
|
-
classes
|
|
38
|
-
} = ownerState;
|
|
35
|
+
const useUtilityClasses = classes => {
|
|
39
36
|
const slots = {
|
|
40
37
|
root: ['root'],
|
|
41
38
|
tabButton: ['tabButton'],
|
|
@@ -86,10 +83,14 @@ const DateTimeRangePickerTabs = exports.DateTimeRangePickerTabs = function DateT
|
|
|
86
83
|
rangePosition,
|
|
87
84
|
onRangePositionChange,
|
|
88
85
|
className,
|
|
86
|
+
classes: classesProp,
|
|
89
87
|
sx
|
|
90
88
|
} = props;
|
|
91
89
|
const translations = (0, _hooks.usePickerTranslations)();
|
|
92
|
-
const
|
|
90
|
+
const {
|
|
91
|
+
ownerState
|
|
92
|
+
} = (0, _internals.usePickerPrivateContext)();
|
|
93
|
+
const classes = useUtilityClasses(classesProp);
|
|
93
94
|
const value = React.useMemo(() => viewToTab(view, rangePosition), [view, rangePosition]);
|
|
94
95
|
const isPreviousHidden = value === 'start-date';
|
|
95
96
|
const isNextHidden = value === 'end-time';
|
|
@@ -128,7 +129,7 @@ const DateTimeRangePickerTabs = exports.DateTimeRangePickerTabs = function DateT
|
|
|
128
129
|
return null;
|
|
129
130
|
}
|
|
130
131
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(DateTimeRangePickerTabsRoot, {
|
|
131
|
-
ownerState:
|
|
132
|
+
ownerState: ownerState,
|
|
132
133
|
className: (0, _clsx.default)(classes.root, className),
|
|
133
134
|
sx: sx,
|
|
134
135
|
children: [!isPreviousHidden ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
|
|
@@ -20,7 +20,7 @@ var _DateTimePicker = require("@mui/x-date-pickers/DateTimePicker");
|
|
|
20
20
|
var _dateTimeRangePickerToolbarClasses = require("./dateTimeRangePickerToolbarClasses");
|
|
21
21
|
var _dateRangeManager = require("../internals/utils/date-range-manager");
|
|
22
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
|
-
const _excluded = ["value", "rangePosition", "onRangePositionChange", "className", "onViewChange", "toolbarVariant", "onChange", "classes", "view", "isLandscape", "views", "ampm", "
|
|
23
|
+
const _excluded = ["value", "rangePosition", "onRangePositionChange", "className", "onViewChange", "toolbarVariant", "onChange", "classes", "view", "isLandscape", "views", "ampm", "hidden", "toolbarFormat", "toolbarPlaceholder", "titleId", "sx"];
|
|
24
24
|
const useUtilityClasses = ownerState => {
|
|
25
25
|
const {
|
|
26
26
|
classes
|
|
@@ -93,8 +93,6 @@ const DateTimeRangePickerToolbar = exports.DateTimeRangePickerToolbar = /*#__PUR
|
|
|
93
93
|
isLandscape,
|
|
94
94
|
views,
|
|
95
95
|
ampm,
|
|
96
|
-
disabled,
|
|
97
|
-
readOnly,
|
|
98
96
|
hidden,
|
|
99
97
|
toolbarFormat,
|
|
100
98
|
toolbarPlaceholder,
|
|
@@ -102,6 +100,10 @@ const DateTimeRangePickerToolbar = exports.DateTimeRangePickerToolbar = /*#__PUR
|
|
|
102
100
|
sx
|
|
103
101
|
} = props,
|
|
104
102
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
103
|
+
const {
|
|
104
|
+
disabled,
|
|
105
|
+
readOnly
|
|
106
|
+
} = (0, _hooks.usePickerContext)();
|
|
105
107
|
const commonToolbarProps = {
|
|
106
108
|
isLandscape,
|
|
107
109
|
views,
|
|
@@ -190,12 +192,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerToolbar.propTypes = {
|
|
|
190
192
|
*/
|
|
191
193
|
classes: _propTypes.default.object,
|
|
192
194
|
className: _propTypes.default.string,
|
|
193
|
-
/**
|
|
194
|
-
* If `true`, the component is disabled.
|
|
195
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
196
|
-
* @default false
|
|
197
|
-
*/
|
|
198
|
-
disabled: _propTypes.default.bool,
|
|
199
195
|
/**
|
|
200
196
|
* If `true`, show the toolbar even in desktop mode.
|
|
201
197
|
* @default `true` for Desktop, `false` for Mobile.
|
|
@@ -211,12 +207,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerToolbar.propTypes = {
|
|
|
211
207
|
*/
|
|
212
208
|
onViewChange: _propTypes.default.func.isRequired,
|
|
213
209
|
rangePosition: _propTypes.default.oneOf(['end', 'start']).isRequired,
|
|
214
|
-
/**
|
|
215
|
-
* If `true`, the component is read-only.
|
|
216
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
217
|
-
* @default false
|
|
218
|
-
*/
|
|
219
|
-
readOnly: _propTypes.default.bool,
|
|
220
210
|
/**
|
|
221
211
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
222
212
|
*/
|
|
@@ -23,14 +23,11 @@ var _hooks = require("@mui/x-date-pickers/hooks");
|
|
|
23
23
|
var _PickersTextField = require("@mui/x-date-pickers/PickersTextField");
|
|
24
24
|
var _useMultiInputDateRangeField = require("../internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField");
|
|
25
25
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
26
|
-
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className"];
|
|
26
|
+
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className", "classes"];
|
|
27
27
|
const multiInputDateRangeFieldClasses = exports.multiInputDateRangeFieldClasses = (0, _utils.unstable_generateUtilityClasses)('MuiMultiInputDateRangeField', ['root', 'separator']);
|
|
28
28
|
const getMultiInputDateRangeFieldUtilityClass = slot => (0, _utils.unstable_generateUtilityClass)('MuiMultiInputDateRangeField', slot);
|
|
29
29
|
exports.getMultiInputDateRangeFieldUtilityClass = getMultiInputDateRangeFieldUtilityClass;
|
|
30
|
-
const useUtilityClasses =
|
|
31
|
-
const {
|
|
32
|
-
classes
|
|
33
|
-
} = ownerState;
|
|
30
|
+
const useUtilityClasses = classes => {
|
|
34
31
|
const slots = {
|
|
35
32
|
root: ['root'],
|
|
36
33
|
separator: ['separator']
|
|
@@ -78,11 +75,12 @@ const MultiInputDateRangeField = exports.MultiInputDateRangeField = /*#__PURE__*
|
|
|
78
75
|
slotProps,
|
|
79
76
|
unstableStartFieldRef,
|
|
80
77
|
unstableEndFieldRef,
|
|
81
|
-
className
|
|
78
|
+
className,
|
|
79
|
+
classes: classesProp
|
|
82
80
|
} = forwardedProps,
|
|
83
81
|
otherForwardedProps = (0, _objectWithoutPropertiesLoose2.default)(forwardedProps, _excluded);
|
|
84
|
-
const ownerState =
|
|
85
|
-
const classes = useUtilityClasses(
|
|
82
|
+
const ownerState = (0, _internals.useFieldOwnerState)(internalProps);
|
|
83
|
+
const classes = useUtilityClasses(classesProp);
|
|
86
84
|
const Root = slots?.root ?? MultiInputDateRangeFieldRoot;
|
|
87
85
|
const rootProps = (0, _useSlotProps.default)({
|
|
88
86
|
elementType: Root,
|
|
@@ -266,10 +264,10 @@ process.env.NODE_ENV !== "production" ? MultiInputDateRangeField.propTypes = {
|
|
|
266
264
|
*/
|
|
267
265
|
shouldDisableDate: _propTypes.default.func,
|
|
268
266
|
/**
|
|
269
|
-
* If `true`, the format will respect the leading zeroes (
|
|
270
|
-
* If `false`, the format will always add leading zeroes (
|
|
267
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
268
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
271
269
|
*
|
|
272
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
270
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
273
271
|
*
|
|
274
272
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
275
273
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|