@mui/x-date-pickers 6.1.0 → 6.2.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.d.ts +114 -0
- package/AdapterDayjs/AdapterDayjs.js +387 -0
- package/AdapterDayjs/index.d.ts +1 -28
- package/AdapterDayjs/index.js +1 -102
- package/CHANGELOG.md +53 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateCalendar/DayCalendar.d.ts +1 -1
- package/DateField/DateField.js +6 -0
- package/DateField/useDateField.js +3 -1
- package/DatePicker/DatePicker.js +6 -0
- package/DateTimeField/DateTimeField.js +6 -0
- package/DateTimeField/useDateTimeField.js +3 -1
- package/DateTimePicker/DateTimePicker.js +6 -0
- package/DateTimePicker/shared.js +3 -1
- package/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/MobileDatePicker/MobileDatePicker.js +6 -0
- package/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/MobileTimePicker/MobileTimePicker.js +6 -0
- package/README.md +1 -0
- package/TimeClock/TimeClock.types.d.ts +1 -1
- package/TimeField/TimeField.js +6 -0
- package/TimeField/useTimeField.js +3 -1
- package/TimePicker/TimePicker.js +6 -0
- package/index.js +1 -1
- package/internals/components/PickersModalDialog.d.ts +1 -1
- package/internals/components/PickersPopper.d.ts +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +1 -1
- package/internals/hooks/useField/useField.types.d.ts +6 -0
- package/internals/hooks/useField/useField.utils.d.ts +1 -1
- package/internals/hooks/useField/useField.utils.js +16 -4
- package/internals/hooks/useField/useFieldState.js +3 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/index.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.d.ts +3 -179
- package/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +233 -0
- package/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/models/props/basePickerProps.d.ts +6 -0
- package/legacy/AdapterDayjs/AdapterDayjs.js +403 -0
- package/legacy/AdapterDayjs/index.js +1 -119
- package/legacy/DateField/DateField.js +6 -0
- package/legacy/DateField/useDateField.js +3 -1
- package/legacy/DatePicker/DatePicker.js +6 -0
- package/legacy/DateTimeField/DateTimeField.js +6 -0
- package/legacy/DateTimeField/useDateTimeField.js +3 -1
- package/legacy/DateTimePicker/DateTimePicker.js +6 -0
- package/legacy/DateTimePicker/shared.js +3 -1
- package/legacy/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/legacy/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/legacy/MobileDatePicker/MobileDatePicker.js +6 -0
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/legacy/MobileTimePicker/MobileTimePicker.js +6 -0
- package/legacy/TimeField/TimeField.js +6 -0
- package/legacy/TimeField/useTimeField.js +3 -1
- package/legacy/TimePicker/TimePicker.js +6 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/legacy/internals/hooks/useField/useField.utils.js +24 -9
- package/legacy/internals/hooks/useField/useFieldState.js +5 -3
- package/legacy/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/legacy/internals/hooks/usePicker/usePickerValue.js +184 -153
- package/legacy/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/index.js +1 -0
- package/legacy/tests/describeGregorianAdapter/testCalculations.js +273 -0
- package/legacy/tests/describeGregorianAdapter/testFormat.js +26 -0
- package/legacy/tests/describeGregorianAdapter/testLocalization.js +15 -0
- package/legacy/tests/describeValidation/describeValidation.js +2 -1
- package/legacy/tests/describeValidation/testMinutesViewValidation.js +201 -0
- package/legacy/tests/describeValue/testPickerActionBar.js +52 -3
- package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/models/adapters.d.ts +21 -20
- package/modern/AdapterDayjs/AdapterDayjs.js +386 -0
- package/modern/AdapterDayjs/index.js +1 -101
- package/modern/DateField/DateField.js +6 -0
- package/modern/DateField/useDateField.js +3 -1
- package/modern/DatePicker/DatePicker.js +6 -0
- package/modern/DateTimeField/DateTimeField.js +6 -0
- package/modern/DateTimeField/useDateTimeField.js +3 -1
- package/modern/DateTimePicker/DateTimePicker.js +6 -0
- package/modern/DateTimePicker/shared.js +3 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +6 -0
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/modern/MobileTimePicker/MobileTimePicker.js +6 -0
- package/modern/TimeField/TimeField.js +6 -0
- package/modern/TimeField/useTimeField.js +3 -1
- package/modern/TimePicker/TimePicker.js +6 -0
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/modern/internals/hooks/useField/useField.utils.js +16 -4
- package/modern/internals/hooks/useField/useFieldState.js +3 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/modern/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/index.js +1 -0
- package/modern/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/modern/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/modern/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/modern/tests/describeValidation/describeValidation.js +2 -1
- package/modern/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/modern/tests/describeValue/testPickerActionBar.js +52 -3
- package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/node/AdapterDayjs/AdapterDayjs.js +395 -0
- package/node/AdapterDayjs/index.js +6 -104
- package/node/DateField/DateField.js +6 -0
- package/node/DateField/useDateField.js +3 -1
- package/node/DatePicker/DatePicker.js +6 -0
- package/node/DateTimeField/DateTimeField.js +6 -0
- package/node/DateTimeField/useDateTimeField.js +3 -1
- package/node/DateTimePicker/DateTimePicker.js +6 -0
- package/node/DateTimePicker/shared.js +3 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/node/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/node/MobileDatePicker/MobileDatePicker.js +6 -0
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/node/MobileTimePicker/MobileTimePicker.js +6 -0
- package/node/TimeField/TimeField.js +6 -0
- package/node/TimeField/useTimeField.js +3 -1
- package/node/TimePicker/TimePicker.js +6 -0
- package/node/index.js +1 -1
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/node/internals/hooks/useField/useField.utils.js +16 -4
- package/node/internals/hooks/useField/useFieldState.js +3 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/node/internals/hooks/usePicker/usePickerValue.js +187 -152
- package/node/internals/hooks/usePicker/usePickerValue.types.js +5 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.js +29 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +5 -0
- package/node/tests/describeGregorianAdapter/index.js +18 -0
- package/node/tests/describeGregorianAdapter/testCalculations.js +279 -0
- package/node/tests/describeGregorianAdapter/testFormat.js +34 -0
- package/node/tests/describeGregorianAdapter/testLocalization.js +23 -0
- package/node/tests/describeValidation/describeValidation.js +2 -1
- package/node/tests/describeValidation/testMinutesViewValidation.js +210 -0
- package/node/tests/describeValue/testPickerActionBar.js +52 -3
- package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/package.json +9 -9
- package/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/tests/describeGregorianAdapter/index.js +1 -0
- package/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/tests/describeValidation/describeValidation.js +2 -1
- package/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/tests/describeValue/testPickerActionBar.js +52 -3
- package/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "minTime", "maxTime", "minDateTime", "maxDateTime", "minutesStep", "disableIgnoringDatePartForTimeValidation", "shouldDisableClock", "shouldDisableTime", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
3
|
+
const _excluded = ["value", "defaultValue", "format", "formatDensity", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "minTime", "maxTime", "minDateTime", "maxDateTime", "minutesStep", "disableIgnoringDatePartForTimeValidation", "shouldDisableClock", "shouldDisableTime", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
4
4
|
import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
|
|
5
5
|
import { useField } from '../internals/hooks/useField';
|
|
6
6
|
import { validateDateTime } from '../internals/hooks/validation/useDateTimeValidation';
|
|
@@ -31,6 +31,7 @@ export const useDateTimeField = ({
|
|
|
31
31
|
value,
|
|
32
32
|
defaultValue,
|
|
33
33
|
format,
|
|
34
|
+
formatDensity,
|
|
34
35
|
onChange,
|
|
35
36
|
readOnly,
|
|
36
37
|
onError,
|
|
@@ -60,6 +61,7 @@ export const useDateTimeField = ({
|
|
|
60
61
|
value,
|
|
61
62
|
defaultValue,
|
|
62
63
|
format,
|
|
64
|
+
formatDensity,
|
|
63
65
|
onChange,
|
|
64
66
|
readOnly,
|
|
65
67
|
onError,
|
|
@@ -142,6 +142,12 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
142
142
|
* Defaults to localized format based on the used `views`.
|
|
143
143
|
*/
|
|
144
144
|
format: PropTypes.string,
|
|
145
|
+
/**
|
|
146
|
+
* Density of the format when rendered in the input.
|
|
147
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
148
|
+
* @default "dense"
|
|
149
|
+
*/
|
|
150
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
145
151
|
/**
|
|
146
152
|
* Pass a ref to the `input` element.
|
|
147
153
|
*/
|
|
@@ -35,7 +35,9 @@ export function useDateTimePickerDefaultizedProps(props, name) {
|
|
|
35
35
|
localeText,
|
|
36
36
|
orientation: themeProps.orientation ?? 'portrait',
|
|
37
37
|
// TODO: Remove from public API
|
|
38
|
-
disableIgnoringDatePartForTimeValidation: themeProps.disableIgnoringDatePartForTimeValidation ?? Boolean(themeProps.minDateTime || themeProps.maxDateTime
|
|
38
|
+
disableIgnoringDatePartForTimeValidation: themeProps.disableIgnoringDatePartForTimeValidation ?? Boolean(themeProps.minDateTime || themeProps.maxDateTime ||
|
|
39
|
+
// allow time clock to correctly check time validity: https://github.com/mui/mui-x/issues/8520
|
|
40
|
+
themeProps.disablePast || themeProps.disableFuture),
|
|
39
41
|
disableFuture: themeProps.disableFuture ?? false,
|
|
40
42
|
disablePast: themeProps.disablePast ?? false,
|
|
41
43
|
minDate: applyDefaultDate(utils, themeProps.minDateTime ?? themeProps.minDate, defaultDates.minDate),
|
|
@@ -139,6 +139,12 @@ DesktopDatePicker.propTypes = {
|
|
|
139
139
|
* Defaults to localized format based on the used `views`.
|
|
140
140
|
*/
|
|
141
141
|
format: PropTypes.string,
|
|
142
|
+
/**
|
|
143
|
+
* Density of the format when rendered in the input.
|
|
144
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
145
|
+
* @default "dense"
|
|
146
|
+
*/
|
|
147
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
142
148
|
/**
|
|
143
149
|
* Pass a ref to the `input` element.
|
|
144
150
|
*/
|
|
@@ -162,6 +162,12 @@ DesktopDateTimePicker.propTypes = {
|
|
|
162
162
|
* Defaults to localized format based on the used `views`.
|
|
163
163
|
*/
|
|
164
164
|
format: PropTypes.string,
|
|
165
|
+
/**
|
|
166
|
+
* Density of the format when rendered in the input.
|
|
167
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
168
|
+
* @default "dense"
|
|
169
|
+
*/
|
|
170
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
165
171
|
/**
|
|
166
172
|
* Pass a ref to the `input` element.
|
|
167
173
|
*/
|
|
@@ -128,6 +128,12 @@ DesktopTimePicker.propTypes = {
|
|
|
128
128
|
* Defaults to localized format based on the used `views`.
|
|
129
129
|
*/
|
|
130
130
|
format: PropTypes.string,
|
|
131
|
+
/**
|
|
132
|
+
* Density of the format when rendered in the input.
|
|
133
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
134
|
+
* @default "dense"
|
|
135
|
+
*/
|
|
136
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
131
137
|
/**
|
|
132
138
|
* Pass a ref to the `input` element.
|
|
133
139
|
*/
|
|
@@ -136,6 +136,12 @@ MobileDatePicker.propTypes = {
|
|
|
136
136
|
* Defaults to localized format based on the used `views`.
|
|
137
137
|
*/
|
|
138
138
|
format: PropTypes.string,
|
|
139
|
+
/**
|
|
140
|
+
* Density of the format when rendered in the input.
|
|
141
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
142
|
+
* @default "dense"
|
|
143
|
+
*/
|
|
144
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
139
145
|
/**
|
|
140
146
|
* Pass a ref to the `input` element.
|
|
141
147
|
*/
|
|
@@ -160,6 +160,12 @@ MobileDateTimePicker.propTypes = {
|
|
|
160
160
|
* Defaults to localized format based on the used `views`.
|
|
161
161
|
*/
|
|
162
162
|
format: PropTypes.string,
|
|
163
|
+
/**
|
|
164
|
+
* Density of the format when rendered in the input.
|
|
165
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
166
|
+
* @default "dense"
|
|
167
|
+
*/
|
|
168
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
163
169
|
/**
|
|
164
170
|
* Pass a ref to the `input` element.
|
|
165
171
|
*/
|
|
@@ -127,6 +127,12 @@ MobileTimePicker.propTypes = {
|
|
|
127
127
|
* Defaults to localized format based on the used `views`.
|
|
128
128
|
*/
|
|
129
129
|
format: PropTypes.string,
|
|
130
|
+
/**
|
|
131
|
+
* Density of the format when rendered in the input.
|
|
132
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
133
|
+
* @default "dense"
|
|
134
|
+
*/
|
|
135
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
130
136
|
/**
|
|
131
137
|
* Pass a ref to the `input` element.
|
|
132
138
|
*/
|
|
@@ -129,6 +129,12 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
|
|
|
129
129
|
* Format of the date when rendered in the input(s).
|
|
130
130
|
*/
|
|
131
131
|
format: PropTypes.string,
|
|
132
|
+
/**
|
|
133
|
+
* Density of the format when rendered in the input.
|
|
134
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
135
|
+
* @default "dense"
|
|
136
|
+
*/
|
|
137
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
132
138
|
/**
|
|
133
139
|
* Props applied to the [`FormHelperText`](/material-ui/api/form-helper-text/) element.
|
|
134
140
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
3
|
+
const _excluded = ["value", "defaultValue", "format", "formatDensity", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
4
4
|
import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
|
|
5
5
|
import { useField } from '../internals/hooks/useField';
|
|
6
6
|
import { validateTime } from '../internals/hooks/validation/useTimeValidation';
|
|
@@ -24,6 +24,7 @@ export const useTimeField = ({
|
|
|
24
24
|
value,
|
|
25
25
|
defaultValue,
|
|
26
26
|
format,
|
|
27
|
+
formatDensity,
|
|
27
28
|
onChange,
|
|
28
29
|
readOnly,
|
|
29
30
|
onError,
|
|
@@ -48,6 +49,7 @@ export const useTimeField = ({
|
|
|
48
49
|
value,
|
|
49
50
|
defaultValue,
|
|
50
51
|
format,
|
|
52
|
+
formatDensity,
|
|
51
53
|
onChange,
|
|
52
54
|
readOnly,
|
|
53
55
|
onError,
|
|
@@ -116,6 +116,12 @@ process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
|
|
|
116
116
|
* Defaults to localized format based on the used `views`.
|
|
117
117
|
*/
|
|
118
118
|
format: PropTypes.string,
|
|
119
|
+
/**
|
|
120
|
+
* Density of the format when rendered in the input.
|
|
121
|
+
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
122
|
+
* @default "dense"
|
|
123
|
+
*/
|
|
124
|
+
formatDensity: PropTypes.oneOf(['dense', 'spacious']),
|
|
119
125
|
/**
|
|
120
126
|
* Pass a ref to the `input` element.
|
|
121
127
|
*/
|
package/modern/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export const useDesktopPicker = ({
|
|
|
33
33
|
className,
|
|
34
34
|
sx,
|
|
35
35
|
format,
|
|
36
|
+
formatDensity,
|
|
36
37
|
label,
|
|
37
38
|
inputRef,
|
|
38
39
|
readOnly,
|
|
@@ -98,6 +99,7 @@ export const useDesktopPicker = ({
|
|
|
98
99
|
className,
|
|
99
100
|
sx,
|
|
100
101
|
format,
|
|
102
|
+
formatDensity,
|
|
101
103
|
label,
|
|
102
104
|
autoFocus: autoFocus && !props.open
|
|
103
105
|
}),
|
|
@@ -309,7 +309,7 @@ const getEscapedPartsFromFormat = (utils, format) => {
|
|
|
309
309
|
}
|
|
310
310
|
return escapedParts;
|
|
311
311
|
};
|
|
312
|
-
export const splitFormatIntoSections = (utils, localeText, format, date) => {
|
|
312
|
+
export const splitFormatIntoSections = (utils, localeText, format, date, formatDensity) => {
|
|
313
313
|
let startSeparator = '';
|
|
314
314
|
const sections = [];
|
|
315
315
|
const commitToken = token => {
|
|
@@ -380,8 +380,8 @@ export const splitFormatIntoSections = (utils, localeText, format, date) => {
|
|
|
380
380
|
if (cleanedSeparator !== null && cleanedSeparator.includes(' ')) {
|
|
381
381
|
cleanedSeparator = `\u2069${cleanedSeparator}\u2066`;
|
|
382
382
|
}
|
|
383
|
-
if (
|
|
384
|
-
cleanedSeparator =
|
|
383
|
+
if (formatDensity === 'spacious' && ['/', '.', '-'].includes(cleanedSeparator)) {
|
|
384
|
+
cleanedSeparator = ` ${cleanedSeparator} `;
|
|
385
385
|
}
|
|
386
386
|
return cleanedSeparator;
|
|
387
387
|
};
|
|
@@ -586,7 +586,19 @@ const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTran
|
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
};
|
|
589
|
-
|
|
589
|
+
const reliableSectionModificationOrder = {
|
|
590
|
+
year: 1,
|
|
591
|
+
month: 2,
|
|
592
|
+
day: 3,
|
|
593
|
+
weekDay: 4,
|
|
594
|
+
hours: 5,
|
|
595
|
+
minutes: 6,
|
|
596
|
+
seconds: 7,
|
|
597
|
+
meridiem: 8
|
|
598
|
+
};
|
|
599
|
+
export const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) =>
|
|
600
|
+
// cloning sections before sort to avoid mutating it
|
|
601
|
+
[...sections].sort((a, b) => reliableSectionModificationOrder[a.type] - reliableSectionModificationOrder[b.type]).reduce((mergedDate, section) => {
|
|
590
602
|
if (!shouldLimitToEditedSections || section.modified) {
|
|
591
603
|
return transferDateSectionValue(utils, section, dateToTransferFrom, mergedDate);
|
|
592
604
|
}
|
|
@@ -21,6 +21,7 @@ export const useFieldState = params => {
|
|
|
21
21
|
defaultValue,
|
|
22
22
|
onChange,
|
|
23
23
|
format,
|
|
24
|
+
formatDensity = 'dense',
|
|
24
25
|
selectedSections: selectedSectionsProp,
|
|
25
26
|
onSelectedSectionsChange
|
|
26
27
|
}
|
|
@@ -28,7 +29,7 @@ export const useFieldState = params => {
|
|
|
28
29
|
const firstDefaultValue = React.useRef(defaultValue);
|
|
29
30
|
const valueFromTheOutside = valueProp ?? firstDefaultValue.current ?? valueManager.emptyValue;
|
|
30
31
|
const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(utils), [utils]);
|
|
31
|
-
const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, isRTL, date => splitFormatIntoSections(utils, localeText, format, date)), [fieldValueManager, format, localeText, isRTL, utils]);
|
|
32
|
+
const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, isRTL, date => splitFormatIntoSections(utils, localeText, format, date, formatDensity)), [fieldValueManager, format, localeText, isRTL, utils, formatDensity]);
|
|
32
33
|
const placeholder = React.useMemo(() => fieldValueManager.getValueStrFromSections(getSectionsFromValue(valueManager.emptyValue), isRTL), [fieldValueManager, getSectionsFromValue, valueManager.emptyValue, isRTL]);
|
|
33
34
|
const [state, setState] = React.useState(() => {
|
|
34
35
|
const sections = getSectionsFromValue(valueFromTheOutside);
|
|
@@ -152,7 +153,7 @@ export const useFieldState = params => {
|
|
|
152
153
|
if (date == null || !utils.isValid(date)) {
|
|
153
154
|
return null;
|
|
154
155
|
}
|
|
155
|
-
const sections = splitFormatIntoSections(utils, localeText, format, date);
|
|
156
|
+
const sections = splitFormatIntoSections(utils, localeText, format, date, formatDensity);
|
|
156
157
|
return mergeDateIntoReferenceDate(utils, date, sections, referenceDate, false);
|
|
157
158
|
};
|
|
158
159
|
const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
|
|
@@ -29,6 +29,7 @@ export const useMobilePicker = ({
|
|
|
29
29
|
className,
|
|
30
30
|
sx,
|
|
31
31
|
format,
|
|
32
|
+
formatDensity,
|
|
32
33
|
label,
|
|
33
34
|
inputRef,
|
|
34
35
|
readOnly,
|
|
@@ -69,6 +70,7 @@ export const useMobilePicker = ({
|
|
|
69
70
|
className,
|
|
70
71
|
sx,
|
|
71
72
|
format,
|
|
73
|
+
formatDensity,
|
|
72
74
|
label
|
|
73
75
|
}),
|
|
74
76
|
ownerState: props
|