@mui/x-date-pickers 8.0.0-alpha.2 → 8.0.0-alpha.3
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 +102 -0
- package/PickersActionBar/PickersActionBar.js +8 -1
- package/PickersShortcuts/PickersShortcuts.js +8 -1
- package/index.js +1 -1
- package/internals/components/PickerProvider.d.ts +2 -15
- package/internals/hooks/useOpenState.d.ts +3 -2
- package/internals/hooks/useOpenState.js +10 -9
- package/internals/hooks/usePicker/usePicker.js +2 -2
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerProvider.d.ts +2 -2
- package/internals/hooks/usePicker/usePickerProvider.js +8 -10
- package/internals/hooks/usePicker/usePickerValue.js +22 -11
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +26 -0
- package/modern/PickersActionBar/PickersActionBar.js +8 -1
- package/modern/PickersShortcuts/PickersShortcuts.js +8 -1
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useOpenState.js +10 -9
- package/modern/internals/hooks/usePicker/usePicker.js +2 -2
- package/modern/internals/hooks/usePicker/usePickerProvider.js +8 -10
- package/modern/internals/hooks/usePicker/usePickerValue.js +22 -11
- package/node/PickersActionBar/PickersActionBar.js +8 -1
- package/node/PickersShortcuts/PickersShortcuts.js +8 -1
- package/node/index.js +1 -1
- package/node/internals/hooks/useOpenState.js +10 -9
- package/node/internals/hooks/usePicker/usePicker.js +2 -2
- package/node/internals/hooks/usePicker/usePickerProvider.js +9 -11
- package/node/internals/hooks/usePicker/usePickerValue.js +22 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,108 @@
|
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
|
6
6
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
7
|
|
|
8
|
+
## 8.0.0-alpha.3
|
|
9
|
+
|
|
10
|
+
_Dec 5, 2024_
|
|
11
|
+
|
|
12
|
+
We'd like to offer a big thanks to the 9 contributors who made this release possible. Here are some highlights ✨:
|
|
13
|
+
|
|
14
|
+
- 💫 Support [Server-side lazy loading](https://mui.com/x/react-data-grid/server-side-data/lazy-loading/) on the Data Grid. Use [data source](https://mui.com/x/react-data-grid/server-side-data/#data-source) to fetch a range of rows on demand and update the rows in the same way as described in [Infinite loading](https://mui.com/x/react-data-grid/row-updates/#infinite-loading) and [Lazy loading](https://mui.com/x/react-data-grid/row-updates/#lazy-loading) without the need to use any additional event listeners and callbacks.
|
|
15
|
+
- 🎯 Improved [data caching](https://mui.com/x/react-data-grid/server-side-data/#data-caching). Check out our [recommendations](https://mui.com/x/react-data-grid/server-side-data/#improving-the-cache-hit-rate) for improving the cache hit rate.
|
|
16
|
+
|
|
17
|
+
Special thanks go out to the community contributors who have helped make this release possible:
|
|
18
|
+
@ihsanberkozcan, @k-rajat19, @perezShaked.
|
|
19
|
+
Following are all team members who have contributed to this release:
|
|
20
|
+
@arminmeh, @cherniavskii, @flaviendelangle, @JCQuintas, @MBilalShafi, @noraleonte.
|
|
21
|
+
|
|
22
|
+
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
23
|
+
|
|
24
|
+
### Data Grid
|
|
25
|
+
|
|
26
|
+
#### Breaking changes
|
|
27
|
+
|
|
28
|
+
- The "Select all" checkbox is now checked when all the selectable rows are selected, ignoring rows that are not selectable because of the `isRowSelectable` prop.
|
|
29
|
+
- The `rowPositionsDebounceMs` prop was removed.
|
|
30
|
+
- The `gridRowsDataRowIdToIdLookupSelector` selector was removed. Use the `gridRowsLookupSelector` selector in combination with the `getRowId()` API method instead.
|
|
31
|
+
```diff
|
|
32
|
+
-const idToIdLookup = gridRowsDataRowIdToIdLookupSelector(apiRef);
|
|
33
|
+
-const rowId = idToIdLookup[id]
|
|
34
|
+
+const rowsLookup = gridRowsLookupSelector(apiRef);
|
|
35
|
+
+const rowId = apiRef.current.getRowId(rowsLookup[id])
|
|
36
|
+
```
|
|
37
|
+
- The Grid is now more aligned with the WAI-ARIA authoring practices and sets the `role` attribute to `treegrid` if the Data Grid is used with row grouping feature.
|
|
38
|
+
|
|
39
|
+
#### `@mui/x-data-grid@8.0.0-alpha.3`
|
|
40
|
+
|
|
41
|
+
- [DataGrid] Fix deselection not working with `isRowSelectable` (#15692) @MBilalShafi
|
|
42
|
+
- [DataGrid] Make column autosizing work with flex columns (#15465) @cherniavskii
|
|
43
|
+
- [DataGrid] Remove `gridRowsDataRowIdToIdLookupSelector` selector (#15698) @arminmeh
|
|
44
|
+
- [DataGrid] Remove `rowPositionsDebounceMs` prop (#15482) @k-rajat19
|
|
45
|
+
- [l10n] Improve Hebrew (he-IL) locale (#15699) @perezShaked
|
|
46
|
+
- [l10n] Improve Turkish (tr-TR) locale (#15734) @ihsanberkozcan
|
|
47
|
+
|
|
48
|
+
#### `@mui/x-data-grid-pro@8.0.0-alpha.3` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
49
|
+
|
|
50
|
+
Same changes as in `@mui/x-data-grid@8.0.0-alpha.3`, plus:
|
|
51
|
+
|
|
52
|
+
- [DataGridPro] Cleanup pinned rows on removal (#15697) @cherniavskii
|
|
53
|
+
- [DataGridPro] Server-side lazy loading (#13878) @arminmeh
|
|
54
|
+
|
|
55
|
+
#### `@mui/x-data-grid-premium@8.0.0-alpha.3` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
56
|
+
|
|
57
|
+
Same changes as in `@mui/x-data-grid-pro@8.0.0-alpha.3`, plus:
|
|
58
|
+
|
|
59
|
+
- [DataGridPremium] Remove the `ariaV8` experimental flag (#15694) @arminmeh
|
|
60
|
+
|
|
61
|
+
### Date and Time Pickers
|
|
62
|
+
|
|
63
|
+
#### Breaking changes
|
|
64
|
+
|
|
65
|
+
- The `onOpen()` and `onClose()` methods of the `usePickerContext()` hook have been replaced with a single `setOpen` method — [Learn more](https://next.mui.com/x/migration/migration-pickers-v7/#usepickercontext).
|
|
66
|
+
|
|
67
|
+
#### `@mui/x-date-pickers@8.0.0-alpha.3`
|
|
68
|
+
|
|
69
|
+
- [pickers] Replace the `onOpen()` and `onClose()` methods of `usePickerContext()` with a single `setOpen()` method. (#15701) @flaviendelangle
|
|
70
|
+
|
|
71
|
+
#### `@mui/x-date-pickers-pro@8.0.0-alpha.3` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
72
|
+
|
|
73
|
+
Same changes as in `@mui/x-date-pickers@8.0.0-alpha.3`.
|
|
74
|
+
|
|
75
|
+
### Charts
|
|
76
|
+
|
|
77
|
+
#### `@mui/x-charts@8.0.0-alpha.3`
|
|
78
|
+
|
|
79
|
+
- [charts] Improve SVG `pattern` and `gradient` support (#15720) @JCQuintas
|
|
80
|
+
|
|
81
|
+
#### `@mui/x-charts-pro@8.0.0-alpha.3` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
82
|
+
|
|
83
|
+
Same changes as in `@mui/x-charts@8.0.0-alpha.3`.
|
|
84
|
+
|
|
85
|
+
### Tree View
|
|
86
|
+
|
|
87
|
+
#### `@mui/x-tree-view@8.0.0-alpha.3`
|
|
88
|
+
|
|
89
|
+
No changes since `@mui/x-tree-view-pro@v8.0.0-alpha.2`.
|
|
90
|
+
|
|
91
|
+
#### `@mui/x-tree-view-pro@8.0.0-alpha.3` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
92
|
+
|
|
93
|
+
Same changes as in `@mui/x-tree-view@8.0.0-alpha.3`.
|
|
94
|
+
|
|
95
|
+
### Docs
|
|
96
|
+
|
|
97
|
+
- [docs] Add a customization demo for the Date and Time Pickers overview page (#15118) @noraleonte
|
|
98
|
+
- [docs] Fix typo in charts axis documentation (#15743) @JCQuintas
|
|
99
|
+
- [docs] Improve SEO titles for the Data Grid (#15695) @MBilalShafi
|
|
100
|
+
|
|
101
|
+
### Core
|
|
102
|
+
|
|
103
|
+
- [core] Add `@mui/x-tree-view-pro` to `releaseChangelog` (#15316) @flaviendelangle
|
|
104
|
+
- [code-infra] Lock file maintenance (#11894)
|
|
105
|
+
- [code-infra] Check if `preset-safe` folder exists in codemod test (#15703) @JCQuintas
|
|
106
|
+
- [code-infra] Import Pickers `preset-safe` into global codemod config (#15659) @JCQuintas
|
|
107
|
+
- [code-infra] Playwright 1.49 (#15493) @JCQuintas
|
|
108
|
+
- [test] Force hover in headless Chrome (#15710) @cherniavskii
|
|
109
|
+
|
|
8
110
|
## v8.0.0-alpha.2
|
|
9
111
|
|
|
10
112
|
_Nov 29, 2024_
|
|
@@ -5,10 +5,17 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
const _excluded = ["onAccept", "onClear", "onCancel", "onSetToday", "actions"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
8
9
|
import Button from '@mui/material/Button';
|
|
9
10
|
import DialogActions from '@mui/material/DialogActions';
|
|
10
11
|
import { usePickerTranslations } from "../hooks/usePickerTranslations.js";
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const PickersActionBarRoot = styled(DialogActions, {
|
|
14
|
+
name: 'MuiPickersLayout',
|
|
15
|
+
slot: 'ActionBar',
|
|
16
|
+
overridesResolver: (_, styles) => styles.actionBar
|
|
17
|
+
})({});
|
|
18
|
+
|
|
12
19
|
/**
|
|
13
20
|
* Demos:
|
|
14
21
|
*
|
|
@@ -58,7 +65,7 @@ function PickersActionBar(props) {
|
|
|
58
65
|
return null;
|
|
59
66
|
}
|
|
60
67
|
});
|
|
61
|
-
return /*#__PURE__*/_jsx(
|
|
68
|
+
return /*#__PURE__*/_jsx(PickersActionBarRoot, _extends({}, other, {
|
|
62
69
|
children: buttons
|
|
63
70
|
}));
|
|
64
71
|
}
|
|
@@ -5,12 +5,19 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
const _excluded = ["items", "changeImportance", "isLandscape", "onChange", "isValid"],
|
|
6
6
|
_excluded2 = ["getValue"];
|
|
7
7
|
import * as React from 'react';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
8
9
|
import PropTypes from 'prop-types';
|
|
9
10
|
import List from '@mui/material/List';
|
|
10
11
|
import ListItem from '@mui/material/ListItem';
|
|
11
12
|
import Chip from '@mui/material/Chip';
|
|
12
13
|
import { VIEW_HEIGHT } from "../internals/constants/dimensions.js";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
const PickersShortcutsRoot = styled(List, {
|
|
16
|
+
name: 'MuiPickersLayout',
|
|
17
|
+
slot: 'Shortcuts',
|
|
18
|
+
overridesResolver: (_, styles) => styles.shortcuts
|
|
19
|
+
})({});
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* Demos:
|
|
16
23
|
*
|
|
@@ -47,7 +54,7 @@ function PickersShortcuts(props) {
|
|
|
47
54
|
disabled: !isValid(newValue)
|
|
48
55
|
});
|
|
49
56
|
});
|
|
50
|
-
return /*#__PURE__*/_jsx(
|
|
57
|
+
return /*#__PURE__*/_jsx(PickersShortcutsRoot, _extends({
|
|
51
58
|
dense: true,
|
|
52
59
|
sx: [{
|
|
53
60
|
maxHeight: VIEW_HEIGHT,
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { PickerOwnerState } from '../../models';
|
|
3
3
|
import { PickersInputLocaleText } from '../../locales';
|
|
4
4
|
import { PickerOrientation, PickerVariant } from '../models';
|
|
5
|
+
import { UsePickerValueContextValue } from '../hooks/usePicker/usePickerValue.types';
|
|
5
6
|
export declare const PickerContext: React.Context<PickerContextValue | null>;
|
|
6
7
|
export declare const PickerPrivateContext: React.Context<PickerPrivateContextValue>;
|
|
7
8
|
/**
|
|
@@ -18,21 +19,7 @@ export interface PickerProviderProps {
|
|
|
18
19
|
localeText: PickersInputLocaleText | undefined;
|
|
19
20
|
children: React.ReactNode;
|
|
20
21
|
}
|
|
21
|
-
export interface PickerContextValue {
|
|
22
|
-
/**
|
|
23
|
-
* Open the picker.
|
|
24
|
-
* @param {React.UIEvent} event The DOM event that triggered the change.
|
|
25
|
-
*/
|
|
26
|
-
onOpen: (event: React.UIEvent) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Close the picker.
|
|
29
|
-
* @param {React.UIEvent} event The DOM event that triggered the change.
|
|
30
|
-
*/
|
|
31
|
-
onClose: (event: React.UIEvent) => void;
|
|
32
|
-
/**
|
|
33
|
-
* `true` if the picker is open, `false` otherwise.
|
|
34
|
-
*/
|
|
35
|
-
open: boolean;
|
|
22
|
+
export interface PickerContextValue extends UsePickerValueContextValue {
|
|
36
23
|
/**
|
|
37
24
|
* `true` if the picker is disabled, `false` otherwise.
|
|
38
25
|
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
export interface OpenStateProps {
|
|
2
3
|
open?: boolean;
|
|
3
4
|
onOpen?: () => void;
|
|
4
5
|
onClose?: () => void;
|
|
5
6
|
}
|
|
6
7
|
export declare const useOpenState: ({ open, onOpen, onClose }: OpenStateProps) => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
open: boolean;
|
|
9
|
+
setOpen: (action: React.SetStateAction<boolean>) => void;
|
|
9
10
|
};
|
|
@@ -5,7 +5,7 @@ export const useOpenState = ({
|
|
|
5
5
|
onClose
|
|
6
6
|
}) => {
|
|
7
7
|
const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
|
|
8
|
-
const [openState,
|
|
8
|
+
const [openState, setOpenState] = React.useState(false);
|
|
9
9
|
|
|
10
10
|
// It is required to update inner state in useEffect in order to avoid situation when
|
|
11
11
|
// Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
|
|
@@ -14,22 +14,23 @@ export const useOpenState = ({
|
|
|
14
14
|
if (typeof open !== 'boolean') {
|
|
15
15
|
throw new Error('You must not mix controlling and uncontrolled mode for `open` prop');
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
setOpenState(open);
|
|
18
18
|
}
|
|
19
19
|
}, [isControllingOpenProp, open]);
|
|
20
|
-
const
|
|
20
|
+
const setOpen = React.useCallback(action => {
|
|
21
|
+
const newOpen = typeof action === 'function' ? action(openState) : action;
|
|
21
22
|
if (!isControllingOpenProp) {
|
|
22
|
-
|
|
23
|
+
setOpenState(newOpen);
|
|
23
24
|
}
|
|
24
|
-
if (
|
|
25
|
+
if (newOpen && onOpen) {
|
|
25
26
|
onOpen();
|
|
26
27
|
}
|
|
27
|
-
if (!
|
|
28
|
+
if (!newOpen && onClose) {
|
|
28
29
|
onClose();
|
|
29
30
|
}
|
|
30
|
-
}, [isControllingOpenProp, onOpen, onClose]);
|
|
31
|
+
}, [isControllingOpenProp, onOpen, onClose, openState]);
|
|
31
32
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
open: openState,
|
|
34
|
+
setOpen
|
|
34
35
|
};
|
|
35
36
|
};
|
|
@@ -37,11 +37,11 @@ export const usePicker = ({
|
|
|
37
37
|
});
|
|
38
38
|
const providerProps = usePickerProvider({
|
|
39
39
|
props,
|
|
40
|
-
pickerValueResponse,
|
|
41
40
|
localeText,
|
|
42
41
|
valueManager,
|
|
43
42
|
variant,
|
|
44
|
-
views: pickerViewsResponse.views
|
|
43
|
+
views: pickerViewsResponse.views,
|
|
44
|
+
paramsFromUsePickerValue: pickerValueResponse.provider
|
|
45
45
|
});
|
|
46
46
|
return {
|
|
47
47
|
// Picker value
|
|
@@ -13,7 +13,7 @@ export interface UsePickerProps<TValue extends PickerValidValue, TView extends D
|
|
|
13
13
|
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any, any>, TAdditionalProps extends {}> extends Pick<UsePickerValueParams<TValue, TExternalProps>, 'valueManager' | 'valueType' | 'variant' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>, 'additionalViewProps' | 'autoFocusView' | 'rendererInterceptor' | 'fieldRef'>, Pick<UsePickerProviderParameters<TValue>, 'localeText'> {
|
|
14
14
|
props: TExternalProps;
|
|
15
15
|
}
|
|
16
|
-
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends
|
|
16
|
+
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<UsePickerValueResponse<TValue, TError>, 'open' | 'actions' | 'fieldProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps' | 'views'> {
|
|
17
17
|
ownerState: PickerOwnerState;
|
|
18
18
|
providerProps: UsePickerProviderReturnValue;
|
|
19
19
|
layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps'] & UsePickerViewsResponse<TView>['layoutProps'];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PickerValueManager,
|
|
1
|
+
import { PickerValueManager, UsePickerValueProviderParams } from './usePickerValue.types';
|
|
2
2
|
import { PickerProviderProps } from '../../components/PickerProvider';
|
|
3
3
|
import type { UsePickerProps } from './usePicker.types';
|
|
4
4
|
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerVariant } from '../../models';
|
|
@@ -6,10 +6,10 @@ export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMe
|
|
|
6
6
|
export declare function usePickerProvider<TValue extends PickerValidValue>(parameters: UsePickerProviderParameters<TValue>): UsePickerProviderReturnValue;
|
|
7
7
|
export interface UsePickerProviderParameters<TValue extends PickerValidValue> extends Pick<PickerProviderProps, 'localeText'> {
|
|
8
8
|
props: UsePickerProps<TValue, any, any, any, any>;
|
|
9
|
-
pickerValueResponse: UsePickerValueResponse<TValue, any>;
|
|
10
9
|
valueManager: PickerValueManager<TValue, any>;
|
|
11
10
|
variant: PickerVariant;
|
|
12
11
|
views: readonly DateOrTimeViewWithMeridiem[];
|
|
12
|
+
paramsFromUsePickerValue: UsePickerValueProviderParams<TValue>;
|
|
13
13
|
}
|
|
14
14
|
export interface UsePickerProviderReturnValue extends Omit<PickerProviderProps, 'children'> {
|
|
15
15
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
3
4
|
import { useUtils } from "../useUtils.js";
|
|
@@ -36,31 +37,28 @@ export const usePickerOrientation = (views, customOrientation) => {
|
|
|
36
37
|
export function usePickerProvider(parameters) {
|
|
37
38
|
const {
|
|
38
39
|
props,
|
|
39
|
-
pickerValueResponse,
|
|
40
40
|
valueManager,
|
|
41
41
|
localeText,
|
|
42
42
|
variant,
|
|
43
|
-
views
|
|
43
|
+
views,
|
|
44
|
+
paramsFromUsePickerValue
|
|
44
45
|
} = parameters;
|
|
45
46
|
const utils = useUtils();
|
|
46
47
|
const orientation = usePickerOrientation(views, props.orientation);
|
|
47
48
|
const ownerState = React.useMemo(() => ({
|
|
48
|
-
isPickerValueEmpty: valueManager.areValuesEqual(utils,
|
|
49
|
-
isPickerOpen:
|
|
49
|
+
isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
|
|
50
|
+
isPickerOpen: paramsFromUsePickerValue.contextValue.open,
|
|
50
51
|
isPickerDisabled: props.disabled ?? false,
|
|
51
52
|
isPickerReadOnly: props.readOnly ?? false,
|
|
52
53
|
pickerOrientation: orientation,
|
|
53
54
|
pickerVariant: variant
|
|
54
|
-
}), [utils, valueManager,
|
|
55
|
-
const contextValue = React.useMemo(() => ({
|
|
56
|
-
onOpen: pickerValueResponse.actions.onOpen,
|
|
57
|
-
onClose: pickerValueResponse.actions.onClose,
|
|
58
|
-
open: pickerValueResponse.open,
|
|
55
|
+
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
56
|
+
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, {
|
|
59
57
|
disabled: props.disabled ?? false,
|
|
60
58
|
readOnly: props.readOnly ?? false,
|
|
61
59
|
variant,
|
|
62
60
|
orientation
|
|
63
|
-
}), [
|
|
61
|
+
}), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
64
62
|
const privateContextValue = React.useMemo(() => ({
|
|
65
63
|
ownerState
|
|
66
64
|
}), [ownerState]);
|
|
@@ -150,8 +150,8 @@ export const usePickerValue = ({
|
|
|
150
150
|
const utils = useUtils();
|
|
151
151
|
const adapter = useLocalizationContext();
|
|
152
152
|
const {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
open,
|
|
154
|
+
setOpen
|
|
155
155
|
} = useOpenState(props);
|
|
156
156
|
const {
|
|
157
157
|
timezone,
|
|
@@ -237,7 +237,7 @@ export const usePickerValue = ({
|
|
|
237
237
|
onAccept(action.value, getContext());
|
|
238
238
|
}
|
|
239
239
|
if (shouldClose) {
|
|
240
|
-
|
|
240
|
+
setOpen(false);
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
@@ -288,11 +288,11 @@ export const usePickerValue = ({
|
|
|
288
288
|
});
|
|
289
289
|
const handleOpen = useEventCallback(event => {
|
|
290
290
|
event.preventDefault();
|
|
291
|
-
|
|
291
|
+
setOpen(true);
|
|
292
292
|
});
|
|
293
293
|
const handleClose = useEventCallback(event => {
|
|
294
294
|
event?.preventDefault();
|
|
295
|
-
|
|
295
|
+
setOpen(false);
|
|
296
296
|
});
|
|
297
297
|
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
298
298
|
name: 'setValueFromView',
|
|
@@ -323,12 +323,12 @@ export const usePickerValue = ({
|
|
|
323
323
|
value: dateState.draft,
|
|
324
324
|
onChange: handleChangeFromField
|
|
325
325
|
};
|
|
326
|
-
const
|
|
326
|
+
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
327
327
|
const viewResponse = {
|
|
328
|
-
value:
|
|
328
|
+
value: valueWithoutError,
|
|
329
329
|
onChange: handleChange,
|
|
330
330
|
onClose: handleClose,
|
|
331
|
-
open
|
|
331
|
+
open
|
|
332
332
|
};
|
|
333
333
|
const isValid = testedValue => {
|
|
334
334
|
const error = validator({
|
|
@@ -340,16 +340,27 @@ export const usePickerValue = ({
|
|
|
340
340
|
return !valueManager.hasError(error);
|
|
341
341
|
};
|
|
342
342
|
const layoutResponse = _extends({}, actions, {
|
|
343
|
-
value:
|
|
343
|
+
value: valueWithoutError,
|
|
344
344
|
onChange: handleChange,
|
|
345
345
|
onSelectShortcut: handleSelectShortcut,
|
|
346
346
|
isValid
|
|
347
347
|
});
|
|
348
|
+
const contextValue = React.useMemo(() => {
|
|
349
|
+
return {
|
|
350
|
+
open,
|
|
351
|
+
setOpen
|
|
352
|
+
};
|
|
353
|
+
}, [open, setOpen]);
|
|
354
|
+
const providerParams = {
|
|
355
|
+
value: valueWithoutError,
|
|
356
|
+
contextValue
|
|
357
|
+
};
|
|
348
358
|
return {
|
|
349
|
-
open
|
|
359
|
+
open,
|
|
350
360
|
fieldProps: fieldResponse,
|
|
351
361
|
viewProps: viewResponse,
|
|
352
362
|
layoutProps: layoutResponse,
|
|
353
|
-
actions
|
|
363
|
+
actions,
|
|
364
|
+
provider: providerParams
|
|
354
365
|
};
|
|
355
366
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { FieldChangeHandlerContext, UseFieldInternalProps } from '../useField';
|
|
2
3
|
import { Validator } from '../../../validation';
|
|
3
4
|
import { PickerVariant } from '../../models/common';
|
|
@@ -264,10 +265,35 @@ export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> e
|
|
|
264
265
|
onSelectShortcut: (newValue: TValue, changeImportance: PickerShortcutChangeImportance, shortcut: PickersShortcutsItemContext) => void;
|
|
265
266
|
isValid: (value: TValue) => boolean;
|
|
266
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Params passed to `usePickerProvider`.
|
|
270
|
+
*/
|
|
271
|
+
export interface UsePickerValueProviderParams<TValue extends PickerValidValue> {
|
|
272
|
+
value: TValue;
|
|
273
|
+
contextValue: UsePickerValueContextValue;
|
|
274
|
+
}
|
|
267
275
|
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
268
276
|
open: boolean;
|
|
269
277
|
actions: UsePickerValueActions;
|
|
270
278
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
271
279
|
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
272
280
|
layoutProps: UsePickerValueLayoutResponse<TValue>;
|
|
281
|
+
provider: UsePickerValueProviderParams<TValue>;
|
|
282
|
+
}
|
|
283
|
+
export interface UsePickerValueContextValue {
|
|
284
|
+
/**
|
|
285
|
+
* Sets the current open state of the Picker.
|
|
286
|
+
* ```ts
|
|
287
|
+
* setOpen(true); // Opens the picker.
|
|
288
|
+
* setOpen(false); // Closes the picker.
|
|
289
|
+
* setOpen((prevOpen) => !prevOpen); // Toggles the open state.
|
|
290
|
+
* ```
|
|
291
|
+
* @param {React.SetStateAction<boolean>} action The new open state of the Picker.
|
|
292
|
+
* It can be a function that will receive the current open state.
|
|
293
|
+
*/
|
|
294
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
295
|
+
/**
|
|
296
|
+
* `true` if the picker is open, `false` otherwise.
|
|
297
|
+
*/
|
|
298
|
+
open: boolean;
|
|
273
299
|
}
|
|
@@ -5,10 +5,17 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
const _excluded = ["onAccept", "onClear", "onCancel", "onSetToday", "actions"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
8
9
|
import Button from '@mui/material/Button';
|
|
9
10
|
import DialogActions from '@mui/material/DialogActions';
|
|
10
11
|
import { usePickerTranslations } from "../hooks/usePickerTranslations.js";
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const PickersActionBarRoot = styled(DialogActions, {
|
|
14
|
+
name: 'MuiPickersLayout',
|
|
15
|
+
slot: 'ActionBar',
|
|
16
|
+
overridesResolver: (_, styles) => styles.actionBar
|
|
17
|
+
})({});
|
|
18
|
+
|
|
12
19
|
/**
|
|
13
20
|
* Demos:
|
|
14
21
|
*
|
|
@@ -58,7 +65,7 @@ function PickersActionBar(props) {
|
|
|
58
65
|
return null;
|
|
59
66
|
}
|
|
60
67
|
});
|
|
61
|
-
return /*#__PURE__*/_jsx(
|
|
68
|
+
return /*#__PURE__*/_jsx(PickersActionBarRoot, _extends({}, other, {
|
|
62
69
|
children: buttons
|
|
63
70
|
}));
|
|
64
71
|
}
|
|
@@ -5,12 +5,19 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
const _excluded = ["items", "changeImportance", "isLandscape", "onChange", "isValid"],
|
|
6
6
|
_excluded2 = ["getValue"];
|
|
7
7
|
import * as React from 'react';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
8
9
|
import PropTypes from 'prop-types';
|
|
9
10
|
import List from '@mui/material/List';
|
|
10
11
|
import ListItem from '@mui/material/ListItem';
|
|
11
12
|
import Chip from '@mui/material/Chip';
|
|
12
13
|
import { VIEW_HEIGHT } from "../internals/constants/dimensions.js";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
const PickersShortcutsRoot = styled(List, {
|
|
16
|
+
name: 'MuiPickersLayout',
|
|
17
|
+
slot: 'Shortcuts',
|
|
18
|
+
overridesResolver: (_, styles) => styles.shortcuts
|
|
19
|
+
})({});
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* Demos:
|
|
16
23
|
*
|
|
@@ -47,7 +54,7 @@ function PickersShortcuts(props) {
|
|
|
47
54
|
disabled: !isValid(newValue)
|
|
48
55
|
});
|
|
49
56
|
});
|
|
50
|
-
return /*#__PURE__*/_jsx(
|
|
57
|
+
return /*#__PURE__*/_jsx(PickersShortcutsRoot, _extends({
|
|
51
58
|
dense: true,
|
|
52
59
|
sx: [{
|
|
53
60
|
maxHeight: VIEW_HEIGHT,
|
package/modern/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export const useOpenState = ({
|
|
|
5
5
|
onClose
|
|
6
6
|
}) => {
|
|
7
7
|
const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
|
|
8
|
-
const [openState,
|
|
8
|
+
const [openState, setOpenState] = React.useState(false);
|
|
9
9
|
|
|
10
10
|
// It is required to update inner state in useEffect in order to avoid situation when
|
|
11
11
|
// Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
|
|
@@ -14,22 +14,23 @@ export const useOpenState = ({
|
|
|
14
14
|
if (typeof open !== 'boolean') {
|
|
15
15
|
throw new Error('You must not mix controlling and uncontrolled mode for `open` prop');
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
setOpenState(open);
|
|
18
18
|
}
|
|
19
19
|
}, [isControllingOpenProp, open]);
|
|
20
|
-
const
|
|
20
|
+
const setOpen = React.useCallback(action => {
|
|
21
|
+
const newOpen = typeof action === 'function' ? action(openState) : action;
|
|
21
22
|
if (!isControllingOpenProp) {
|
|
22
|
-
|
|
23
|
+
setOpenState(newOpen);
|
|
23
24
|
}
|
|
24
|
-
if (
|
|
25
|
+
if (newOpen && onOpen) {
|
|
25
26
|
onOpen();
|
|
26
27
|
}
|
|
27
|
-
if (!
|
|
28
|
+
if (!newOpen && onClose) {
|
|
28
29
|
onClose();
|
|
29
30
|
}
|
|
30
|
-
}, [isControllingOpenProp, onOpen, onClose]);
|
|
31
|
+
}, [isControllingOpenProp, onOpen, onClose, openState]);
|
|
31
32
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
open: openState,
|
|
34
|
+
setOpen
|
|
34
35
|
};
|
|
35
36
|
};
|
|
@@ -37,11 +37,11 @@ export const usePicker = ({
|
|
|
37
37
|
});
|
|
38
38
|
const providerProps = usePickerProvider({
|
|
39
39
|
props,
|
|
40
|
-
pickerValueResponse,
|
|
41
40
|
localeText,
|
|
42
41
|
valueManager,
|
|
43
42
|
variant,
|
|
44
|
-
views: pickerViewsResponse.views
|
|
43
|
+
views: pickerViewsResponse.views,
|
|
44
|
+
paramsFromUsePickerValue: pickerValueResponse.provider
|
|
45
45
|
});
|
|
46
46
|
return {
|
|
47
47
|
// Picker value
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
3
4
|
import { useUtils } from "../useUtils.js";
|
|
@@ -36,31 +37,28 @@ export const usePickerOrientation = (views, customOrientation) => {
|
|
|
36
37
|
export function usePickerProvider(parameters) {
|
|
37
38
|
const {
|
|
38
39
|
props,
|
|
39
|
-
pickerValueResponse,
|
|
40
40
|
valueManager,
|
|
41
41
|
localeText,
|
|
42
42
|
variant,
|
|
43
|
-
views
|
|
43
|
+
views,
|
|
44
|
+
paramsFromUsePickerValue
|
|
44
45
|
} = parameters;
|
|
45
46
|
const utils = useUtils();
|
|
46
47
|
const orientation = usePickerOrientation(views, props.orientation);
|
|
47
48
|
const ownerState = React.useMemo(() => ({
|
|
48
|
-
isPickerValueEmpty: valueManager.areValuesEqual(utils,
|
|
49
|
-
isPickerOpen:
|
|
49
|
+
isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
|
|
50
|
+
isPickerOpen: paramsFromUsePickerValue.contextValue.open,
|
|
50
51
|
isPickerDisabled: props.disabled ?? false,
|
|
51
52
|
isPickerReadOnly: props.readOnly ?? false,
|
|
52
53
|
pickerOrientation: orientation,
|
|
53
54
|
pickerVariant: variant
|
|
54
|
-
}), [utils, valueManager,
|
|
55
|
-
const contextValue = React.useMemo(() => ({
|
|
56
|
-
onOpen: pickerValueResponse.actions.onOpen,
|
|
57
|
-
onClose: pickerValueResponse.actions.onClose,
|
|
58
|
-
open: pickerValueResponse.open,
|
|
55
|
+
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
56
|
+
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, {
|
|
59
57
|
disabled: props.disabled ?? false,
|
|
60
58
|
readOnly: props.readOnly ?? false,
|
|
61
59
|
variant,
|
|
62
60
|
orientation
|
|
63
|
-
}), [
|
|
61
|
+
}), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
64
62
|
const privateContextValue = React.useMemo(() => ({
|
|
65
63
|
ownerState
|
|
66
64
|
}), [ownerState]);
|
|
@@ -150,8 +150,8 @@ export const usePickerValue = ({
|
|
|
150
150
|
const utils = useUtils();
|
|
151
151
|
const adapter = useLocalizationContext();
|
|
152
152
|
const {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
open,
|
|
154
|
+
setOpen
|
|
155
155
|
} = useOpenState(props);
|
|
156
156
|
const {
|
|
157
157
|
timezone,
|
|
@@ -237,7 +237,7 @@ export const usePickerValue = ({
|
|
|
237
237
|
onAccept(action.value, getContext());
|
|
238
238
|
}
|
|
239
239
|
if (shouldClose) {
|
|
240
|
-
|
|
240
|
+
setOpen(false);
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
@@ -288,11 +288,11 @@ export const usePickerValue = ({
|
|
|
288
288
|
});
|
|
289
289
|
const handleOpen = useEventCallback(event => {
|
|
290
290
|
event.preventDefault();
|
|
291
|
-
|
|
291
|
+
setOpen(true);
|
|
292
292
|
});
|
|
293
293
|
const handleClose = useEventCallback(event => {
|
|
294
294
|
event?.preventDefault();
|
|
295
|
-
|
|
295
|
+
setOpen(false);
|
|
296
296
|
});
|
|
297
297
|
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
298
298
|
name: 'setValueFromView',
|
|
@@ -323,12 +323,12 @@ export const usePickerValue = ({
|
|
|
323
323
|
value: dateState.draft,
|
|
324
324
|
onChange: handleChangeFromField
|
|
325
325
|
};
|
|
326
|
-
const
|
|
326
|
+
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
327
327
|
const viewResponse = {
|
|
328
|
-
value:
|
|
328
|
+
value: valueWithoutError,
|
|
329
329
|
onChange: handleChange,
|
|
330
330
|
onClose: handleClose,
|
|
331
|
-
open
|
|
331
|
+
open
|
|
332
332
|
};
|
|
333
333
|
const isValid = testedValue => {
|
|
334
334
|
const error = validator({
|
|
@@ -340,16 +340,27 @@ export const usePickerValue = ({
|
|
|
340
340
|
return !valueManager.hasError(error);
|
|
341
341
|
};
|
|
342
342
|
const layoutResponse = _extends({}, actions, {
|
|
343
|
-
value:
|
|
343
|
+
value: valueWithoutError,
|
|
344
344
|
onChange: handleChange,
|
|
345
345
|
onSelectShortcut: handleSelectShortcut,
|
|
346
346
|
isValid
|
|
347
347
|
});
|
|
348
|
+
const contextValue = React.useMemo(() => {
|
|
349
|
+
return {
|
|
350
|
+
open,
|
|
351
|
+
setOpen
|
|
352
|
+
};
|
|
353
|
+
}, [open, setOpen]);
|
|
354
|
+
const providerParams = {
|
|
355
|
+
value: valueWithoutError,
|
|
356
|
+
contextValue
|
|
357
|
+
};
|
|
348
358
|
return {
|
|
349
|
-
open
|
|
359
|
+
open,
|
|
350
360
|
fieldProps: fieldResponse,
|
|
351
361
|
viewProps: viewResponse,
|
|
352
362
|
layoutProps: layoutResponse,
|
|
353
|
-
actions
|
|
363
|
+
actions,
|
|
364
|
+
provider: providerParams
|
|
354
365
|
};
|
|
355
366
|
};
|
|
@@ -11,11 +11,18 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
11
11
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
|
+
var _styles = require("@mui/material/styles");
|
|
14
15
|
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
|
15
16
|
var _DialogActions = _interopRequireDefault(require("@mui/material/DialogActions"));
|
|
16
17
|
var _usePickerTranslations = require("../hooks/usePickerTranslations");
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
19
|
const _excluded = ["onAccept", "onClear", "onCancel", "onSetToday", "actions"];
|
|
20
|
+
const PickersActionBarRoot = (0, _styles.styled)(_DialogActions.default, {
|
|
21
|
+
name: 'MuiPickersLayout',
|
|
22
|
+
slot: 'ActionBar',
|
|
23
|
+
overridesResolver: (_, styles) => styles.actionBar
|
|
24
|
+
})({});
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* Demos:
|
|
21
28
|
*
|
|
@@ -65,7 +72,7 @@ function PickersActionBar(props) {
|
|
|
65
72
|
return null;
|
|
66
73
|
}
|
|
67
74
|
});
|
|
68
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
75
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersActionBarRoot, (0, _extends2.default)({}, other, {
|
|
69
76
|
children: buttons
|
|
70
77
|
}));
|
|
71
78
|
}
|
|
@@ -10,6 +10,7 @@ exports.PickersShortcuts = PickersShortcuts;
|
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _styles = require("@mui/material/styles");
|
|
13
14
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
15
|
var _List = _interopRequireDefault(require("@mui/material/List"));
|
|
15
16
|
var _ListItem = _interopRequireDefault(require("@mui/material/ListItem"));
|
|
@@ -18,6 +19,12 @@ var _dimensions = require("../internals/constants/dimensions");
|
|
|
18
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
20
|
const _excluded = ["items", "changeImportance", "isLandscape", "onChange", "isValid"],
|
|
20
21
|
_excluded2 = ["getValue"];
|
|
22
|
+
const PickersShortcutsRoot = (0, _styles.styled)(_List.default, {
|
|
23
|
+
name: 'MuiPickersLayout',
|
|
24
|
+
slot: 'Shortcuts',
|
|
25
|
+
overridesResolver: (_, styles) => styles.shortcuts
|
|
26
|
+
})({});
|
|
27
|
+
|
|
21
28
|
/**
|
|
22
29
|
* Demos:
|
|
23
30
|
*
|
|
@@ -54,7 +61,7 @@ function PickersShortcuts(props) {
|
|
|
54
61
|
disabled: !isValid(newValue)
|
|
55
62
|
});
|
|
56
63
|
});
|
|
57
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
64
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersShortcutsRoot, (0, _extends2.default)({
|
|
58
65
|
dense: true,
|
|
59
66
|
sx: [{
|
|
60
67
|
maxHeight: _dimensions.VIEW_HEIGHT,
|
package/node/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const useOpenState = ({
|
|
|
12
12
|
onClose
|
|
13
13
|
}) => {
|
|
14
14
|
const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
|
|
15
|
-
const [openState,
|
|
15
|
+
const [openState, setOpenState] = React.useState(false);
|
|
16
16
|
|
|
17
17
|
// It is required to update inner state in useEffect in order to avoid situation when
|
|
18
18
|
// Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
|
|
@@ -21,23 +21,24 @@ const useOpenState = ({
|
|
|
21
21
|
if (typeof open !== 'boolean') {
|
|
22
22
|
throw new Error('You must not mix controlling and uncontrolled mode for `open` prop');
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
setOpenState(open);
|
|
25
25
|
}
|
|
26
26
|
}, [isControllingOpenProp, open]);
|
|
27
|
-
const
|
|
27
|
+
const setOpen = React.useCallback(action => {
|
|
28
|
+
const newOpen = typeof action === 'function' ? action(openState) : action;
|
|
28
29
|
if (!isControllingOpenProp) {
|
|
29
|
-
|
|
30
|
+
setOpenState(newOpen);
|
|
30
31
|
}
|
|
31
|
-
if (
|
|
32
|
+
if (newOpen && onOpen) {
|
|
32
33
|
onOpen();
|
|
33
34
|
}
|
|
34
|
-
if (!
|
|
35
|
+
if (!newOpen && onClose) {
|
|
35
36
|
onClose();
|
|
36
37
|
}
|
|
37
|
-
}, [isControllingOpenProp, onOpen, onClose]);
|
|
38
|
+
}, [isControllingOpenProp, onOpen, onClose, openState]);
|
|
38
39
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
open: openState,
|
|
41
|
+
setOpen
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
44
|
exports.useOpenState = useOpenState;
|
|
@@ -44,11 +44,11 @@ const usePicker = ({
|
|
|
44
44
|
});
|
|
45
45
|
const providerProps = (0, _usePickerProvider.usePickerProvider)({
|
|
46
46
|
props,
|
|
47
|
-
pickerValueResponse,
|
|
48
47
|
localeText,
|
|
49
48
|
valueManager,
|
|
50
49
|
variant,
|
|
51
|
-
views: pickerViewsResponse.views
|
|
50
|
+
views: pickerViewsResponse.views,
|
|
51
|
+
paramsFromUsePickerValue: pickerValueResponse.provider
|
|
52
52
|
});
|
|
53
53
|
return {
|
|
54
54
|
// Picker value
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.usePickerOrientation = void 0;
|
|
9
9
|
exports.usePickerProvider = usePickerProvider;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var React = _interopRequireWildcard(require("react"));
|
|
11
12
|
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
12
13
|
var _useUtils = require("../useUtils");
|
|
@@ -46,31 +47,28 @@ exports.usePickerOrientation = usePickerOrientation;
|
|
|
46
47
|
function usePickerProvider(parameters) {
|
|
47
48
|
const {
|
|
48
49
|
props,
|
|
49
|
-
pickerValueResponse,
|
|
50
50
|
valueManager,
|
|
51
51
|
localeText,
|
|
52
52
|
variant,
|
|
53
|
-
views
|
|
53
|
+
views,
|
|
54
|
+
paramsFromUsePickerValue
|
|
54
55
|
} = parameters;
|
|
55
56
|
const utils = (0, _useUtils.useUtils)();
|
|
56
57
|
const orientation = usePickerOrientation(views, props.orientation);
|
|
57
58
|
const ownerState = React.useMemo(() => ({
|
|
58
|
-
isPickerValueEmpty: valueManager.areValuesEqual(utils,
|
|
59
|
-
isPickerOpen:
|
|
59
|
+
isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
|
|
60
|
+
isPickerOpen: paramsFromUsePickerValue.contextValue.open,
|
|
60
61
|
isPickerDisabled: props.disabled ?? false,
|
|
61
62
|
isPickerReadOnly: props.readOnly ?? false,
|
|
62
63
|
pickerOrientation: orientation,
|
|
63
64
|
pickerVariant: variant
|
|
64
|
-
}), [utils, valueManager,
|
|
65
|
-
const contextValue = React.useMemo(() => ({
|
|
66
|
-
onOpen: pickerValueResponse.actions.onOpen,
|
|
67
|
-
onClose: pickerValueResponse.actions.onClose,
|
|
68
|
-
open: pickerValueResponse.open,
|
|
65
|
+
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
66
|
+
const contextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.contextValue, {
|
|
69
67
|
disabled: props.disabled ?? false,
|
|
70
68
|
readOnly: props.readOnly ?? false,
|
|
71
69
|
variant,
|
|
72
70
|
orientation
|
|
73
|
-
}), [
|
|
71
|
+
}), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
74
72
|
const privateContextValue = React.useMemo(() => ({
|
|
75
73
|
ownerState
|
|
76
74
|
}), [ownerState]);
|
|
@@ -158,8 +158,8 @@ const usePickerValue = ({
|
|
|
158
158
|
const utils = (0, _useUtils.useUtils)();
|
|
159
159
|
const adapter = (0, _useUtils.useLocalizationContext)();
|
|
160
160
|
const {
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
open,
|
|
162
|
+
setOpen
|
|
163
163
|
} = (0, _useOpenState.useOpenState)(props);
|
|
164
164
|
const {
|
|
165
165
|
timezone,
|
|
@@ -245,7 +245,7 @@ const usePickerValue = ({
|
|
|
245
245
|
onAccept(action.value, getContext());
|
|
246
246
|
}
|
|
247
247
|
if (shouldClose) {
|
|
248
|
-
|
|
248
|
+
setOpen(false);
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
@@ -296,11 +296,11 @@ const usePickerValue = ({
|
|
|
296
296
|
});
|
|
297
297
|
const handleOpen = (0, _useEventCallback.default)(event => {
|
|
298
298
|
event.preventDefault();
|
|
299
|
-
|
|
299
|
+
setOpen(true);
|
|
300
300
|
});
|
|
301
301
|
const handleClose = (0, _useEventCallback.default)(event => {
|
|
302
302
|
event?.preventDefault();
|
|
303
|
-
|
|
303
|
+
setOpen(false);
|
|
304
304
|
});
|
|
305
305
|
const handleChange = (0, _useEventCallback.default)((newValue, selectionState = 'partial') => updateDate({
|
|
306
306
|
name: 'setValueFromView',
|
|
@@ -331,12 +331,12 @@ const usePickerValue = ({
|
|
|
331
331
|
value: dateState.draft,
|
|
332
332
|
onChange: handleChangeFromField
|
|
333
333
|
};
|
|
334
|
-
const
|
|
334
|
+
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
335
335
|
const viewResponse = {
|
|
336
|
-
value:
|
|
336
|
+
value: valueWithoutError,
|
|
337
337
|
onChange: handleChange,
|
|
338
338
|
onClose: handleClose,
|
|
339
|
-
open
|
|
339
|
+
open
|
|
340
340
|
};
|
|
341
341
|
const isValid = testedValue => {
|
|
342
342
|
const error = validator({
|
|
@@ -348,17 +348,28 @@ const usePickerValue = ({
|
|
|
348
348
|
return !valueManager.hasError(error);
|
|
349
349
|
};
|
|
350
350
|
const layoutResponse = (0, _extends2.default)({}, actions, {
|
|
351
|
-
value:
|
|
351
|
+
value: valueWithoutError,
|
|
352
352
|
onChange: handleChange,
|
|
353
353
|
onSelectShortcut: handleSelectShortcut,
|
|
354
354
|
isValid
|
|
355
355
|
});
|
|
356
|
+
const contextValue = React.useMemo(() => {
|
|
357
|
+
return {
|
|
358
|
+
open,
|
|
359
|
+
setOpen
|
|
360
|
+
};
|
|
361
|
+
}, [open, setOpen]);
|
|
362
|
+
const providerParams = {
|
|
363
|
+
value: valueWithoutError,
|
|
364
|
+
contextValue
|
|
365
|
+
};
|
|
356
366
|
return {
|
|
357
|
-
open
|
|
367
|
+
open,
|
|
358
368
|
fieldProps: fieldResponse,
|
|
359
369
|
viewProps: viewResponse,
|
|
360
370
|
layoutProps: layoutResponse,
|
|
361
|
-
actions
|
|
371
|
+
actions,
|
|
372
|
+
provider: providerParams
|
|
362
373
|
};
|
|
363
374
|
};
|
|
364
375
|
exports.usePickerValue = usePickerValue;
|