@mui/x-date-pickers 8.0.0-alpha.0 → 8.0.0-alpha.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 +429 -5
- package/DateCalendar/DateCalendar.js +1 -0
- package/DatePicker/DatePickerToolbar.js +0 -12
- package/DateTimePicker/DateTimePickerToolbar.d.ts +2 -2
- package/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
- package/DigitalClock/DigitalClock.js +1 -0
- package/MonthCalendar/MonthCalendar.js +1 -0
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/PickersLayout/PickersLayout.js +0 -12
- package/PickersLayout/PickersLayout.types.d.ts +2 -2
- package/PickersLayout/usePickerLayout.js +1 -5
- package/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/PickersTextField/PickersTextField.js +2 -2
- package/README.md +2 -2
- package/TimeClock/Clock.js +1 -0
- package/TimeClock/TimeClock.js +1 -0
- package/TimePicker/TimePickerToolbar.js +6 -15
- package/YearCalendar/YearCalendar.js +1 -0
- package/hooks/useSplitFieldProps.d.ts +3 -3
- package/index.js +1 -1
- package/internals/components/PickerProvider.d.ts +26 -0
- package/internals/components/PickerProvider.js +3 -1
- package/internals/components/PickersToolbar.js +2 -4
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/internals/hooks/useField/useField.types.d.ts +2 -2
- package/internals/hooks/useField/useField.utils.d.ts +2 -2
- package/internals/hooks/useField/useFieldState.js +1 -0
- package/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/internals/hooks/usePicker/usePicker.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.js +9 -12
- package/internals/hooks/usePicker/usePicker.types.d.ts +6 -6
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +6 -7
- package/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
- package/internals/hooks/usePicker/usePickerProvider.d.ts +20 -4
- package/internals/hooks/usePicker/usePickerProvider.js +61 -5
- package/internals/hooks/usePicker/usePickerValue.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.js +18 -6
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +8 -7
- package/internals/hooks/usePicker/usePickerViews.d.ts +1 -0
- package/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/internals/hooks/useValueWithTimezone.d.ts +19 -15
- package/internals/hooks/useValueWithTimezone.js +13 -1
- package/internals/index.d.ts +1 -1
- package/internals/models/common.d.ts +2 -1
- package/internals/models/props/toolbar.d.ts +1 -2
- package/internals/utils/date-utils.d.ts +2 -2
- package/models/common.d.ts +1 -0
- package/models/fields.d.ts +0 -1
- package/models/pickers.d.ts +18 -0
- package/modern/DateCalendar/DateCalendar.js +1 -0
- package/modern/DatePicker/DatePickerToolbar.js +0 -12
- package/modern/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
- package/modern/DigitalClock/DigitalClock.js +1 -0
- package/modern/MonthCalendar/MonthCalendar.js +1 -0
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/modern/PickersLayout/PickersLayout.js +0 -12
- package/modern/PickersLayout/usePickerLayout.js +1 -5
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/modern/PickersTextField/PickersTextField.js +2 -2
- package/modern/TimeClock/Clock.js +1 -0
- package/modern/TimeClock/TimeClock.js +1 -0
- package/modern/TimePicker/TimePickerToolbar.js +6 -15
- package/modern/YearCalendar/YearCalendar.js +1 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerProvider.js +3 -1
- package/modern/internals/components/PickersToolbar.js +2 -4
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/modern/internals/hooks/useField/useFieldState.js +1 -0
- package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/modern/internals/hooks/usePicker/usePicker.js +9 -12
- package/modern/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
- package/modern/internals/hooks/usePicker/usePickerProvider.js +61 -5
- package/modern/internals/hooks/usePicker/usePickerValue.js +18 -6
- package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/modern/internals/hooks/useValueWithTimezone.js +13 -1
- package/node/DateCalendar/DateCalendar.js +1 -0
- package/node/DatePicker/DatePickerToolbar.js +0 -12
- package/node/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
- package/node/DigitalClock/DigitalClock.js +1 -0
- package/node/MonthCalendar/MonthCalendar.js +1 -0
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/node/PickersLayout/PickersLayout.js +0 -12
- package/node/PickersLayout/usePickerLayout.js +1 -5
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/node/PickersTextField/PickersTextField.js +2 -2
- package/node/TimeClock/Clock.js +1 -0
- package/node/TimeClock/TimeClock.js +1 -0
- package/node/TimePicker/TimePickerToolbar.js +6 -15
- package/node/YearCalendar/YearCalendar.js +1 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickerProvider.js +3 -1
- package/node/internals/components/PickersToolbar.js +2 -4
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/node/internals/hooks/useField/useFieldState.js +1 -0
- package/node/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/node/internals/hooks/usePicker/usePicker.js +9 -12
- package/node/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
- package/node/internals/hooks/usePicker/usePickerProvider.js +64 -5
- package/node/internals/hooks/usePicker/usePickerValue.js +18 -6
- package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/node/internals/hooks/useValueWithTimezone.js +13 -1
- package/package.json +4 -4
- package/internals/hooks/usePicker/usePickerOwnerState.d.ts +0 -10
- package/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
- package/modern/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
- package/node/internals/hooks/usePicker/usePickerOwnerState.js +0 -23
|
@@ -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 = ["elements", "areAllSectionsEmpty", "defaultValue", "label", "value", "onChange", "id", "autoFocus", "endAdornment", "startAdornment", "renderSuffix", "slots", "slotProps", "contentEditable", "tabIndex", "onInput", "onPaste", "onKeyDown", "fullWidth", "name", "readOnly", "inputProps", "inputRef", "sectionListRef"];
|
|
3
|
+
const _excluded = ["elements", "areAllSectionsEmpty", "defaultValue", "label", "value", "onChange", "id", "autoFocus", "endAdornment", "startAdornment", "renderSuffix", "slots", "slotProps", "contentEditable", "tabIndex", "onInput", "onPaste", "onKeyDown", "fullWidth", "name", "readOnly", "inputProps", "inputRef", "sectionListRef", "onFocus", "onBlur"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { useFormControl } from '@mui/material/FormControl';
|
|
@@ -194,7 +194,9 @@ const PickersInputBase = /*#__PURE__*/React.forwardRef(function PickersInputBase
|
|
|
194
194
|
readOnly,
|
|
195
195
|
inputProps,
|
|
196
196
|
inputRef,
|
|
197
|
-
sectionListRef
|
|
197
|
+
sectionListRef,
|
|
198
|
+
onFocus,
|
|
199
|
+
onBlur
|
|
198
200
|
} = props,
|
|
199
201
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
200
202
|
const rootRef = React.useRef(null);
|
|
@@ -206,13 +208,12 @@ const PickersInputBase = /*#__PURE__*/React.forwardRef(function PickersInputBase
|
|
|
206
208
|
throw new Error('MUI X: PickersInputBase should always be used inside a PickersTextField component');
|
|
207
209
|
}
|
|
208
210
|
const handleInputFocus = event => {
|
|
209
|
-
// Fix a bug with IE11 where the focus/blur events are triggered
|
|
210
|
-
// while the component is disabled.
|
|
211
|
-
if (muiFormControl.disabled) {
|
|
212
|
-
event.stopPropagation();
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
211
|
muiFormControl.onFocus?.(event);
|
|
212
|
+
onFocus?.(event);
|
|
213
|
+
};
|
|
214
|
+
const handleInputBlur = event => {
|
|
215
|
+
muiFormControl.onBlur?.(event);
|
|
216
|
+
onBlur?.(event);
|
|
216
217
|
};
|
|
217
218
|
React.useEffect(() => {
|
|
218
219
|
if (muiFormControl) {
|
|
@@ -254,7 +255,7 @@ const PickersInputBase = /*#__PURE__*/React.forwardRef(function PickersInputBase
|
|
|
254
255
|
tabIndex: tabIndex,
|
|
255
256
|
className: classes.sectionsContainer,
|
|
256
257
|
onFocus: handleInputFocus,
|
|
257
|
-
onBlur:
|
|
258
|
+
onBlur: handleInputBlur,
|
|
258
259
|
onInput: onInput,
|
|
259
260
|
onPaste: onPaste,
|
|
260
261
|
onKeyDown: onKeyDown,
|
|
@@ -105,8 +105,6 @@ const PickersTextField = /*#__PURE__*/React.forwardRef(function PickersTextField
|
|
|
105
105
|
className: clsx(classes.root, className),
|
|
106
106
|
ref: handleRootRef,
|
|
107
107
|
focused: focused,
|
|
108
|
-
onFocus: onFocus,
|
|
109
|
-
onBlur: onBlur,
|
|
110
108
|
disabled: disabled,
|
|
111
109
|
variant: variant,
|
|
112
110
|
error: error,
|
|
@@ -128,6 +126,8 @@ const PickersTextField = /*#__PURE__*/React.forwardRef(function PickersTextField
|
|
|
128
126
|
onKeyUp: onKeyUp,
|
|
129
127
|
onInput: onInput,
|
|
130
128
|
onPaste: onPaste,
|
|
129
|
+
onFocus: onFocus,
|
|
130
|
+
onBlur: onBlur,
|
|
131
131
|
endAdornment: endAdornment,
|
|
132
132
|
startAdornment: startAdornment,
|
|
133
133
|
tabIndex: tabIndex,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "
|
|
5
|
+
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "className"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
@@ -18,6 +18,7 @@ import { useUtils } from "../internals/hooks/useUtils.js";
|
|
|
18
18
|
import { useMeridiemMode } from "../internals/hooks/date-helpers-hooks.js";
|
|
19
19
|
import { getTimePickerToolbarUtilityClass, timePickerToolbarClasses } from "./timePickerToolbarClasses.js";
|
|
20
20
|
import { formatMeridiem } from "../internals/utils/date-utils.js";
|
|
21
|
+
import { usePickerContext } from "../hooks/index.js";
|
|
21
22
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
23
|
const useUtilityClasses = ownerState => {
|
|
23
24
|
const {
|
|
@@ -128,14 +129,16 @@ function TimePickerToolbar(inProps) {
|
|
|
128
129
|
view,
|
|
129
130
|
onViewChange,
|
|
130
131
|
views,
|
|
131
|
-
disabled,
|
|
132
|
-
readOnly,
|
|
133
132
|
className
|
|
134
133
|
} = props,
|
|
135
134
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
136
135
|
const utils = useUtils();
|
|
137
136
|
const translations = usePickerTranslations();
|
|
138
137
|
const isRtl = useRtl();
|
|
138
|
+
const {
|
|
139
|
+
disabled,
|
|
140
|
+
readOnly
|
|
141
|
+
} = usePickerContext();
|
|
139
142
|
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
|
|
140
143
|
const {
|
|
141
144
|
meridiemMode,
|
|
@@ -216,12 +219,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
216
219
|
*/
|
|
217
220
|
classes: PropTypes.object,
|
|
218
221
|
className: PropTypes.string,
|
|
219
|
-
/**
|
|
220
|
-
* If `true`, the component is disabled.
|
|
221
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
222
|
-
* @default false
|
|
223
|
-
*/
|
|
224
|
-
disabled: PropTypes.bool,
|
|
225
222
|
/**
|
|
226
223
|
* If `true`, show the toolbar even in desktop mode.
|
|
227
224
|
* @default `true` for Desktop, `false` for Mobile.
|
|
@@ -235,12 +232,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
235
232
|
* @param {TView} view The view to open
|
|
236
233
|
*/
|
|
237
234
|
onViewChange: PropTypes.func.isRequired,
|
|
238
|
-
/**
|
|
239
|
-
* If `true`, the component is read-only.
|
|
240
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
241
|
-
* @default false
|
|
242
|
-
*/
|
|
243
|
-
readOnly: PropTypes.bool,
|
|
244
235
|
/**
|
|
245
236
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
246
237
|
*/
|
package/modern/index.js
CHANGED
|
@@ -7,7 +7,9 @@ export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
|
7
7
|
isPickerDisabled: false,
|
|
8
8
|
isPickerReadOnly: false,
|
|
9
9
|
isPickerValueEmpty: false,
|
|
10
|
-
isPickerOpen: false
|
|
10
|
+
isPickerOpen: false,
|
|
11
|
+
pickerVariant: 'desktop',
|
|
12
|
+
pickerOrientation: 'portrait'
|
|
11
13
|
}
|
|
12
14
|
});
|
|
13
15
|
|
|
@@ -10,13 +10,11 @@ import { getPickersToolbarUtilityClass } from "./pickersToolbarClasses.js";
|
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
const useUtilityClasses = ownerState => {
|
|
12
12
|
const {
|
|
13
|
-
classes
|
|
14
|
-
isLandscape
|
|
13
|
+
classes
|
|
15
14
|
} = ownerState;
|
|
16
15
|
const slots = {
|
|
17
16
|
root: ['root'],
|
|
18
|
-
content: ['content']
|
|
19
|
-
penIconButton: ['penIconButton', isLandscape && 'penIconButtonLandscape']
|
|
17
|
+
content: ['content']
|
|
20
18
|
};
|
|
21
19
|
return composeClasses(slots, getPickersToolbarUtilityClass, classes);
|
|
22
20
|
};
|
|
@@ -67,7 +67,7 @@ export const useDesktopPicker = _ref => {
|
|
|
67
67
|
localeText,
|
|
68
68
|
autoFocusView: true,
|
|
69
69
|
additionalViewProps: {},
|
|
70
|
-
|
|
70
|
+
variant: 'desktop'
|
|
71
71
|
}));
|
|
72
72
|
const InputAdornment = slots.inputAdornment ?? MuiInputAdornment;
|
|
73
73
|
const _useSlotProps = useSlotProps({
|
|
@@ -198,8 +198,9 @@ export const useFieldV7TextField = params => {
|
|
|
198
198
|
if (focused || !sectionListRef.current) {
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
+
const activeElement = getActiveElement(document);
|
|
201
202
|
setFocused(true);
|
|
202
|
-
const isFocusInsideASection = sectionListRef.current.getSectionIndexFromDOMElement(
|
|
203
|
+
const isFocusInsideASection = sectionListRef.current.getSectionIndexFromDOMElement(activeElement) != null;
|
|
203
204
|
if (!isFocusInsideASection) {
|
|
204
205
|
setSelectedSections(sectionOrder.startIndex);
|
|
205
206
|
}
|
|
@@ -2,13 +2,12 @@ import { warnOnce } from '@mui/x-internals/warning';
|
|
|
2
2
|
import { usePickerValue } from "./usePickerValue.js";
|
|
3
3
|
import { usePickerViews } from "./usePickerViews.js";
|
|
4
4
|
import { usePickerLayoutProps } from "./usePickerLayoutProps.js";
|
|
5
|
-
import { usePickerOwnerState } from "./usePickerOwnerState.js";
|
|
6
5
|
import { usePickerProvider } from "./usePickerProvider.js";
|
|
7
6
|
export const usePicker = ({
|
|
8
7
|
props,
|
|
9
8
|
valueManager,
|
|
10
9
|
valueType,
|
|
11
|
-
|
|
10
|
+
variant,
|
|
12
11
|
additionalViewProps,
|
|
13
12
|
validator,
|
|
14
13
|
autoFocusView,
|
|
@@ -25,7 +24,7 @@ export const usePicker = ({
|
|
|
25
24
|
props,
|
|
26
25
|
valueManager,
|
|
27
26
|
valueType,
|
|
28
|
-
|
|
27
|
+
variant,
|
|
29
28
|
validator
|
|
30
29
|
});
|
|
31
30
|
const pickerViewsResponse = usePickerViews({
|
|
@@ -38,19 +37,17 @@ export const usePicker = ({
|
|
|
38
37
|
});
|
|
39
38
|
const pickerLayoutResponse = usePickerLayoutProps({
|
|
40
39
|
props,
|
|
41
|
-
|
|
40
|
+
variant,
|
|
42
41
|
propsFromPickerValue: pickerValueResponse.layoutProps,
|
|
43
42
|
propsFromPickerViews: pickerViewsResponse.layoutProps
|
|
44
43
|
});
|
|
45
|
-
const pickerOwnerState = usePickerOwnerState({
|
|
46
|
-
props,
|
|
47
|
-
pickerValueResponse,
|
|
48
|
-
valueManager
|
|
49
|
-
});
|
|
50
44
|
const providerProps = usePickerProvider({
|
|
45
|
+
props,
|
|
51
46
|
pickerValueResponse,
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
localeText,
|
|
48
|
+
valueManager,
|
|
49
|
+
variant,
|
|
50
|
+
views: pickerViewsResponse.views
|
|
54
51
|
});
|
|
55
52
|
return {
|
|
56
53
|
// Picker value
|
|
@@ -66,6 +63,6 @@ export const usePicker = ({
|
|
|
66
63
|
// Picker provider
|
|
67
64
|
providerProps,
|
|
68
65
|
// Picker owner state
|
|
69
|
-
ownerState:
|
|
66
|
+
ownerState: providerProps.privateContextValue.ownerState
|
|
70
67
|
};
|
|
71
68
|
};
|
|
@@ -4,7 +4,6 @@ import { useIsLandscape } from "../useIsLandscape.js";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Props used to create the layout of the views.
|
|
7
|
-
* Those props are exposed on all the pickers.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -14,7 +13,7 @@ export const usePickerLayoutProps = ({
|
|
|
14
13
|
props,
|
|
15
14
|
propsFromPickerValue,
|
|
16
15
|
propsFromPickerViews,
|
|
17
|
-
|
|
16
|
+
variant
|
|
18
17
|
}) => {
|
|
19
18
|
const {
|
|
20
19
|
orientation
|
|
@@ -24,9 +23,7 @@ export const usePickerLayoutProps = ({
|
|
|
24
23
|
const layoutProps = _extends({}, propsFromPickerViews, propsFromPickerValue, {
|
|
25
24
|
isLandscape,
|
|
26
25
|
isRtl,
|
|
27
|
-
wrapperVariant
|
|
28
|
-
disabled: props.disabled,
|
|
29
|
-
readOnly: props.readOnly
|
|
26
|
+
wrapperVariant: variant
|
|
30
27
|
});
|
|
31
28
|
return {
|
|
32
29
|
layoutProps
|
|
@@ -1,15 +1,66 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
3
|
+
import { useUtils } from "../useUtils.js";
|
|
4
|
+
import { arrayIncludes } from "../../utils/utils.js";
|
|
5
|
+
function getOrientation() {
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
return 'portrait';
|
|
8
|
+
}
|
|
9
|
+
if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
|
|
10
|
+
return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Support IOS safari
|
|
14
|
+
if (window.orientation) {
|
|
15
|
+
return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
|
|
16
|
+
}
|
|
17
|
+
return 'portrait';
|
|
18
|
+
}
|
|
19
|
+
export const usePickerOrientation = (views, customOrientation) => {
|
|
20
|
+
const [orientation, setOrientation] = React.useState(getOrientation);
|
|
21
|
+
useEnhancedEffect(() => {
|
|
22
|
+
const eventHandler = () => {
|
|
23
|
+
setOrientation(getOrientation());
|
|
24
|
+
};
|
|
25
|
+
window.addEventListener('orientationchange', eventHandler);
|
|
26
|
+
return () => {
|
|
27
|
+
window.removeEventListener('orientationchange', eventHandler);
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
if (arrayIncludes(views, ['hours', 'minutes', 'seconds'])) {
|
|
31
|
+
// could not display 13:34:44 in landscape mode
|
|
32
|
+
return 'portrait';
|
|
33
|
+
}
|
|
34
|
+
return customOrientation ?? orientation;
|
|
35
|
+
};
|
|
2
36
|
export function usePickerProvider(parameters) {
|
|
3
37
|
const {
|
|
38
|
+
props,
|
|
4
39
|
pickerValueResponse,
|
|
5
|
-
|
|
6
|
-
localeText
|
|
40
|
+
valueManager,
|
|
41
|
+
localeText,
|
|
42
|
+
variant,
|
|
43
|
+
views
|
|
7
44
|
} = parameters;
|
|
45
|
+
const utils = useUtils();
|
|
46
|
+
const orientation = usePickerOrientation(views, props.orientation);
|
|
47
|
+
const ownerState = React.useMemo(() => ({
|
|
48
|
+
isPickerValueEmpty: valueManager.areValuesEqual(utils, pickerValueResponse.viewProps.value, valueManager.emptyValue),
|
|
49
|
+
isPickerOpen: pickerValueResponse.open,
|
|
50
|
+
isPickerDisabled: props.disabled ?? false,
|
|
51
|
+
isPickerReadOnly: props.readOnly ?? false,
|
|
52
|
+
pickerOrientation: orientation,
|
|
53
|
+
pickerVariant: variant
|
|
54
|
+
}), [utils, valueManager, pickerValueResponse.viewProps.value, pickerValueResponse.open, orientation, variant, props.disabled, props.readOnly]);
|
|
8
55
|
const contextValue = React.useMemo(() => ({
|
|
9
56
|
onOpen: pickerValueResponse.actions.onOpen,
|
|
10
57
|
onClose: pickerValueResponse.actions.onClose,
|
|
11
|
-
open: pickerValueResponse.open
|
|
12
|
-
|
|
58
|
+
open: pickerValueResponse.open,
|
|
59
|
+
disabled: props.disabled ?? false,
|
|
60
|
+
readOnly: props.readOnly ?? false,
|
|
61
|
+
variant,
|
|
62
|
+
orientation
|
|
63
|
+
}), [pickerValueResponse.actions.onOpen, pickerValueResponse.actions.onClose, pickerValueResponse.open, variant, orientation, props.disabled, props.readOnly]);
|
|
13
64
|
const privateContextValue = React.useMemo(() => ({
|
|
14
65
|
ownerState
|
|
15
66
|
}), [ownerState]);
|
|
@@ -18,4 +69,9 @@ export function usePickerProvider(parameters) {
|
|
|
18
69
|
contextValue,
|
|
19
70
|
privateContextValue
|
|
20
71
|
};
|
|
21
|
-
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Props used to create the private context.
|
|
76
|
+
* Those props are exposed on all the pickers.
|
|
77
|
+
*/
|
|
@@ -113,7 +113,7 @@ export const usePickerValue = ({
|
|
|
113
113
|
props,
|
|
114
114
|
valueManager,
|
|
115
115
|
valueType,
|
|
116
|
-
|
|
116
|
+
variant,
|
|
117
117
|
validator
|
|
118
118
|
}) => {
|
|
119
119
|
const {
|
|
@@ -121,8 +121,9 @@ export const usePickerValue = ({
|
|
|
121
121
|
onChange,
|
|
122
122
|
value: inValueWithoutRenderTimezone,
|
|
123
123
|
defaultValue: inDefaultValue,
|
|
124
|
-
closeOnSelect =
|
|
125
|
-
timezone: timezoneProp
|
|
124
|
+
closeOnSelect = variant === 'desktop',
|
|
125
|
+
timezone: timezoneProp,
|
|
126
|
+
referenceDate
|
|
126
127
|
} = props;
|
|
127
128
|
const {
|
|
128
129
|
current: defaultValue
|
|
@@ -130,6 +131,7 @@ export const usePickerValue = ({
|
|
|
130
131
|
const {
|
|
131
132
|
current: isControlled
|
|
132
133
|
} = React.useRef(inValueWithoutRenderTimezone !== undefined);
|
|
134
|
+
const [previousTimezoneProp, setPreviousTimezoneProp] = React.useState(timezoneProp);
|
|
133
135
|
|
|
134
136
|
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
135
137
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -160,6 +162,7 @@ export const usePickerValue = ({
|
|
|
160
162
|
timezone: timezoneProp,
|
|
161
163
|
value: inValueWithoutRenderTimezone,
|
|
162
164
|
defaultValue,
|
|
165
|
+
referenceDate,
|
|
163
166
|
onChange,
|
|
164
167
|
valueManager
|
|
165
168
|
});
|
|
@@ -176,10 +179,19 @@ export const usePickerValue = ({
|
|
|
176
179
|
draft: initialValue,
|
|
177
180
|
lastPublishedValue: initialValue,
|
|
178
181
|
lastCommittedValue: initialValue,
|
|
179
|
-
lastControlledValue:
|
|
182
|
+
lastControlledValue: inValueWithoutRenderTimezone,
|
|
180
183
|
hasBeenModifiedSinceMount: false
|
|
181
184
|
};
|
|
182
185
|
});
|
|
186
|
+
const timezoneFromDraftValue = valueManager.getTimezone(utils, dateState.draft);
|
|
187
|
+
if (previousTimezoneProp !== timezoneProp) {
|
|
188
|
+
setPreviousTimezoneProp(timezoneProp);
|
|
189
|
+
if (timezoneProp && timezoneFromDraftValue && timezoneProp !== timezoneFromDraftValue) {
|
|
190
|
+
setDateState(prev => _extends({}, prev, {
|
|
191
|
+
draft: valueManager.setTimezone(utils, timezoneProp, prev.draft)
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
183
195
|
const {
|
|
184
196
|
getValidationErrorForNewValue
|
|
185
197
|
} = useValidation({
|
|
@@ -229,10 +241,10 @@ export const usePickerValue = ({
|
|
|
229
241
|
setIsOpen(false);
|
|
230
242
|
}
|
|
231
243
|
});
|
|
232
|
-
if (
|
|
244
|
+
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
233
245
|
const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValueWithTimezoneToRender);
|
|
234
246
|
setDateState(prev => _extends({}, prev, {
|
|
235
|
-
lastControlledValue:
|
|
247
|
+
lastControlledValue: inValueWithoutRenderTimezone
|
|
236
248
|
}, isUpdateComingFromPicker ? {} : {
|
|
237
249
|
lastCommittedValue: inValueWithTimezoneToRender,
|
|
238
250
|
lastPublishedValue: inValueWithTimezoneToRender,
|
|
@@ -48,7 +48,7 @@ export const useStaticPicker = _ref => {
|
|
|
48
48
|
fieldRef: undefined,
|
|
49
49
|
localeText,
|
|
50
50
|
additionalViewProps: {},
|
|
51
|
-
|
|
51
|
+
variant: displayStaticWrapperAs
|
|
52
52
|
}));
|
|
53
53
|
const Layout = slots?.layout ?? PickerStaticLayout;
|
|
54
54
|
const renderPicker = () => /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, {
|
|
@@ -11,6 +11,7 @@ export const useValueWithTimezone = ({
|
|
|
11
11
|
timezone: timezoneProp,
|
|
12
12
|
value: valueProp,
|
|
13
13
|
defaultValue,
|
|
14
|
+
referenceDate,
|
|
14
15
|
onChange,
|
|
15
16
|
valueManager
|
|
16
17
|
}) => {
|
|
@@ -24,7 +25,16 @@ export const useValueWithTimezone = ({
|
|
|
24
25
|
}
|
|
25
26
|
return valueManager.setTimezone(utils, inputTimezone, newValue);
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
+
let timezoneToRender;
|
|
29
|
+
if (timezoneProp) {
|
|
30
|
+
timezoneToRender = timezoneProp;
|
|
31
|
+
} else if (inputTimezone) {
|
|
32
|
+
timezoneToRender = inputTimezone;
|
|
33
|
+
} else if (referenceDate) {
|
|
34
|
+
timezoneToRender = utils.getTimezone(referenceDate);
|
|
35
|
+
} else {
|
|
36
|
+
timezoneToRender = 'default';
|
|
37
|
+
}
|
|
28
38
|
const valueWithTimezoneToRender = React.useMemo(() => valueManager.setTimezone(utils, timezoneToRender, inputValue), [valueManager, utils, timezoneToRender, inputValue]);
|
|
29
39
|
const handleValueChange = useEventCallback((newValue, ...otherParams) => {
|
|
30
40
|
const newValueWithInputTimezone = setInputTimezone(newValue);
|
|
@@ -45,6 +55,7 @@ export const useControlledValueWithTimezone = ({
|
|
|
45
55
|
timezone: timezoneProp,
|
|
46
56
|
value: valueProp,
|
|
47
57
|
defaultValue,
|
|
58
|
+
referenceDate,
|
|
48
59
|
onChange: onChangeProp,
|
|
49
60
|
valueManager
|
|
50
61
|
}) => {
|
|
@@ -62,6 +73,7 @@ export const useControlledValueWithTimezone = ({
|
|
|
62
73
|
timezone: timezoneProp,
|
|
63
74
|
value: valueWithInputTimezone,
|
|
64
75
|
defaultValue: undefined,
|
|
76
|
+
referenceDate,
|
|
65
77
|
onChange,
|
|
66
78
|
valueManager
|
|
67
79
|
});
|
|
@@ -144,6 +144,7 @@ const DateCalendar = exports.DateCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
144
144
|
timezone: timezoneProp,
|
|
145
145
|
value: valueProp,
|
|
146
146
|
defaultValue,
|
|
147
|
+
referenceDate: referenceDateProp,
|
|
147
148
|
onChange,
|
|
148
149
|
valueManager: _valueManagers.singleItemValueManager
|
|
149
150
|
});
|
|
@@ -114,12 +114,6 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
|
|
|
114
114
|
*/
|
|
115
115
|
classes: _propTypes.default.object,
|
|
116
116
|
className: _propTypes.default.string,
|
|
117
|
-
/**
|
|
118
|
-
* If `true`, the component is disabled.
|
|
119
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
120
|
-
* @default false
|
|
121
|
-
*/
|
|
122
|
-
disabled: _propTypes.default.bool,
|
|
123
117
|
/**
|
|
124
118
|
* If `true`, show the toolbar even in desktop mode.
|
|
125
119
|
* @default `true` for Desktop, `false` for Mobile.
|
|
@@ -133,12 +127,6 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
|
|
|
133
127
|
* @param {TView} view The view to open
|
|
134
128
|
*/
|
|
135
129
|
onViewChange: _propTypes.default.func.isRequired,
|
|
136
|
-
/**
|
|
137
|
-
* If `true`, the component is read-only.
|
|
138
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
139
|
-
* @default false
|
|
140
|
-
*/
|
|
141
|
-
readOnly: _propTypes.default.bool,
|
|
142
130
|
/**
|
|
143
131
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
144
132
|
*/
|
|
@@ -26,8 +26,9 @@ var _dimensions = require("../internals/constants/dimensions");
|
|
|
26
26
|
var _dateUtils = require("../internals/utils/date-utils");
|
|
27
27
|
var _pickersToolbarTextClasses = require("../internals/components/pickersToolbarTextClasses");
|
|
28
28
|
var _pickersToolbarClasses = require("../internals/components/pickersToolbarClasses");
|
|
29
|
+
var _usePickerContext = require("../hooks/usePickerContext");
|
|
29
30
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
30
|
-
const _excluded = ["ampm", "ampmInClock", "value", "onChange", "view", "isLandscape", "onViewChange", "toolbarFormat", "toolbarPlaceholder", "views", "
|
|
31
|
+
const _excluded = ["ampm", "ampmInClock", "value", "onChange", "view", "isLandscape", "onViewChange", "toolbarFormat", "toolbarPlaceholder", "views", "toolbarVariant", "toolbarTitle", "className"];
|
|
31
32
|
const useUtilityClasses = ownerState => {
|
|
32
33
|
const {
|
|
33
34
|
classes,
|
|
@@ -233,14 +234,16 @@ function DateTimePickerToolbar(inProps) {
|
|
|
233
234
|
toolbarFormat,
|
|
234
235
|
toolbarPlaceholder = '––',
|
|
235
236
|
views,
|
|
236
|
-
disabled,
|
|
237
|
-
readOnly,
|
|
238
237
|
toolbarVariant = 'mobile',
|
|
239
238
|
toolbarTitle: inToolbarTitle,
|
|
240
239
|
className
|
|
241
240
|
} = props,
|
|
242
241
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
243
242
|
const isRtl = (0, _RtlProvider.useRtl)();
|
|
243
|
+
const {
|
|
244
|
+
disabled,
|
|
245
|
+
readOnly
|
|
246
|
+
} = (0, _usePickerContext.usePickerContext)();
|
|
244
247
|
const ownerState = (0, _extends2.default)({}, props, {
|
|
245
248
|
isRtl
|
|
246
249
|
});
|
|
@@ -366,12 +369,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
|
|
|
366
369
|
*/
|
|
367
370
|
classes: _propTypes.default.object,
|
|
368
371
|
className: _propTypes.default.string,
|
|
369
|
-
/**
|
|
370
|
-
* If `true`, the component is disabled.
|
|
371
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
372
|
-
* @default false
|
|
373
|
-
*/
|
|
374
|
-
disabled: _propTypes.default.bool,
|
|
375
372
|
/**
|
|
376
373
|
* If `true`, show the toolbar even in desktop mode.
|
|
377
374
|
* @default `true` for Desktop, `false` for Mobile.
|
|
@@ -385,12 +382,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
|
|
|
385
382
|
* @param {TView} view The view to open
|
|
386
383
|
*/
|
|
387
384
|
onViewChange: _propTypes.default.func.isRequired,
|
|
388
|
-
/**
|
|
389
|
-
* If `true`, the component is read-only.
|
|
390
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
391
|
-
* @default false
|
|
392
|
-
*/
|
|
393
|
-
readOnly: _propTypes.default.bool,
|
|
394
385
|
/**
|
|
395
386
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
396
387
|
*/
|
|
@@ -74,12 +74,6 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
|
|
|
74
74
|
*/
|
|
75
75
|
classes: _propTypes.default.object,
|
|
76
76
|
className: _propTypes.default.string,
|
|
77
|
-
/**
|
|
78
|
-
* If `true`, the component is disabled.
|
|
79
|
-
* When disabled, the value cannot be changed and no interaction is possible.
|
|
80
|
-
* @default false
|
|
81
|
-
*/
|
|
82
|
-
disabled: _propTypes.default.bool,
|
|
83
77
|
isLandscape: _propTypes.default.bool.isRequired,
|
|
84
78
|
/**
|
|
85
79
|
* `true` if the application is in right-to-left direction.
|
|
@@ -100,12 +94,6 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
|
|
|
100
94
|
* Force rendering in particular orientation.
|
|
101
95
|
*/
|
|
102
96
|
orientation: _propTypes.default.oneOf(['landscape', 'portrait']),
|
|
103
|
-
/**
|
|
104
|
-
* If `true`, the component is read-only.
|
|
105
|
-
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
106
|
-
* @default false
|
|
107
|
-
*/
|
|
108
|
-
readOnly: _propTypes.default.bool,
|
|
109
97
|
/**
|
|
110
98
|
* The props used for each component slot.
|
|
111
99
|
* @default {}
|
|
@@ -156,6 +156,7 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
|
|
|
156
156
|
timezone: timezoneProp,
|
|
157
157
|
value: valueProp,
|
|
158
158
|
defaultValue,
|
|
159
|
+
referenceDate: referenceDateProp,
|
|
159
160
|
onChange,
|
|
160
161
|
valueManager: _valueManagers.singleItemValueManager
|
|
161
162
|
});
|
|
@@ -106,6 +106,7 @@ const MonthCalendar = exports.MonthCalendar = /*#__PURE__*/React.forwardRef(func
|
|
|
106
106
|
timezone: timezoneProp,
|
|
107
107
|
value: valueProp,
|
|
108
108
|
defaultValue,
|
|
109
|
+
referenceDate: referenceDateProp,
|
|
109
110
|
onChange,
|
|
110
111
|
valueManager: _valueManagers.singleItemValueManager
|
|
111
112
|
});
|