@mui/x-date-pickers 8.0.0-alpha.13 → 8.0.0-alpha.14
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 +131 -0
- package/DatePicker/shared.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/DateTimePicker/shared.d.ts +18 -10
- package/DateTimePicker/shared.js +23 -2
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/PickersTextField/PickersTextField.js +3 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/TimePicker/shared.d.ts +1 -1
- package/esm/DatePicker/shared.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/esm/DateTimePicker/shared.d.ts +18 -10
- package/esm/DateTimePicker/shared.js +23 -2
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/esm/PickersTextField/PickersTextField.js +3 -1
- package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/esm/TimePicker/shared.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.js +6 -2
- package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/esm/internals/components/PickerProvider.d.ts +137 -6
- package/esm/internals/components/PickerProvider.js +1 -1
- package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/esm/internals/hooks/useField/useField.js +7 -8
- package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
- package/esm/internals/hooks/useField/useField.utils.js +4 -1
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/esm/internals/hooks/useField/useFieldState.js +136 -83
- package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/esm/internals/hooks/usePicker/index.d.ts +1 -3
- package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/esm/internals/hooks/usePicker/usePicker.js +276 -34
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/esm/internals/index.d.ts +3 -6
- package/esm/internals/models/manager.d.ts +108 -4
- package/esm/internals/models/props/basePickerProps.d.ts +2 -2
- package/esm/internals/models/props/time.d.ts +1 -1
- package/esm/internals/utils/date-time-utils.d.ts +2 -2
- package/esm/internals/utils/valueManagers.d.ts +1 -1
- package/esm/internals/utils/valueManagers.js +10 -18
- package/esm/managers/useDateManager.d.ts +3 -4
- package/esm/managers/useDateTimeManager.d.ts +3 -4
- package/esm/managers/useTimeManager.d.ts +3 -4
- package/esm/models/adapters.d.ts +2 -1
- package/esm/models/manager.d.ts +4 -5
- package/esm/validation/useValidation.d.ts +1 -1
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.js +6 -2
- package/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/internals/components/PickerProvider.d.ts +137 -6
- package/internals/components/PickerProvider.js +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/internals/hooks/useField/useField.js +7 -8
- package/internals/hooks/useField/useField.types.d.ts +46 -43
- package/internals/hooks/useField/useField.utils.js +4 -1
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/internals/hooks/useField/useFieldState.js +135 -82
- package/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
- package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
- package/internals/hooks/usePicker/index.d.ts +1 -3
- package/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/internals/hooks/usePicker/usePicker.js +278 -34
- package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/internals/index.d.ts +3 -6
- package/internals/models/manager.d.ts +108 -4
- package/internals/models/props/basePickerProps.d.ts +2 -2
- package/internals/models/props/time.d.ts +1 -1
- package/internals/utils/date-time-utils.d.ts +2 -2
- package/internals/utils/valueManagers.d.ts +1 -1
- package/internals/utils/valueManagers.js +10 -18
- package/managers/useDateManager.d.ts +3 -4
- package/managers/useDateTimeManager.d.ts +3 -4
- package/managers/useTimeManager.d.ts +3 -4
- package/models/adapters.d.ts +2 -1
- package/models/manager.d.ts +4 -5
- package/modern/DatePicker/shared.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/modern/DateTimePicker/shared.d.ts +18 -10
- package/modern/DateTimePicker/shared.js +23 -2
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/modern/PickersTextField/PickersTextField.js +3 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/modern/TimePicker/shared.d.ts +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.js +6 -2
- package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/modern/internals/components/PickerProvider.d.ts +137 -6
- package/modern/internals/components/PickerProvider.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/modern/internals/hooks/useField/useField.js +7 -8
- package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
- package/modern/internals/hooks/useField/useField.utils.js +4 -1
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/modern/internals/hooks/useField/useFieldState.js +136 -83
- package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/modern/internals/hooks/usePicker/index.d.ts +1 -3
- package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/modern/internals/hooks/usePicker/usePicker.js +276 -34
- package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/modern/internals/index.d.ts +3 -6
- package/modern/internals/models/manager.d.ts +108 -4
- package/modern/internals/models/props/basePickerProps.d.ts +2 -2
- package/modern/internals/models/props/time.d.ts +1 -1
- package/modern/internals/utils/date-time-utils.d.ts +2 -2
- package/modern/internals/utils/valueManagers.d.ts +1 -1
- package/modern/internals/utils/valueManagers.js +10 -18
- package/modern/managers/useDateManager.d.ts +3 -4
- package/modern/managers/useDateTimeManager.d.ts +3 -4
- package/modern/managers/useTimeManager.d.ts +3 -4
- package/modern/models/adapters.d.ts +2 -1
- package/modern/models/manager.d.ts +4 -5
- package/modern/validation/useValidation.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/validation/useValidation.d.ts +1 -1
- package/esm/internals/hooks/useOpenState.d.ts +0 -14
- package/esm/internals/hooks/useOpenState.js +0 -37
- package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
- package/internals/hooks/useOpenState.d.ts +0 -14
- package/internals/hooks/useOpenState.js +0 -46
- package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/internals/hooks/usePicker/usePickerProvider.js +0 -135
- package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
- package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/internals/hooks/usePicker/usePickerViews.js +0 -195
- package/modern/internals/hooks/useOpenState.d.ts +0 -14
- package/modern/internals/hooks/useOpenState.js +0 -37
- package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/modern/internals/hooks/usePicker/usePickerViews.js +0 -188
|
@@ -4,11 +4,15 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { useDateTimePickerDefaultizedProps } from "../DateTimePicker/shared.js";
|
|
7
|
-
import {
|
|
7
|
+
import { renderDigitalClockTimeView, renderMultiSectionDigitalClockTimeView } from "../timeViewRenderers/index.js";
|
|
8
8
|
import { renderDateViewCalendar } from "../dateViewRenderers/index.js";
|
|
9
9
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
10
10
|
import { useStaticPicker } from "../internals/hooks/useStaticPicker/index.js";
|
|
11
11
|
import { validateDateTime } from "../validation/index.js";
|
|
12
|
+
import { mergeSx } from "../internals/utils/utils.js";
|
|
13
|
+
import { multiSectionDigitalClockClasses, multiSectionDigitalClockSectionClasses } from "../MultiSectionDigitalClock/index.js";
|
|
14
|
+
import { DIALOG_WIDTH, VIEW_HEIGHT } from "../internals/constants/dimensions.js";
|
|
15
|
+
import { digitalClockClasses } from "../DigitalClock/index.js";
|
|
12
16
|
/**
|
|
13
17
|
* Demos:
|
|
14
18
|
*
|
|
@@ -23,19 +27,26 @@ const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTi
|
|
|
23
27
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiStaticDateTimePicker');
|
|
24
28
|
const displayStaticWrapperAs = defaultizedProps.displayStaticWrapperAs ?? 'mobile';
|
|
25
29
|
const ampmInClock = defaultizedProps.ampmInClock ?? displayStaticWrapperAs === 'desktop';
|
|
30
|
+
const renderTimeView = defaultizedProps.shouldRenderTimeInASingleColumn ? renderDigitalClockTimeView : renderMultiSectionDigitalClockTimeView;
|
|
26
31
|
const viewRenderers = _extends({
|
|
27
32
|
day: renderDateViewCalendar,
|
|
28
33
|
month: renderDateViewCalendar,
|
|
29
34
|
year: renderDateViewCalendar,
|
|
30
|
-
hours:
|
|
31
|
-
minutes:
|
|
32
|
-
seconds:
|
|
35
|
+
hours: renderTimeView,
|
|
36
|
+
minutes: renderTimeView,
|
|
37
|
+
seconds: renderTimeView,
|
|
38
|
+
meridiem: renderTimeView
|
|
33
39
|
}, defaultizedProps.viewRenderers);
|
|
34
40
|
|
|
41
|
+
// Need to avoid adding the `meridiem` view when unexpected renderer is specified
|
|
42
|
+
const shouldHoursRendererContainMeridiemView = viewRenderers.hours?.name === renderMultiSectionDigitalClockTimeView.name;
|
|
43
|
+
const views = !shouldHoursRendererContainMeridiemView ? defaultizedProps.views.filter(view => view !== 'meridiem') : defaultizedProps.views;
|
|
44
|
+
|
|
35
45
|
// Props with the default values specific to the static variant
|
|
36
46
|
const props = _extends({}, defaultizedProps, {
|
|
37
47
|
viewRenderers,
|
|
38
48
|
displayStaticWrapperAs,
|
|
49
|
+
views,
|
|
39
50
|
ampmInClock,
|
|
40
51
|
yearsPerRow: defaultizedProps.yearsPerRow ?? (displayStaticWrapperAs === 'mobile' ? 3 : 4),
|
|
41
52
|
slotProps: _extends({}, defaultizedProps.slotProps, {
|
|
@@ -46,7 +57,28 @@ const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTi
|
|
|
46
57
|
hidden: displayStaticWrapperAs === 'desktop',
|
|
47
58
|
ampmInClock
|
|
48
59
|
}, defaultizedProps.slotProps?.toolbar)
|
|
49
|
-
})
|
|
60
|
+
}),
|
|
61
|
+
sx: mergeSx([{
|
|
62
|
+
[`& .${multiSectionDigitalClockClasses.root}`]: {
|
|
63
|
+
width: DIALOG_WIDTH
|
|
64
|
+
},
|
|
65
|
+
[`& .${multiSectionDigitalClockSectionClasses.root}`]: {
|
|
66
|
+
flex: 1,
|
|
67
|
+
// account for the border on `MultiSectionDigitalClock`
|
|
68
|
+
maxHeight: VIEW_HEIGHT - 1,
|
|
69
|
+
[`.${multiSectionDigitalClockSectionClasses.item}`]: {
|
|
70
|
+
width: 'auto'
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[`& .${digitalClockClasses.root}`]: {
|
|
74
|
+
width: DIALOG_WIDTH,
|
|
75
|
+
maxHeight: VIEW_HEIGHT,
|
|
76
|
+
flex: 1,
|
|
77
|
+
[`.${digitalClockClasses.item}`]: {
|
|
78
|
+
justifyContent: 'center'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}], defaultizedProps?.sx)
|
|
50
82
|
});
|
|
51
83
|
const {
|
|
52
84
|
renderPicker
|
|
@@ -236,7 +268,7 @@ StaticDateTimePicker.propTypes = {
|
|
|
236
268
|
* Used when the component view is not controlled.
|
|
237
269
|
* Must be a valid option from `views` list.
|
|
238
270
|
*/
|
|
239
|
-
openTo: PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', 'year']),
|
|
271
|
+
openTo: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
240
272
|
/**
|
|
241
273
|
* Force rendering in particular orientation.
|
|
242
274
|
*/
|
|
@@ -302,6 +334,11 @@ StaticDateTimePicker.propTypes = {
|
|
|
302
334
|
* @default false
|
|
303
335
|
*/
|
|
304
336
|
showDaysOutsideCurrentMonth: PropTypes.bool,
|
|
337
|
+
/**
|
|
338
|
+
* If `true`, disabled digital clock items will not be rendered.
|
|
339
|
+
* @default false
|
|
340
|
+
*/
|
|
341
|
+
skipDisabled: PropTypes.bool,
|
|
305
342
|
/**
|
|
306
343
|
* The props used for each component slot.
|
|
307
344
|
* @default {}
|
|
@@ -316,6 +353,22 @@ StaticDateTimePicker.propTypes = {
|
|
|
316
353
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
317
354
|
*/
|
|
318
355
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
356
|
+
/**
|
|
357
|
+
* Amount of time options below or at which the single column time renderer is used.
|
|
358
|
+
* @default 24
|
|
359
|
+
*/
|
|
360
|
+
thresholdToRenderTimeInASingleColumn: PropTypes.number,
|
|
361
|
+
/**
|
|
362
|
+
* The time steps between two time unit options.
|
|
363
|
+
* For example, if `timeStep.minutes = 8`, then the available minute options will be `[0, 8, 16, 24, 32, 40, 48, 56]`.
|
|
364
|
+
* When single column time renderer is used, only `timeStep.minutes` will be used.
|
|
365
|
+
* @default{ hours: 1, minutes: 5, seconds: 5 }
|
|
366
|
+
*/
|
|
367
|
+
timeSteps: PropTypes.shape({
|
|
368
|
+
hours: PropTypes.number,
|
|
369
|
+
minutes: PropTypes.number,
|
|
370
|
+
seconds: PropTypes.number
|
|
371
|
+
}),
|
|
319
372
|
/**
|
|
320
373
|
* Choose which timezone to use for the value.
|
|
321
374
|
* Example: "default", "system", "UTC", "America/New_York".
|
|
@@ -334,7 +387,7 @@ StaticDateTimePicker.propTypes = {
|
|
|
334
387
|
* Used when the component view is controlled.
|
|
335
388
|
* Must be a valid option from `views` list.
|
|
336
389
|
*/
|
|
337
|
-
view: PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', 'year']),
|
|
390
|
+
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
338
391
|
/**
|
|
339
392
|
* Define custom view renderers for each section.
|
|
340
393
|
* If `null`, the section will only have field editing.
|
|
@@ -343,6 +396,7 @@ StaticDateTimePicker.propTypes = {
|
|
|
343
396
|
viewRenderers: PropTypes.shape({
|
|
344
397
|
day: PropTypes.func,
|
|
345
398
|
hours: PropTypes.func,
|
|
399
|
+
meridiem: PropTypes.func,
|
|
346
400
|
minutes: PropTypes.func,
|
|
347
401
|
month: PropTypes.func,
|
|
348
402
|
seconds: PropTypes.func,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { MakeOptional } from '@mui/x-internals/types';
|
|
2
2
|
import { BaseDateTimePickerProps, BaseDateTimePickerSlots, BaseDateTimePickerSlotProps } from "../DateTimePicker/shared.js";
|
|
3
3
|
import { StaticOnlyPickerProps, UseStaticPickerSlots, UseStaticPickerSlotProps } from "../internals/hooks/useStaticPicker/index.js";
|
|
4
|
-
import { DateOrTimeView } from "../models/index.js";
|
|
5
4
|
export interface StaticDateTimePickerSlots extends BaseDateTimePickerSlots, UseStaticPickerSlots {}
|
|
6
5
|
export interface StaticDateTimePickerSlotProps extends BaseDateTimePickerSlotProps, UseStaticPickerSlotProps {}
|
|
7
|
-
export interface StaticDateTimePickerProps extends BaseDateTimePickerProps
|
|
6
|
+
export interface StaticDateTimePickerProps extends BaseDateTimePickerProps, MakeOptional<StaticOnlyPickerProps, 'displayStaticWrapperAs'> {
|
|
8
7
|
/**
|
|
9
8
|
* Overridable component slots.
|
|
10
9
|
* @default {}
|
|
@@ -5,7 +5,7 @@ import { BasePickerInputProps } from "../internals/models/props/basePickerProps.
|
|
|
5
5
|
import { LocalizedComponent } from "../locales/utils/pickersLocaleTextApi.js";
|
|
6
6
|
import { TimePickerToolbarProps, ExportedTimePickerToolbarProps } from "./TimePickerToolbar.js";
|
|
7
7
|
import { TimeValidationError } from "../models/index.js";
|
|
8
|
-
import { PickerViewRendererLookup } from "../internals/hooks/usePicker/
|
|
8
|
+
import { PickerViewRendererLookup } from "../internals/hooks/usePicker/index.js";
|
|
9
9
|
import { TimeViewRendererProps } from "../timeViewRenderers/index.js";
|
|
10
10
|
import { BaseClockProps, ExportedBaseClockProps } from "../internals/models/props/time.js";
|
|
11
11
|
import { PickerValue, TimeViewWithMeridiem } from "../internals/models/index.js";
|
package/esm/index.js
CHANGED
|
@@ -154,7 +154,9 @@ export function PickerFieldUI(props) {
|
|
|
154
154
|
disabled: triggerStatus === 'disabled',
|
|
155
155
|
onClick: handleClickOpeningButton,
|
|
156
156
|
'aria-label': openPickerAriaLabel,
|
|
157
|
-
edge:
|
|
157
|
+
edge:
|
|
158
|
+
// open button is always rendered at the edge
|
|
159
|
+
textFieldProps.variant !== 'standard' ? openPickerButtonPosition : false
|
|
158
160
|
},
|
|
159
161
|
ownerState
|
|
160
162
|
}),
|
|
@@ -176,7 +178,9 @@ export function PickerFieldUI(props) {
|
|
|
176
178
|
tabIndex: -1,
|
|
177
179
|
onClick: onClear,
|
|
178
180
|
disabled: fieldResponse.disabled || fieldResponse.readOnly,
|
|
179
|
-
edge:
|
|
181
|
+
edge:
|
|
182
|
+
// clear button can only be at the edge if it's position differs from the open button
|
|
183
|
+
textFieldProps.variant !== 'standard' && clearButtonPosition !== openPickerButtonPosition ? clearButtonPosition : false
|
|
180
184
|
},
|
|
181
185
|
ownerState
|
|
182
186
|
}),
|
|
@@ -219,7 +219,7 @@ export function PickerPopper(inProps) {
|
|
|
219
219
|
} = usePickerContext();
|
|
220
220
|
const {
|
|
221
221
|
dismissViews,
|
|
222
|
-
|
|
222
|
+
getCurrentViewMode,
|
|
223
223
|
viewContainerRole
|
|
224
224
|
} = usePickerPrivateContext();
|
|
225
225
|
React.useEffect(() => {
|
|
@@ -235,7 +235,7 @@ export function PickerPopper(inProps) {
|
|
|
235
235
|
}, [dismissViews, open]);
|
|
236
236
|
const lastFocusedElementRef = React.useRef(null);
|
|
237
237
|
React.useEffect(() => {
|
|
238
|
-
if (viewContainerRole === 'tooltip' ||
|
|
238
|
+
if (viewContainerRole === 'tooltip' || getCurrentViewMode() === 'field') {
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
if (open) {
|
|
@@ -249,7 +249,7 @@ export function PickerPopper(inProps) {
|
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
}, [open, viewContainerRole,
|
|
252
|
+
}, [open, viewContainerRole, getCurrentViewMode]);
|
|
253
253
|
const classes = useUtilityClasses(classesProp);
|
|
254
254
|
const {
|
|
255
255
|
ownerState: pickerOwnerState,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { SxProps } from '@mui/system';
|
|
3
3
|
import { Theme } from '@mui/material/styles';
|
|
4
|
-
import { PickerOwnerState } from "../../models/index.js";
|
|
4
|
+
import { PickerChangeImportance, PickerOwnerState, PickersTimezone } from "../../models/index.js";
|
|
5
5
|
import { PickersInputLocaleText } from "../../locales/index.js";
|
|
6
6
|
import { DateOrTimeViewWithMeridiem, PickerOrientation, PickerValidValue, PickerVariant } from "../models/index.js";
|
|
7
|
-
import type { UsePickerValueActionsContextValue, UsePickerValueContextValue, UsePickerValuePrivateContextValue } from '../hooks/usePicker/usePickerValue.types';
|
|
8
|
-
import { UsePickerViewsActionsContextValue, UsePickerViewsContextValue, UsePickerViewsPrivateContextValue } from "../hooks/usePicker/usePickerViews.js";
|
|
9
7
|
import { PickerFieldPrivateContextValue } from "../hooks/useNullableFieldPrivateContext.js";
|
|
8
|
+
import type { PickersShortcutsItemContext } from '../../PickersShortcuts';
|
|
10
9
|
export declare const PickerActionsContext: React.Context<PickerActionsContextValue<any, any, any> | null>;
|
|
11
10
|
export declare const PickerPrivateContext: React.Context<PickerPrivateContextValue>;
|
|
12
11
|
/**
|
|
@@ -26,7 +25,24 @@ export interface PickerProviderProps<TValue extends PickerValidValue> {
|
|
|
26
25
|
localeText: PickersInputLocaleText | undefined;
|
|
27
26
|
children: React.ReactNode;
|
|
28
27
|
}
|
|
29
|
-
export interface PickerContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends
|
|
28
|
+
export interface PickerContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends PickerActionsContextValue<TValue, TView, TError> {
|
|
29
|
+
/**
|
|
30
|
+
* The current value of the picker.
|
|
31
|
+
*/
|
|
32
|
+
value: TValue;
|
|
33
|
+
/**
|
|
34
|
+
* The timezone to use when rendering the dates.
|
|
35
|
+
* If a `timezone` prop is provided, it will be used.
|
|
36
|
+
* If the `value` prop contains a valid date, its timezone will be used.
|
|
37
|
+
* If no `value` prop is provided, but the `defaultValue` contains a valid date, its timezone will be used.
|
|
38
|
+
* If no `value` or `defaultValue` is provided, but the `referenceDate` is provided, its timezone will be used.
|
|
39
|
+
* Otherwise, the timezone will be the default one of your date library.
|
|
40
|
+
*/
|
|
41
|
+
timezone: PickersTimezone;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the picker is open.
|
|
44
|
+
*/
|
|
45
|
+
open: boolean;
|
|
30
46
|
/**
|
|
31
47
|
* Whether the picker is disabled.
|
|
32
48
|
*/
|
|
@@ -41,6 +57,25 @@ export interface PickerContextValue<TValue extends PickerValidValue, TView exten
|
|
|
41
57
|
* If the picker does not have a field (if it is a static picker) or is not open, the view should be focused.
|
|
42
58
|
*/
|
|
43
59
|
autoFocus: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The views that the picker has to render.
|
|
62
|
+
* It is equal to the picker `views` prop—if defined.
|
|
63
|
+
* Otherwise, a default set of views is provided based on the component you are using:
|
|
64
|
+
* - Date Pickers: ['year', 'day']
|
|
65
|
+
* - Time Pickers: ['hours', 'minutes']
|
|
66
|
+
* - Date Time Pickers: ['year', 'day', 'hours', 'minutes']
|
|
67
|
+
* - Date Range Pickers: ['day']
|
|
68
|
+
* - Date Time Range Pickers: ['day', 'hours', 'minutes']
|
|
69
|
+
*/
|
|
70
|
+
views: readonly TView[];
|
|
71
|
+
/**
|
|
72
|
+
* The currently rendered view.
|
|
73
|
+
*/
|
|
74
|
+
view: TView | null;
|
|
75
|
+
/**
|
|
76
|
+
* The view showed when first opening the picker.
|
|
77
|
+
*/
|
|
78
|
+
initialView: TView | null;
|
|
44
79
|
/**
|
|
45
80
|
* The responsive variant of the picker.
|
|
46
81
|
* It is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
|
|
@@ -122,8 +157,85 @@ export interface PickerContextValue<TValue extends PickerValidValue, TView exten
|
|
|
122
157
|
*/
|
|
123
158
|
rootRef: React.ForwardedRef<HTMLDivElement> | undefined;
|
|
124
159
|
}
|
|
125
|
-
export interface PickerActionsContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError = string | null>
|
|
126
|
-
|
|
160
|
+
export interface PickerActionsContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError = string | null> {
|
|
161
|
+
/**
|
|
162
|
+
* Set the current value of the picker.
|
|
163
|
+
* @param {TValue} value The new value of the picker.
|
|
164
|
+
* @param {SetValueActionOptions<TError>} options The options to customize the behavior of this update.
|
|
165
|
+
*/
|
|
166
|
+
setValue: (value: TValue, options?: SetValueActionOptions<TError>) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Set the current open state of the Picker.
|
|
169
|
+
* It can be a function that will receive the current open state as parameter.
|
|
170
|
+
* ```ts
|
|
171
|
+
* setOpen(true); // Opens the picker.
|
|
172
|
+
* setOpen(false); // Closes the picker.
|
|
173
|
+
* setOpen((prevOpen) => !prevOpen); // Toggles the open state.
|
|
174
|
+
* ```
|
|
175
|
+
* @param {React.SetStateAction<boolean>} action The new open state of the Picker.
|
|
176
|
+
*/
|
|
177
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
178
|
+
/**
|
|
179
|
+
* Set the current view.
|
|
180
|
+
* @template TView
|
|
181
|
+
* @param {TView} view The view to render
|
|
182
|
+
*/
|
|
183
|
+
setView: (view: TView) => void;
|
|
184
|
+
/**
|
|
185
|
+
* Set the current value of the picker to be empty.
|
|
186
|
+
* The value will be `null` on single pickers and `[null, null]` on range pickers.
|
|
187
|
+
*/
|
|
188
|
+
clearValue: () => void;
|
|
189
|
+
/**
|
|
190
|
+
* Set the current value of the picker to be the current date.
|
|
191
|
+
* The value will be `today` on single pickers and `[today, today]` on range pickers.
|
|
192
|
+
* With `today` being the current date, with its time set to `00:00:00` on Date Pickers and its time set to the current time on Time and Date Pickers.
|
|
193
|
+
*/
|
|
194
|
+
setValueToToday: () => void;
|
|
195
|
+
/**
|
|
196
|
+
* Accept the current value of the picker.
|
|
197
|
+
* Will call `onAccept` if defined.
|
|
198
|
+
* If the picker is re-opened, this value will be the one used to initialize the views.
|
|
199
|
+
*/
|
|
200
|
+
acceptValueChanges: () => void;
|
|
201
|
+
/**
|
|
202
|
+
* Cancel the changes made to the current value of the picker.
|
|
203
|
+
* The value will be reset to the last accepted value.
|
|
204
|
+
*/
|
|
205
|
+
cancelValueChanges: () => void;
|
|
206
|
+
}
|
|
207
|
+
export interface SetValueActionOptions<TError = string | null> {
|
|
208
|
+
/**
|
|
209
|
+
* The importance of the change when picking a value:
|
|
210
|
+
* - "accept": fires `onChange`, fires `onAccept` and closes the picker.
|
|
211
|
+
* - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
|
|
212
|
+
* @default "accept"
|
|
213
|
+
*/
|
|
214
|
+
changeImportance?: PickerChangeImportance;
|
|
215
|
+
/**
|
|
216
|
+
* The validation error associated to the current value.
|
|
217
|
+
* If not defined, the validation will be computed by the picker.
|
|
218
|
+
*/
|
|
219
|
+
validationError?: TError;
|
|
220
|
+
/**
|
|
221
|
+
* The shortcut that triggered this change.
|
|
222
|
+
* It should not be defined if the change does not come from a shortcut.
|
|
223
|
+
*/
|
|
224
|
+
shortcut?: PickersShortcutsItemContext;
|
|
225
|
+
/**
|
|
226
|
+
* Whether the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
|
|
227
|
+
* If `true`, the `onChange` and `onAccept` callback will only be fired if the value has been modified (and is not equal to the last published value).
|
|
228
|
+
* If `false`, the `onChange` and `onAccept` callback will be fired when the value has never been modified (`onAccept` only if `changeImportance` is set to "accept").
|
|
229
|
+
* @default false
|
|
230
|
+
*/
|
|
231
|
+
skipPublicationIfPristine?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Whether the picker should close.
|
|
234
|
+
* @default changeImportance === "accept"
|
|
235
|
+
*/
|
|
236
|
+
shouldClose?: boolean;
|
|
237
|
+
}
|
|
238
|
+
export interface PickerPrivateContextValue {
|
|
127
239
|
/**
|
|
128
240
|
* The ownerState of the picker.
|
|
129
241
|
*/
|
|
@@ -137,4 +249,23 @@ export interface PickerPrivateContextValue extends UsePickerValuePrivateContextV
|
|
|
137
249
|
* The id of the label element.
|
|
138
250
|
*/
|
|
139
251
|
labelId: string | undefined;
|
|
252
|
+
dismissViews: () => void;
|
|
253
|
+
/**
|
|
254
|
+
* Whether at least one view has an UI (it has a view renderer associated).
|
|
255
|
+
*/
|
|
256
|
+
hasUIView: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Return the mode of the current view.
|
|
259
|
+
* @returns {boolean} The mode of the current view.
|
|
260
|
+
*/
|
|
261
|
+
getCurrentViewMode: () => 'UI' | 'field';
|
|
262
|
+
/**
|
|
263
|
+
* The aria role associated with the view container.
|
|
264
|
+
* It is equal to "dialog" when the view is rendered inside a `@mui/material/Dialog`.
|
|
265
|
+
* It is equal to "dialog" when the view is rendered inside a `@mui/material/Popper` and the focus is trapped inside the view.
|
|
266
|
+
* It is equal to "tooltip" when the view is rendered inside a `@mui/material/Popper` and the focus remains inside the field.
|
|
267
|
+
* It is always equal to null if the picker does not have a field (static pickers).
|
|
268
|
+
* It is always equal to null if the component you are accessing the context from is not wrapped by a picker.
|
|
269
|
+
*/
|
|
270
|
+
viewContainerRole: 'dialog' | 'tooltip' | null;
|
|
140
271
|
}
|
|
@@ -2,14 +2,11 @@ import * as React from 'react';
|
|
|
2
2
|
import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
3
3
|
import { BasePickerProps } from "../../models/props/basePickerProps.js";
|
|
4
4
|
import { PickerPopperSlots, PickerPopperSlotProps } from "../../components/PickerPopper/PickerPopper.js";
|
|
5
|
-
import {
|
|
5
|
+
import { UsePickerParameters, UsePickerNonStaticProps, UsePickerProps } from "../usePicker/index.js";
|
|
6
6
|
import { PickerFieldSlotProps, PickerOwnerState } from "../../../models/index.js";
|
|
7
7
|
import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from "../../../PickersLayout/PickersLayout.types.js";
|
|
8
|
-
import { UsePickerValueNonStaticProps } from "../usePicker/usePickerValue.types.js";
|
|
9
|
-
import { UsePickerViewsProps } from "../usePicker/usePickerViews.js";
|
|
10
8
|
import { DateOrTimeViewWithMeridiem, PickerValue } from "../../models/index.js";
|
|
11
9
|
import { PickerFieldUISlotsFromContext, PickerFieldUISlotPropsFromContext } from "../../components/PickerFieldUI.js";
|
|
12
|
-
import { UsePickerProviderNonStaticProps } from "../usePicker/usePickerProvider.js";
|
|
13
10
|
export interface UseDesktopPickerSlots extends Pick<PickerPopperSlots, 'desktopPaper' | 'desktopTransition' | 'desktopTrapFocus' | 'popper'>, ExportedPickersLayoutSlots<PickerValue>, PickerFieldUISlotsFromContext {
|
|
14
11
|
/**
|
|
15
12
|
* Component used to enter the date with the keyboard.
|
|
@@ -20,14 +17,14 @@ export interface ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStru
|
|
|
20
17
|
field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
|
|
21
18
|
}
|
|
22
19
|
export interface UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {}
|
|
23
|
-
export interface DesktopOnlyPickerProps extends
|
|
20
|
+
export interface DesktopOnlyPickerProps extends UsePickerNonStaticProps {
|
|
24
21
|
/**
|
|
25
22
|
* If `true`, the `input` element is focused during the first mount.
|
|
26
23
|
* @default false
|
|
27
24
|
*/
|
|
28
25
|
autoFocus?: boolean;
|
|
29
26
|
}
|
|
30
|
-
export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends
|
|
27
|
+
export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerProps<PickerValue, TView, TError, any>> extends BasePickerProps<PickerValue, any, TError, TExternalProps>, MakeRequired<DesktopOnlyPickerProps, 'format'> {
|
|
31
28
|
/**
|
|
32
29
|
* Overridable component slots.
|
|
33
30
|
* @default {}
|
|
@@ -39,6 +36,6 @@ export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem,
|
|
|
39
36
|
*/
|
|
40
37
|
slotProps?: UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>;
|
|
41
38
|
}
|
|
42
|
-
export interface UseDesktopPickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseDesktopPickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<
|
|
39
|
+
export interface UseDesktopPickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseDesktopPickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParameters<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor' | 'ref'> {
|
|
43
40
|
props: TExternalProps;
|
|
44
41
|
}
|
|
@@ -29,7 +29,6 @@ export const useField = params => {
|
|
|
29
29
|
onClear
|
|
30
30
|
},
|
|
31
31
|
fieldValueManager,
|
|
32
|
-
valueManager,
|
|
33
32
|
validator,
|
|
34
33
|
getOpenPickerButtonAriaLabel: getOpenDialogAriaText
|
|
35
34
|
} = params;
|
|
@@ -37,6 +36,7 @@ export const useField = params => {
|
|
|
37
36
|
const stateResponse = useFieldState(params);
|
|
38
37
|
const {
|
|
39
38
|
state,
|
|
39
|
+
value,
|
|
40
40
|
activeSectionIndex,
|
|
41
41
|
parsedSelectedSections,
|
|
42
42
|
setSelectedSections,
|
|
@@ -59,7 +59,7 @@ export const useField = params => {
|
|
|
59
59
|
const {
|
|
60
60
|
resetCharacterQuery
|
|
61
61
|
} = characterEditingResponse;
|
|
62
|
-
const areAllSectionsEmpty =
|
|
62
|
+
const areAllSectionsEmpty = React.useMemo(() => state.sections.every(section => section.value === ''), [state.sections]);
|
|
63
63
|
const useFieldTextField = enableAccessibleFieldDOMStructure ? useFieldV7TextField : useFieldV6TextField;
|
|
64
64
|
const sectionOrder = React.useMemo(() => getSectionOrder(state.sections, isRtl && !enableAccessibleFieldDOMStructure), [state.sections, isRtl, enableAccessibleFieldDOMStructure]);
|
|
65
65
|
const {
|
|
@@ -149,12 +149,11 @@ export const useField = params => {
|
|
|
149
149
|
setSelectedSections(activeSectionIndex);
|
|
150
150
|
}
|
|
151
151
|
const activeSection = state.sections[activeSectionIndex];
|
|
152
|
-
const
|
|
153
|
-
const newSectionValue = adjustSectionValue(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, activeDateManager.date, {
|
|
152
|
+
const newSectionValue = adjustSectionValue(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
|
|
154
153
|
minutesStep
|
|
155
154
|
});
|
|
156
155
|
updateSectionValue({
|
|
157
|
-
activeSection,
|
|
156
|
+
section: activeSection,
|
|
158
157
|
newSectionValue,
|
|
159
158
|
shouldGoToNextSection: false
|
|
160
159
|
});
|
|
@@ -171,7 +170,7 @@ export const useField = params => {
|
|
|
171
170
|
props: internalProps,
|
|
172
171
|
validator,
|
|
173
172
|
timezone,
|
|
174
|
-
value
|
|
173
|
+
value,
|
|
175
174
|
onError: internalProps.onError
|
|
176
175
|
});
|
|
177
176
|
const inputError = React.useMemo(() => {
|
|
@@ -225,8 +224,8 @@ export const useField = params => {
|
|
|
225
224
|
};
|
|
226
225
|
const localizationContext = useLocalizationContext();
|
|
227
226
|
const openPickerAriaLabel = React.useMemo(() => getOpenDialogAriaText(_extends({}, localizationContext, {
|
|
228
|
-
value
|
|
229
|
-
})), [getOpenDialogAriaText,
|
|
227
|
+
value
|
|
228
|
+
})), [getOpenDialogAriaText, value, localizationContext]);
|
|
230
229
|
const commonAdditionalProps = {
|
|
231
230
|
disabled,
|
|
232
231
|
readOnly,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { FieldSectionType, FieldSection, FieldSelectedSections, MuiPickersAdapter, TimezoneProps, FieldSectionContentType, PickerValidDate, FieldRef, OnErrorProps, InferError, InferFieldSection, PickerValueType } from "../../../models/index.js";
|
|
3
|
-
import type { PickerValueManager } from '
|
|
3
|
+
import type { PickerValueManager } from '../../models';
|
|
4
4
|
import type { Validator } from '../../../validation';
|
|
5
5
|
import type { UseFieldStateResponse } from './useFieldState';
|
|
6
6
|
import type { UseFieldCharacterEditingResponse } from './useFieldCharacterEditing';
|
|
@@ -165,47 +165,17 @@ export type FieldChangeHandler<TValue extends PickerValidValue, TError> = (value
|
|
|
165
165
|
export interface FieldChangeHandlerContext<TError> {
|
|
166
166
|
validationError: TError;
|
|
167
167
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Object used to access and update the active date (i.e: the date containing the active section).
|
|
170
|
-
* Mainly useful in the range fields where we need to update the date containing the active section without impacting the other one.
|
|
171
|
-
*/
|
|
172
|
-
interface FieldActiveDateManager<TValue extends PickerValidValue> {
|
|
173
|
-
/**
|
|
174
|
-
* Active date from `state.value`.
|
|
175
|
-
*/
|
|
176
|
-
date: PickerValidDate | null;
|
|
177
|
-
/**
|
|
178
|
-
* Active date from the `state.referenceValue`.
|
|
179
|
-
*/
|
|
180
|
-
referenceDate: PickerValidDate;
|
|
181
|
-
/**
|
|
182
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
183
|
-
* @param {InferFieldSection<TValue>[]} sections The sections of the full value.
|
|
184
|
-
* @returns {InferFieldSection<TValue>[]} The sections of the active date.
|
|
185
|
-
* Get the sections of the active date.
|
|
186
|
-
*/
|
|
187
|
-
getSections: (sections: InferFieldSection<TValue>[]) => InferFieldSection<TValue>[];
|
|
188
|
-
/**
|
|
189
|
-
* Creates the new value and reference value based on the new active date and the current state.
|
|
190
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
191
|
-
* @param {PickerValidDate | null} newActiveDate The new value of the date containing the active section.
|
|
192
|
-
* @returns {Pick<UseFieldState<TValue>, 'value' | 'referenceValue'>} The new value and reference value to publish and store in the state.
|
|
193
|
-
*/
|
|
194
|
-
getNewValuesFromNewActiveDate: (newActiveDate: PickerValidDate | null) => Pick<UseFieldState<TValue>, 'value' | 'referenceValue'>;
|
|
195
|
-
}
|
|
196
168
|
export type FieldParsedSelectedSections = number | 'all' | null;
|
|
197
169
|
export interface FieldValueManager<TValue extends PickerValidValue> {
|
|
198
170
|
/**
|
|
199
171
|
* Creates the section list from the current value.
|
|
200
172
|
* The `prevSections` are used on the range fields to avoid losing the sections of a partially filled date when editing the other date.
|
|
201
173
|
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
202
|
-
* @param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
203
174
|
* @param {TValue} value The current value to generate sections from.
|
|
204
|
-
* @param {
|
|
205
|
-
* @param {(date: PickerValidDate) => FieldSection[]} getSectionsFromDate Returns the sections of the given date.
|
|
175
|
+
* @param {(date: PickerValidDate | null) => FieldSection[]} getSectionsFromDate Returns the sections of the given date.
|
|
206
176
|
* @returns {InferFieldSection<TValue>[]} The new section list.
|
|
207
177
|
*/
|
|
208
|
-
getSectionsFromValue: (
|
|
178
|
+
getSectionsFromValue: (value: TValue, getSectionsFromDate: (date: PickerValidDate | null) => FieldSection[]) => InferFieldSection<TValue>[];
|
|
209
179
|
/**
|
|
210
180
|
* Creates the string value to render in the input based on the current section list.
|
|
211
181
|
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
@@ -222,15 +192,6 @@ export interface FieldValueManager<TValue extends PickerValidValue> {
|
|
|
222
192
|
* @returns {string} The string value to render in the input.
|
|
223
193
|
*/
|
|
224
194
|
getV7HiddenInputValueFromSections: (sections: InferFieldSection<TValue>[]) => string;
|
|
225
|
-
/**
|
|
226
|
-
* Returns the manager of the active date.
|
|
227
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
228
|
-
* @param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
229
|
-
* @param {UseFieldState<TValue>} state The current state of the field.
|
|
230
|
-
* @param {InferFieldSection<TValue>} activeSection The active section.
|
|
231
|
-
* @returns {FieldActiveDateManager<TValue>} The manager of the active date.
|
|
232
|
-
*/
|
|
233
|
-
getActiveDateManager: (utils: MuiPickersAdapter, state: UseFieldState<TValue>, activeSection: InferFieldSection<TValue>) => FieldActiveDateManager<TValue>;
|
|
234
195
|
/**
|
|
235
196
|
* Parses a string version (most of the time coming from the input).
|
|
236
197
|
* This method should only be used when the change does not come from a single section.
|
|
@@ -251,9 +212,51 @@ export interface FieldValueManager<TValue extends PickerValidValue> {
|
|
|
251
212
|
* @returns {TValue} The new reference value with no invalid date.
|
|
252
213
|
*/
|
|
253
214
|
updateReferenceValue: (utils: MuiPickersAdapter, value: TValue, prevReferenceValue: InferNonNullablePickerValue<TValue>) => InferNonNullablePickerValue<TValue>;
|
|
215
|
+
/**
|
|
216
|
+
* Extract from the given value the date that contains the given section.
|
|
217
|
+
* @param {TValue} value The value to extract the date from.
|
|
218
|
+
* @param {InferFieldSection<TValue>} section The section to get the date from.
|
|
219
|
+
* @returns {PickerValidDate | null} The date that contains the section.
|
|
220
|
+
*/
|
|
221
|
+
getDateFromSection: (value: TValue, section: InferFieldSection<TValue>) => PickerValidDate | null;
|
|
222
|
+
/**
|
|
223
|
+
* Get the sections of the date that contains the given section.
|
|
224
|
+
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
225
|
+
* @param {InferFieldSection<TValue>[]} sections The sections of the full value.
|
|
226
|
+
* @param {InferFieldSection<TValue>} section A section of the date from which we want to get all the sections.
|
|
227
|
+
* @returns {InferFieldSection<TValue>[]} The sections of the date that contains the section.
|
|
228
|
+
*/
|
|
229
|
+
getDateSectionsFromValue: (sections: InferFieldSection<TValue>[], section: InferFieldSection<TValue>) => InferFieldSection<TValue>[];
|
|
230
|
+
/**
|
|
231
|
+
* Creates a new value based on the provided date and the current value.
|
|
232
|
+
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
233
|
+
* @param {TValue} value The value to update the date in.
|
|
234
|
+
* @param {InferFieldSection<TValue>} section A section of the date we want to update in the value.
|
|
235
|
+
* @param {PickerValidDate | null} date The date that contains the section.
|
|
236
|
+
* @returns {TValue} The updated value.
|
|
237
|
+
*/
|
|
238
|
+
updateDateInValue: (value: TValue, section: InferFieldSection<TValue>, date: PickerValidDate | null) => TValue;
|
|
239
|
+
/**
|
|
240
|
+
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
241
|
+
* @param {InferFieldSection<TValue>[]} sections The sections of the full value.
|
|
242
|
+
* @param {InferFieldSection<TValue>} section A section of the date from which we want to clear all the sections.
|
|
243
|
+
* @returns {InferFieldSection<TValue>[]} The sections of the full value with all the sections of the target date cleared.
|
|
244
|
+
*/
|
|
245
|
+
clearDateSections: (sections: InferFieldSection<TValue>[], section: InferFieldSection<TValue>) => InferFieldSection<TValue>[];
|
|
254
246
|
}
|
|
255
247
|
export interface UseFieldState<TValue extends PickerValidValue> {
|
|
256
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Last value returned by `useControlledValueWithTimezone`.
|
|
250
|
+
*/
|
|
251
|
+
lastValue: TValue | undefined;
|
|
252
|
+
/**
|
|
253
|
+
* Last value of the parameters used to generate the sections.
|
|
254
|
+
*/
|
|
255
|
+
lastSectionsDependencies: {
|
|
256
|
+
format: string;
|
|
257
|
+
isRtl: boolean;
|
|
258
|
+
locale: any;
|
|
259
|
+
};
|
|
257
260
|
/**
|
|
258
261
|
* Non-nullable value used to keep trace of the timezone and the date parts not present in the format.
|
|
259
262
|
* It is updated whenever we have a valid date (for the range picker we update only the portion of the range that is valid).
|
|
@@ -447,8 +447,11 @@ const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTran
|
|
|
447
447
|
}
|
|
448
448
|
case 'weekDay':
|
|
449
449
|
{
|
|
450
|
+
let dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
|
|
451
|
+
if (section.hasLeadingZerosInInput) {
|
|
452
|
+
dayInWeekStrOfActiveDate = cleanLeadingZeros(dayInWeekStrOfActiveDate, section.maxLength);
|
|
453
|
+
}
|
|
450
454
|
const formattedDaysInWeek = getDaysInWeekStr(utils, section.format);
|
|
451
|
-
const dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
|
|
452
455
|
const dayInWeekOfActiveDate = formattedDaysInWeek.indexOf(dayInWeekStrOfActiveDate);
|
|
453
456
|
const dayInWeekOfNewSectionValue = formattedDaysInWeek.indexOf(section.value);
|
|
454
457
|
const diff = dayInWeekOfNewSectionValue - dayInWeekOfActiveDate;
|