@mui/x-date-pickers 8.0.0-beta.0 → 8.0.0-beta.1
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 +77 -0
- package/DateCalendar/DayCalendar.d.ts +3 -7
- package/DateCalendar/DayCalendar.js +16 -8
- package/DateCalendar/index.d.ts +0 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +2 -16
- package/DatePicker/DatePicker.js +1 -0
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +2 -16
- package/DateTimePicker/DateTimePicker.js +1 -0
- package/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/MobileDatePicker/MobileDatePicker.js +1 -0
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/MobileTimePicker/MobileTimePicker.js +1 -0
- package/PickersDay/PickersDay.d.ts +1 -72
- package/PickersDay/PickersDay.js +30 -28
- package/PickersDay/PickersDay.types.d.ts +114 -0
- package/PickersDay/PickersDay.types.js +5 -0
- package/PickersDay/index.d.ts +1 -1
- package/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/PickersDay/usePickerDayOwnerState.js +40 -0
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +2 -16
- package/TimePicker/TimePicker.js +1 -0
- package/esm/DateCalendar/DayCalendar.d.ts +3 -7
- package/esm/DateCalendar/DayCalendar.js +16 -8
- package/esm/DateCalendar/index.d.ts +0 -1
- package/esm/DateField/useDateField.d.ts +1 -1
- package/esm/DateField/useDateField.js +3 -17
- package/esm/DatePicker/DatePicker.js +1 -0
- package/esm/DateTimeField/useDateTimeField.d.ts +1 -1
- package/esm/DateTimeField/useDateTimeField.js +3 -17
- package/esm/DateTimePicker/DateTimePicker.js +1 -0
- package/esm/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/esm/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/esm/MobileDatePicker/MobileDatePicker.js +1 -0
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/esm/MobileTimePicker/MobileTimePicker.js +1 -0
- package/esm/PickersDay/PickersDay.d.ts +1 -72
- package/esm/PickersDay/PickersDay.js +30 -28
- package/esm/PickersDay/PickersDay.types.d.ts +114 -0
- package/esm/PickersDay/PickersDay.types.js +1 -0
- package/esm/PickersDay/index.d.ts +1 -1
- package/esm/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/esm/PickersDay/usePickerDayOwnerState.js +32 -0
- package/esm/TimeField/useTimeField.d.ts +1 -1
- package/esm/TimeField/useTimeField.js +3 -17
- package/esm/TimePicker/TimePicker.js +1 -0
- package/esm/hooks/useSplitFieldProps.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.d.ts +5 -5
- package/esm/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/esm/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/esm/internals/hooks/useField/index.d.ts +1 -1
- package/esm/internals/hooks/useField/useField.d.ts +2 -4
- package/esm/internals/hooks/useField/useField.js +5 -229
- package/esm/internals/hooks/useField/useField.types.d.ts +48 -68
- package/esm/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/esm/internals/hooks/useField/useField.utils.js +7 -92
- package/esm/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +204 -0
- package/esm/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/esm/internals/hooks/useField/useFieldState.js +103 -30
- package/esm/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/esm/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/esm/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/esm/internals/hooks/useField/useFieldV7TextField.js +217 -153
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/esm/internals/index.d.ts +2 -1
- package/esm/internals/index.js +1 -0
- package/esm/managers/useDateManager.js +3 -3
- package/esm/managers/useDateTimeManager.js +3 -3
- package/esm/managers/useTimeManager.js +3 -3
- package/esm/models/fields.d.ts +2 -2
- package/esm/models/manager.d.ts +3 -2
- package/hooks/useSplitFieldProps.d.ts +1 -1
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.d.ts +5 -5
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/internals/hooks/useField/index.d.ts +1 -1
- package/internals/hooks/useField/useField.d.ts +2 -4
- package/internals/hooks/useField/useField.js +5 -231
- package/internals/hooks/useField/useField.types.d.ts +48 -68
- package/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/internals/hooks/useField/useField.utils.js +8 -94
- package/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/internals/hooks/useField/useFieldCharacterEditing.js +41 -59
- package/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/internals/hooks/useField/useFieldRootHandleKeyDown.js +210 -0
- package/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/internals/hooks/useField/useFieldState.js +102 -29
- package/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/internals/hooks/useField/useFieldV7TextField.js +218 -154
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/internals/index.d.ts +2 -1
- package/internals/index.js +7 -0
- package/managers/useDateManager.js +3 -3
- package/managers/useDateTimeManager.js +3 -3
- package/managers/useTimeManager.js +3 -3
- package/models/fields.d.ts +2 -2
- package/models/manager.d.ts +3 -2
- package/modern/DateCalendar/DayCalendar.d.ts +3 -7
- package/modern/DateCalendar/DayCalendar.js +16 -8
- package/modern/DateCalendar/index.d.ts +0 -1
- package/modern/DateField/useDateField.d.ts +1 -1
- package/modern/DateField/useDateField.js +3 -17
- package/modern/DatePicker/DatePicker.js +1 -0
- package/modern/DateTimeField/useDateTimeField.d.ts +1 -1
- package/modern/DateTimeField/useDateTimeField.js +3 -17
- package/modern/DateTimePicker/DateTimePicker.js +1 -0
- package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/modern/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +1 -0
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/modern/MobileTimePicker/MobileTimePicker.js +1 -0
- package/modern/PickersDay/PickersDay.d.ts +1 -72
- package/modern/PickersDay/PickersDay.js +30 -28
- package/modern/PickersDay/PickersDay.types.d.ts +114 -0
- package/modern/PickersDay/PickersDay.types.js +1 -0
- package/modern/PickersDay/index.d.ts +1 -1
- package/modern/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/modern/PickersDay/usePickerDayOwnerState.js +32 -0
- package/modern/TimeField/useTimeField.d.ts +1 -1
- package/modern/TimeField/useTimeField.js +3 -17
- package/modern/TimePicker/TimePicker.js +1 -0
- package/modern/hooks/useSplitFieldProps.d.ts +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.d.ts +5 -5
- package/modern/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/modern/internals/hooks/useField/index.d.ts +1 -1
- package/modern/internals/hooks/useField/useField.d.ts +2 -4
- package/modern/internals/hooks/useField/useField.js +5 -229
- package/modern/internals/hooks/useField/useField.types.d.ts +48 -68
- package/modern/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/modern/internals/hooks/useField/useField.utils.js +7 -92
- package/modern/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
- package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.js +204 -0
- package/modern/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/modern/internals/hooks/useField/useFieldState.js +103 -30
- package/modern/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/modern/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/modern/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/modern/internals/hooks/useField/useFieldV7TextField.js +217 -153
- package/modern/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/modern/internals/index.d.ts +2 -1
- package/modern/internals/index.js +1 -0
- package/modern/managers/useDateManager.js +3 -3
- package/modern/managers/useDateTimeManager.js +3 -3
- package/modern/managers/useTimeManager.js +3 -3
- package/modern/models/fields.d.ts +2 -2
- package/modern/models/manager.d.ts +3 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ButtonBaseProps } from '@mui/material/ButtonBase';
|
|
2
|
+
import { PickerOwnerState, PickerValidDate } from "../models/pickers.js";
|
|
3
|
+
import { ExtendMui } from "../internals/models/helpers.js";
|
|
4
|
+
import { PickersDayClasses } from "./pickersDayClasses.js";
|
|
5
|
+
export interface PickerDayOwnerState extends PickerOwnerState {
|
|
6
|
+
/**
|
|
7
|
+
* The object representing the day.
|
|
8
|
+
*/
|
|
9
|
+
day: PickerValidDate;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the day is selected.
|
|
12
|
+
*/
|
|
13
|
+
isDaySelected: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the day is disabled.
|
|
16
|
+
*/
|
|
17
|
+
isDayDisabled: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the day is equal to today.
|
|
20
|
+
*/
|
|
21
|
+
isDayCurrent: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the day is outside the month it's being rendered in.
|
|
24
|
+
*/
|
|
25
|
+
isDayOutsideMonth: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the day is the first day of the week.
|
|
28
|
+
*/
|
|
29
|
+
isDayStartOfWeek: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the day is the last day of the week.
|
|
32
|
+
*/
|
|
33
|
+
isDayEndOfWeek: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the margin around the day should be removed.
|
|
36
|
+
*/
|
|
37
|
+
disableMargin: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the visual indication around the current day should be removed.
|
|
40
|
+
*/
|
|
41
|
+
disableHighlightToday: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the day outside of the month they are being rendered in should be visible.
|
|
44
|
+
*/
|
|
45
|
+
showDaysOutsideCurrentMonth: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface ExportedPickersDayProps {
|
|
48
|
+
/**
|
|
49
|
+
* If `true`, today's date is rendering without highlighting with circle.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
disableHighlightToday?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* If `true`, days outside the current month are rendered:
|
|
55
|
+
*
|
|
56
|
+
* - if `fixedWeekNumber` is defined, renders days to have the weeks requested.
|
|
57
|
+
*
|
|
58
|
+
* - if `fixedWeekNumber` is not defined, renders day to fill the first and last week of the current month.
|
|
59
|
+
*
|
|
60
|
+
* - ignored if `calendars` equals more than `1` on range pickers.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
showDaysOutsideCurrentMonth?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface PickersDayProps extends ExportedPickersDayProps, Omit<ExtendMui<ButtonBaseProps>, 'onKeyDown' | 'onFocus' | 'onBlur' | 'onMouseEnter' | 'LinkComponent'> {
|
|
66
|
+
/**
|
|
67
|
+
* Override or extend the styles applied to the component.
|
|
68
|
+
*/
|
|
69
|
+
classes?: Partial<PickersDayClasses>;
|
|
70
|
+
/**
|
|
71
|
+
* The date to show.
|
|
72
|
+
*/
|
|
73
|
+
day: PickerValidDate;
|
|
74
|
+
/**
|
|
75
|
+
* If `true`, renders as disabled.
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* If `true`, days are rendering without margin. Useful for displaying linked range of days.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
disableMargin?: boolean;
|
|
84
|
+
isAnimating?: boolean;
|
|
85
|
+
onFocus?: (event: React.FocusEvent<HTMLButtonElement>, day: PickerValidDate) => void;
|
|
86
|
+
onBlur?: (event: React.FocusEvent<HTMLButtonElement>, day: PickerValidDate) => void;
|
|
87
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLButtonElement>, day: PickerValidDate) => void;
|
|
88
|
+
onMouseEnter?: (event: React.MouseEvent<HTMLButtonElement>, day: PickerValidDate) => void;
|
|
89
|
+
onDaySelect: (day: PickerValidDate) => void;
|
|
90
|
+
/**
|
|
91
|
+
* If `true`, day is outside of month and will be hidden.
|
|
92
|
+
*/
|
|
93
|
+
outsideCurrentMonth: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* If `true`, day is the first visible cell of the month.
|
|
96
|
+
* Either the first day of the month or the first day of the week depending on `showDaysOutsideCurrentMonth`.
|
|
97
|
+
*/
|
|
98
|
+
isFirstVisibleCell: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* If `true`, day is the last visible cell of the month.
|
|
101
|
+
* Either the last day of the month or the last day of the week depending on `showDaysOutsideCurrentMonth`.
|
|
102
|
+
*/
|
|
103
|
+
isLastVisibleCell: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* If `true`, renders as selected.
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
selected?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* If `true`, renders as today date.
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
today?: boolean;
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { PickersDay } from "./PickersDay.js";
|
|
2
|
-
export type { PickersDayProps } from './PickersDay';
|
|
2
|
+
export type { PickersDayProps, PickerDayOwnerState } from './PickersDay.types';
|
|
3
3
|
export { pickersDayClasses, getPickersDayUtilityClass } from "./pickersDayClasses.js";
|
|
4
4
|
export type { PickersDayClasses, PickersDayClassKey } from './pickersDayClasses';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PickerDayOwnerState } from "./PickersDay.types.js";
|
|
2
|
+
import { PickerValidDate } from "../models/pickers.js";
|
|
3
|
+
export declare function usePickerDayOwnerState(parameters: UsePickerDayOwnerStateParameters): PickerDayOwnerState;
|
|
4
|
+
interface UsePickerDayOwnerStateParameters {
|
|
5
|
+
day: PickerValidDate;
|
|
6
|
+
disabled: boolean | undefined;
|
|
7
|
+
selected: boolean | undefined;
|
|
8
|
+
today: boolean | undefined;
|
|
9
|
+
outsideCurrentMonth: boolean | undefined;
|
|
10
|
+
disableMargin: boolean | undefined;
|
|
11
|
+
disableHighlightToday: boolean | undefined;
|
|
12
|
+
showDaysOutsideCurrentMonth: boolean | undefined;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
|
4
|
+
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
5
|
+
export function usePickerDayOwnerState(parameters) {
|
|
6
|
+
const {
|
|
7
|
+
disabled,
|
|
8
|
+
selected,
|
|
9
|
+
today,
|
|
10
|
+
outsideCurrentMonth,
|
|
11
|
+
day,
|
|
12
|
+
disableMargin,
|
|
13
|
+
disableHighlightToday,
|
|
14
|
+
showDaysOutsideCurrentMonth
|
|
15
|
+
} = parameters;
|
|
16
|
+
const utils = useUtils();
|
|
17
|
+
const {
|
|
18
|
+
ownerState: pickerOwnerState
|
|
19
|
+
} = usePickerPrivateContext();
|
|
20
|
+
return React.useMemo(() => _extends({}, pickerOwnerState, {
|
|
21
|
+
day,
|
|
22
|
+
isDaySelected: selected ?? false,
|
|
23
|
+
isDayDisabled: disabled ?? false,
|
|
24
|
+
isDayCurrent: today ?? false,
|
|
25
|
+
isDayOutsideMonth: outsideCurrentMonth ?? false,
|
|
26
|
+
isDayStartOfWeek: utils.isSameDay(day, utils.startOfWeek(day)),
|
|
27
|
+
isDayEndOfWeek: utils.isSameDay(day, utils.endOfWeek(day)),
|
|
28
|
+
disableMargin: disableMargin ?? false,
|
|
29
|
+
disableHighlightToday: disableHighlightToday ?? false,
|
|
30
|
+
showDaysOutsideCurrentMonth: showDaysOutsideCurrentMonth ?? false
|
|
31
|
+
}), [utils, pickerOwnerState, day, selected, disabled, today, outsideCurrentMonth, disableMargin, disableHighlightToday, showDaysOutsideCurrentMonth]);
|
|
32
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UseTimeFieldProps } from "./TimeField.types.js";
|
|
2
|
-
export declare const useTimeField: <TEnableAccessibleFieldDOMStructure extends boolean,
|
|
2
|
+
export declare const useTimeField: <TEnableAccessibleFieldDOMStructure extends boolean, TProps extends UseTimeFieldProps<TEnableAccessibleFieldDOMStructure>>(props: TProps) => import("../internals").UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TProps>;
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useField
|
|
4
|
-
import { useSplitFieldProps } from "../hooks/index.js";
|
|
3
|
+
import { useField } from "../internals/hooks/useField/index.js";
|
|
5
4
|
import { useTimeManager } from "../managers/index.js";
|
|
6
5
|
export const useTimeField = props => {
|
|
7
6
|
const manager = useTimeManager(props);
|
|
8
|
-
const {
|
|
9
|
-
forwardedProps,
|
|
10
|
-
internalProps
|
|
11
|
-
} = useSplitFieldProps(props, 'time');
|
|
12
|
-
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
|
|
13
|
-
manager,
|
|
14
|
-
internalProps
|
|
15
|
-
});
|
|
16
7
|
return useField({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
valueManager: manager.internal_valueManager,
|
|
20
|
-
fieldValueManager: manager.internal_fieldValueManager,
|
|
21
|
-
validator: manager.validator,
|
|
22
|
-
valueType: manager.valueType,
|
|
23
|
-
getOpenPickerButtonAriaLabel: manager.internal_useOpenPickerButtonAriaLabel()
|
|
8
|
+
manager,
|
|
9
|
+
props
|
|
24
10
|
});
|
|
25
11
|
};
|
|
@@ -102,6 +102,7 @@ process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
|
|
|
102
102
|
disableIgnoringDatePartForTimeValidation: PropTypes.bool,
|
|
103
103
|
/**
|
|
104
104
|
* If `true`, the button to open the Picker will not be rendered (it will only render the field).
|
|
105
|
+
* @deprecated Use the [field component](https://next.mui.com/x/react-date-pickers/fields/) instead.
|
|
105
106
|
* @default false
|
|
106
107
|
*/
|
|
107
108
|
disableOpenPicker: PropTypes.bool,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from "../validation/extractValidationProps.js";
|
|
2
2
|
import { PickerValueType } from "../models/common.js";
|
|
3
3
|
declare const SHARED_FIELD_INTERNAL_PROP_NAMES: readonly ["value", "defaultValue", "referenceDate", "format", "formatDensity", "onChange", "timezone", "onError", "shouldRespectLeadingZeros", "selectedSections", "onSelectedSectionsChange", "unstableFieldRef", "unstableStartFieldRef", "unstableEndFieldRef", "enableAccessibleFieldDOMStructure", "disabled", "readOnly", "dateSeparator", "autoFocus", "focused"];
|
|
4
|
-
type InternalPropNames<TValueType extends PickerValueType> = (typeof SHARED_FIELD_INTERNAL_PROP_NAMES)[number] | (TValueType extends 'date' | 'date-time' ? (typeof DATE_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'time' | 'date-time' ? (typeof TIME_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'date-time' ? (typeof DATE_TIME_VALIDATION_PROP_NAMES)[number] : never);
|
|
4
|
+
export type InternalPropNames<TValueType extends PickerValueType> = (typeof SHARED_FIELD_INTERNAL_PROP_NAMES)[number] | (TValueType extends 'date' | 'date-time' ? (typeof DATE_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'time' | 'date-time' ? (typeof TIME_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'date-time' ? (typeof DATE_TIME_VALIDATION_PROP_NAMES)[number] : never);
|
|
5
5
|
/**
|
|
6
6
|
* Split the props received by the field component into:
|
|
7
7
|
* - `internalProps` which are used by the various hooks called by the field component.
|
package/esm/index.js
CHANGED
|
@@ -6,9 +6,9 @@ import { SvgIconProps } from '@mui/material/SvgIcon';
|
|
|
6
6
|
import { MakeOptional, SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
7
7
|
import { FieldOwnerState } from "../../models/index.js";
|
|
8
8
|
import { UseFieldOwnerStateParameters } from "../hooks/useFieldOwnerState.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseFieldReturnValue, UseFieldProps } from '../hooks/useField';
|
|
10
10
|
import { PickersTextFieldProps } from "../../PickersTextField/index.js";
|
|
11
|
-
export declare const cleanFieldResponse: <TFieldResponse extends MakeOptional<
|
|
11
|
+
export declare const cleanFieldResponse: <TFieldResponse extends MakeOptional<UseFieldReturnValue<any, ExportedPickerFieldUIProps & {
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}>, "onClear" | "clearable">>({
|
|
14
14
|
enableAccessibleFieldDOMStructure,
|
|
@@ -22,7 +22,7 @@ export declare const PickerFieldUIContext: React.Context<PickerFieldUIContextVal
|
|
|
22
22
|
* Adds the button to open the Picker and the button to clear the value of the field.
|
|
23
23
|
* @ignore - internal component.
|
|
24
24
|
*/
|
|
25
|
-
export declare function PickerFieldUI(props: PickerFieldUIProps): React.JSX.Element;
|
|
25
|
+
export declare function PickerFieldUI<TEnableAccessibleFieldDOMStructure extends boolean, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>>(props: PickerFieldUIProps<TEnableAccessibleFieldDOMStructure, TProps>): React.JSX.Element;
|
|
26
26
|
export interface ExportedPickerFieldUIProps {
|
|
27
27
|
/**
|
|
28
28
|
* If `true`, a clear button will be shown in the field allowing value clearing.
|
|
@@ -46,7 +46,7 @@ export interface ExportedPickerFieldUIProps {
|
|
|
46
46
|
*/
|
|
47
47
|
openPickerButtonPosition?: 'start' | 'end';
|
|
48
48
|
}
|
|
49
|
-
export interface PickerFieldUIProps {
|
|
49
|
+
export interface PickerFieldUIProps<TEnableAccessibleFieldDOMStructure extends boolean, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>> {
|
|
50
50
|
/**
|
|
51
51
|
* Overridable component slots.
|
|
52
52
|
* @default {}
|
|
@@ -60,7 +60,7 @@ export interface PickerFieldUIProps {
|
|
|
60
60
|
/**
|
|
61
61
|
* Object returned by the `useField` hook or one of its wrapper (for example `useDateField`).
|
|
62
62
|
*/
|
|
63
|
-
fieldResponse:
|
|
63
|
+
fieldResponse: UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TProps>;
|
|
64
64
|
/**
|
|
65
65
|
* The component to use to render the Picker opening icon if none is provided in the Picker's slots.
|
|
66
66
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldSection, MuiPickersAdapter, PickerValidDate } from "../../../models/index.js";
|
|
2
2
|
import { PickersLocaleText } from "../../../locales/index.js";
|
|
3
|
-
interface
|
|
3
|
+
interface BuildSectionsFromFormatParameters {
|
|
4
4
|
utils: MuiPickersAdapter;
|
|
5
5
|
format: string;
|
|
6
6
|
formatDensity: 'dense' | 'spacious';
|
|
@@ -11,5 +11,5 @@ interface BuildSectionsFromFormatParams {
|
|
|
11
11
|
date: PickerValidDate | null;
|
|
12
12
|
enableAccessibleFieldDOMStructure: boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare const buildSectionsFromFormat: (
|
|
14
|
+
export declare const buildSectionsFromFormat: (parameters: BuildSectionsFromFormatParameters) => FieldSection[];
|
|
15
15
|
export {};
|
|
@@ -141,12 +141,12 @@ const createSection = ({
|
|
|
141
141
|
modified: false
|
|
142
142
|
});
|
|
143
143
|
};
|
|
144
|
-
const buildSections =
|
|
144
|
+
const buildSections = parameters => {
|
|
145
145
|
const {
|
|
146
146
|
utils,
|
|
147
147
|
expandedFormat,
|
|
148
148
|
escapedParts
|
|
149
|
-
} =
|
|
149
|
+
} = parameters;
|
|
150
150
|
const now = utils.date(undefined);
|
|
151
151
|
const sections = [];
|
|
152
152
|
let startSeparator = '';
|
|
@@ -171,7 +171,7 @@ const buildSections = params => {
|
|
|
171
171
|
while (word.length > 0) {
|
|
172
172
|
const firstWord = regExpFirstTokenInWord.exec(word)[1];
|
|
173
173
|
word = word.slice(firstWord.length);
|
|
174
|
-
sections.push(createSection(_extends({},
|
|
174
|
+
sections.push(createSection(_extends({}, parameters, {
|
|
175
175
|
now,
|
|
176
176
|
token: firstWord,
|
|
177
177
|
startSeparator
|
|
@@ -236,19 +236,19 @@ const postProcessSections = ({
|
|
|
236
236
|
return section;
|
|
237
237
|
});
|
|
238
238
|
};
|
|
239
|
-
export const buildSectionsFromFormat =
|
|
240
|
-
let expandedFormat = expandFormat(
|
|
241
|
-
if (
|
|
239
|
+
export const buildSectionsFromFormat = parameters => {
|
|
240
|
+
let expandedFormat = expandFormat(parameters);
|
|
241
|
+
if (parameters.isRtl && parameters.enableAccessibleFieldDOMStructure) {
|
|
242
242
|
expandedFormat = expandedFormat.split(' ').reverse().join(' ');
|
|
243
243
|
}
|
|
244
|
-
const escapedParts = getEscapedPartsFromFormat(_extends({},
|
|
244
|
+
const escapedParts = getEscapedPartsFromFormat(_extends({}, parameters, {
|
|
245
245
|
expandedFormat
|
|
246
246
|
}));
|
|
247
|
-
const sections = buildSections(_extends({},
|
|
247
|
+
const sections = buildSections(_extends({}, parameters, {
|
|
248
248
|
expandedFormat,
|
|
249
249
|
escapedParts
|
|
250
250
|
}));
|
|
251
|
-
return postProcessSections(_extends({},
|
|
251
|
+
return postProcessSections(_extends({}, parameters, {
|
|
252
252
|
sections
|
|
253
253
|
}));
|
|
254
254
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { useField } from "./useField.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type { UseFieldInternalProps, UseFieldParameters, UseFieldReturnValue, UseFieldProps, FieldValueManager, FieldChangeHandler, FieldChangeHandlerContext } from './useField.types';
|
|
3
3
|
export { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections } from "./useField.utils.js";
|
|
4
4
|
export { useFieldInternalPropsWithDefaults } from "./useFieldInternalPropsWithDefaults.js";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseFieldParameters, UseFieldReturnValue, UseFieldProps } from "./useField.types.js";
|
|
2
2
|
import { PickerValidValue } from "../../models/index.js";
|
|
3
|
-
export declare const useField: <TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean,
|
|
4
|
-
minutesStep?: number;
|
|
5
|
-
}>(params: UseFieldParams<TValue, TEnableAccessibleFieldDOMStructure, TForwardedProps, TInternalProps>) => UseFieldResponse<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
|
|
3
|
+
export declare const useField: <TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError, TValidationProps extends {}, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>>(parameters: UseFieldParameters<TValue, TEnableAccessibleFieldDOMStructure, TError, TValidationProps, TProps>) => UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TProps>;
|
|
@@ -1,233 +1,9 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
4
|
-
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
|
-
import { useRtl } from '@mui/system/RtlProvider';
|
|
6
|
-
import { useValidation } from "../../../validation/index.js";
|
|
7
|
-
import { useUtils } from "../useUtils.js";
|
|
8
|
-
import { adjustSectionValue, getSectionOrder } from "./useField.utils.js";
|
|
9
|
-
import { useFieldState } from "./useFieldState.js";
|
|
10
|
-
import { useFieldCharacterEditing } from "./useFieldCharacterEditing.js";
|
|
11
1
|
import { useFieldV7TextField } from "./useFieldV7TextField.js";
|
|
12
2
|
import { useFieldV6TextField } from "./useFieldV6TextField.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
internalProps: {
|
|
18
|
-
unstableFieldRef,
|
|
19
|
-
minutesStep,
|
|
20
|
-
enableAccessibleFieldDOMStructure = true,
|
|
21
|
-
disabled = false,
|
|
22
|
-
readOnly = false,
|
|
23
|
-
autoFocus = false
|
|
24
|
-
},
|
|
25
|
-
forwardedProps: {
|
|
26
|
-
onKeyDown,
|
|
27
|
-
error,
|
|
28
|
-
clearable,
|
|
29
|
-
onClear
|
|
30
|
-
},
|
|
31
|
-
fieldValueManager,
|
|
32
|
-
validator,
|
|
33
|
-
getOpenPickerButtonAriaLabel: getOpenDialogAriaText
|
|
34
|
-
} = params;
|
|
35
|
-
const isRtl = useRtl();
|
|
36
|
-
const stateResponse = useFieldState(params);
|
|
37
|
-
const {
|
|
38
|
-
state,
|
|
39
|
-
value,
|
|
40
|
-
activeSectionIndex,
|
|
41
|
-
parsedSelectedSections,
|
|
42
|
-
setSelectedSections,
|
|
43
|
-
clearValue,
|
|
44
|
-
clearActiveSection,
|
|
45
|
-
updateSectionValue,
|
|
46
|
-
setTempAndroidValueStr,
|
|
47
|
-
sectionsValueBoundaries,
|
|
48
|
-
localizedDigits,
|
|
49
|
-
timezone
|
|
50
|
-
} = stateResponse;
|
|
51
|
-
const characterEditingResponse = useFieldCharacterEditing({
|
|
52
|
-
sections: state.sections,
|
|
53
|
-
updateSectionValue,
|
|
54
|
-
sectionsValueBoundaries,
|
|
55
|
-
localizedDigits,
|
|
56
|
-
setTempAndroidValueStr,
|
|
57
|
-
timezone
|
|
58
|
-
});
|
|
59
|
-
const {
|
|
60
|
-
resetCharacterQuery
|
|
61
|
-
} = characterEditingResponse;
|
|
62
|
-
const areAllSectionsEmpty = React.useMemo(() => state.sections.every(section => section.value === ''), [state.sections]);
|
|
3
|
+
import { useNullableFieldPrivateContext } from "../useNullableFieldPrivateContext.js";
|
|
4
|
+
export const useField = parameters => {
|
|
5
|
+
const fieldPrivateContext = useNullableFieldPrivateContext();
|
|
6
|
+
const enableAccessibleFieldDOMStructure = parameters.props.enableAccessibleFieldDOMStructure ?? fieldPrivateContext?.enableAccessibleFieldDOMStructure ?? true;
|
|
63
7
|
const useFieldTextField = enableAccessibleFieldDOMStructure ? useFieldV7TextField : useFieldV6TextField;
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
returnedValue,
|
|
67
|
-
interactions
|
|
68
|
-
} = useFieldTextField(_extends({}, params, stateResponse, characterEditingResponse, {
|
|
69
|
-
areAllSectionsEmpty,
|
|
70
|
-
sectionOrder
|
|
71
|
-
}));
|
|
72
|
-
const handleContainerKeyDown = useEventCallback(event => {
|
|
73
|
-
onKeyDown?.(event);
|
|
74
|
-
if (disabled) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// eslint-disable-next-line default-case
|
|
78
|
-
switch (true) {
|
|
79
|
-
// Select all
|
|
80
|
-
case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
|
|
81
|
-
{
|
|
82
|
-
// prevent default to make sure that the next line "select all" while updating
|
|
83
|
-
// the internal state at the same time.
|
|
84
|
-
event.preventDefault();
|
|
85
|
-
setSelectedSections('all');
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Move selection to next section
|
|
90
|
-
case event.key === 'ArrowRight':
|
|
91
|
-
{
|
|
92
|
-
event.preventDefault();
|
|
93
|
-
if (parsedSelectedSections == null) {
|
|
94
|
-
setSelectedSections(sectionOrder.startIndex);
|
|
95
|
-
} else if (parsedSelectedSections === 'all') {
|
|
96
|
-
setSelectedSections(sectionOrder.endIndex);
|
|
97
|
-
} else {
|
|
98
|
-
const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].rightIndex;
|
|
99
|
-
if (nextSectionIndex !== null) {
|
|
100
|
-
setSelectedSections(nextSectionIndex);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Move selection to previous section
|
|
107
|
-
case event.key === 'ArrowLeft':
|
|
108
|
-
{
|
|
109
|
-
event.preventDefault();
|
|
110
|
-
if (parsedSelectedSections == null) {
|
|
111
|
-
setSelectedSections(sectionOrder.endIndex);
|
|
112
|
-
} else if (parsedSelectedSections === 'all') {
|
|
113
|
-
setSelectedSections(sectionOrder.startIndex);
|
|
114
|
-
} else {
|
|
115
|
-
const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].leftIndex;
|
|
116
|
-
if (nextSectionIndex !== null) {
|
|
117
|
-
setSelectedSections(nextSectionIndex);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Reset the value of the selected section
|
|
124
|
-
case event.key === 'Delete':
|
|
125
|
-
{
|
|
126
|
-
event.preventDefault();
|
|
127
|
-
if (readOnly) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
if (parsedSelectedSections == null || parsedSelectedSections === 'all') {
|
|
131
|
-
clearValue();
|
|
132
|
-
} else {
|
|
133
|
-
clearActiveSection();
|
|
134
|
-
}
|
|
135
|
-
resetCharacterQuery();
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Increment / decrement the selected section value
|
|
140
|
-
case ['ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown'].includes(event.key):
|
|
141
|
-
{
|
|
142
|
-
event.preventDefault();
|
|
143
|
-
if (readOnly || activeSectionIndex == null) {
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// if all sections are selected, mark the currently editing one as selected
|
|
148
|
-
if (parsedSelectedSections === 'all') {
|
|
149
|
-
setSelectedSections(activeSectionIndex);
|
|
150
|
-
}
|
|
151
|
-
const activeSection = state.sections[activeSectionIndex];
|
|
152
|
-
const newSectionValue = adjustSectionValue(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
|
|
153
|
-
minutesStep
|
|
154
|
-
});
|
|
155
|
-
updateSectionValue({
|
|
156
|
-
section: activeSection,
|
|
157
|
-
newSectionValue,
|
|
158
|
-
shouldGoToNextSection: false
|
|
159
|
-
});
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
useEnhancedEffect(() => {
|
|
165
|
-
interactions.syncSelectionToDOM();
|
|
166
|
-
});
|
|
167
|
-
const {
|
|
168
|
-
hasValidationError
|
|
169
|
-
} = useValidation({
|
|
170
|
-
props: internalProps,
|
|
171
|
-
validator,
|
|
172
|
-
timezone,
|
|
173
|
-
value,
|
|
174
|
-
onError: internalProps.onError
|
|
175
|
-
});
|
|
176
|
-
const inputError = React.useMemo(() => {
|
|
177
|
-
// only override when `error` is undefined.
|
|
178
|
-
// in case of multi input fields, the `error` value is provided externally and will always be defined.
|
|
179
|
-
if (error !== undefined) {
|
|
180
|
-
return error;
|
|
181
|
-
}
|
|
182
|
-
return hasValidationError;
|
|
183
|
-
}, [hasValidationError, error]);
|
|
184
|
-
React.useEffect(() => {
|
|
185
|
-
if (!inputError && activeSectionIndex == null) {
|
|
186
|
-
resetCharacterQuery();
|
|
187
|
-
}
|
|
188
|
-
}, [state.referenceValue, activeSectionIndex, inputError]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
189
|
-
|
|
190
|
-
// If `tempValueStrAndroid` is still defined for some section when running `useEffect`,
|
|
191
|
-
// Then `onChange` has only been called once, which means the user pressed `Backspace` to reset the section.
|
|
192
|
-
// This causes a small flickering on Android,
|
|
193
|
-
// But we can't use `useEnhancedEffect` which is always called before the second `onChange` call and then would cause false positives.
|
|
194
|
-
React.useEffect(() => {
|
|
195
|
-
if (state.tempValueStrAndroid != null && activeSectionIndex != null) {
|
|
196
|
-
resetCharacterQuery();
|
|
197
|
-
clearActiveSection();
|
|
198
|
-
}
|
|
199
|
-
}, [state.sections]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
200
|
-
|
|
201
|
-
React.useImperativeHandle(unstableFieldRef, () => ({
|
|
202
|
-
getSections: () => state.sections,
|
|
203
|
-
getActiveSectionIndex: interactions.getActiveSectionIndexFromDOM,
|
|
204
|
-
setSelectedSections: interactions.setSelectedSections,
|
|
205
|
-
focusField: interactions.focusField,
|
|
206
|
-
isFieldFocused: interactions.isFieldFocused
|
|
207
|
-
}));
|
|
208
|
-
const handleClearValue = useEventCallback((event, ...args) => {
|
|
209
|
-
event.preventDefault();
|
|
210
|
-
onClear?.(event, ...args);
|
|
211
|
-
clearValue();
|
|
212
|
-
if (!interactions.isFieldFocused()) {
|
|
213
|
-
// setSelectedSections is called internally
|
|
214
|
-
interactions.focusField(0);
|
|
215
|
-
} else {
|
|
216
|
-
setSelectedSections(sectionOrder.startIndex);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
const commonForwardedProps = {
|
|
220
|
-
onKeyDown: handleContainerKeyDown,
|
|
221
|
-
onClear: handleClearValue,
|
|
222
|
-
error: inputError,
|
|
223
|
-
clearable: Boolean(clearable && !areAllSectionsEmpty && !readOnly && !disabled)
|
|
224
|
-
};
|
|
225
|
-
const openPickerAriaLabel = React.useMemo(() => getOpenDialogAriaText(value), [getOpenDialogAriaText, value]);
|
|
226
|
-
const commonAdditionalProps = {
|
|
227
|
-
disabled,
|
|
228
|
-
readOnly,
|
|
229
|
-
autoFocus,
|
|
230
|
-
openPickerAriaLabel
|
|
231
|
-
};
|
|
232
|
-
return _extends({}, params.forwardedProps, commonForwardedProps, commonAdditionalProps, returnedValue);
|
|
8
|
+
return useFieldTextField(parameters);
|
|
233
9
|
};
|