@mui/x-date-pickers 8.0.0-alpha.2 → 8.0.0-alpha.4

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/DateField/useDateField.d.ts +1 -1
  3. package/DatePicker/DatePickerToolbar.js +8 -9
  4. package/DateTimeField/useDateTimeField.d.ts +1 -1
  5. package/DateTimePicker/DateTimePickerToolbar.d.ts +6 -2
  6. package/DateTimePicker/DateTimePickerToolbar.js +53 -39
  7. package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
  8. package/DigitalClock/DigitalClock.js +13 -11
  9. package/DigitalClock/DigitalClock.types.d.ts +8 -2
  10. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +8 -7
  11. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +12 -10
  12. package/PickersActionBar/PickersActionBar.js +8 -1
  13. package/PickersLayout/PickersLayout.js +2 -2
  14. package/PickersLayout/PickersLayout.types.d.ts +4 -2
  15. package/PickersLayout/usePickerLayout.js +3 -3
  16. package/PickersShortcuts/PickersShortcuts.js +8 -1
  17. package/README.md +1 -1
  18. package/TimeClock/Clock.js +18 -21
  19. package/TimeClock/ClockNumber.js +15 -11
  20. package/TimeClock/ClockPointer.d.ts +6 -1
  21. package/TimeClock/ClockPointer.js +14 -10
  22. package/TimeClock/TimeClock.js +9 -8
  23. package/TimeField/useTimeField.d.ts +1 -1
  24. package/TimePicker/TimePickerToolbar.js +14 -17
  25. package/hooks/useClearableField.d.ts +5 -3
  26. package/hooks/useClearableField.js +4 -2
  27. package/index.js +1 -1
  28. package/internals/components/PickerProvider.d.ts +2 -15
  29. package/internals/components/PickersPopper.d.ts +11 -7
  30. package/internals/components/PickersPopper.js +18 -20
  31. package/internals/components/PickersToolbar.js +15 -12
  32. package/internals/components/PickersToolbarButton.js +4 -6
  33. package/internals/components/PickersToolbarText.js +11 -13
  34. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +3 -2
  35. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +3 -2
  36. package/internals/hooks/useOpenState.d.ts +3 -2
  37. package/internals/hooks/useOpenState.js +10 -9
  38. package/internals/hooks/usePicker/usePicker.js +3 -3
  39. package/internals/hooks/usePicker/usePicker.types.d.ts +3 -2
  40. package/internals/hooks/usePicker/usePickerProvider.d.ts +17 -6
  41. package/internals/hooks/usePicker/usePickerProvider.js +14 -12
  42. package/internals/hooks/usePicker/usePickerValue.js +22 -11
  43. package/internals/hooks/usePicker/usePickerValue.types.d.ts +26 -0
  44. package/internals/hooks/usePicker/usePickerViews.d.ts +5 -15
  45. package/internals/hooks/usePicker/usePickerViews.js +5 -6
  46. package/internals/hooks/useToolbarOwnerState.d.ts +10 -0
  47. package/internals/hooks/useToolbarOwnerState.js +13 -0
  48. package/internals/index.d.ts +5 -1
  49. package/internals/index.js +3 -1
  50. package/internals/models/common.d.ts +1 -1
  51. package/locales/roRO.js +15 -18
  52. package/modern/DatePicker/DatePickerToolbar.js +8 -9
  53. package/modern/DateTimePicker/DateTimePickerToolbar.js +53 -39
  54. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
  55. package/modern/DigitalClock/DigitalClock.js +13 -11
  56. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +8 -7
  57. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +12 -10
  58. package/modern/PickersActionBar/PickersActionBar.js +8 -1
  59. package/modern/PickersLayout/PickersLayout.js +2 -2
  60. package/modern/PickersLayout/usePickerLayout.js +3 -3
  61. package/modern/PickersShortcuts/PickersShortcuts.js +8 -1
  62. package/modern/TimeClock/Clock.js +18 -21
  63. package/modern/TimeClock/ClockNumber.js +15 -11
  64. package/modern/TimeClock/ClockPointer.js +14 -10
  65. package/modern/TimeClock/TimeClock.js +9 -8
  66. package/modern/TimePicker/TimePickerToolbar.js +14 -17
  67. package/modern/hooks/useClearableField.js +4 -2
  68. package/modern/index.js +1 -1
  69. package/modern/internals/components/PickersPopper.js +18 -20
  70. package/modern/internals/components/PickersToolbar.js +15 -12
  71. package/modern/internals/components/PickersToolbarButton.js +4 -6
  72. package/modern/internals/components/PickersToolbarText.js +11 -13
  73. package/modern/internals/hooks/useOpenState.js +10 -9
  74. package/modern/internals/hooks/usePicker/usePicker.js +3 -3
  75. package/modern/internals/hooks/usePicker/usePickerProvider.js +14 -12
  76. package/modern/internals/hooks/usePicker/usePickerValue.js +22 -11
  77. package/modern/internals/hooks/usePicker/usePickerViews.js +5 -6
  78. package/modern/internals/hooks/useToolbarOwnerState.js +13 -0
  79. package/modern/internals/index.js +3 -1
  80. package/modern/locales/roRO.js +15 -18
  81. package/node/DatePicker/DatePickerToolbar.js +8 -9
  82. package/node/DateTimePicker/DateTimePickerToolbar.js +54 -39
  83. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
  84. package/node/DigitalClock/DigitalClock.js +13 -11
  85. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +8 -7
  86. package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +12 -10
  87. package/node/PickersActionBar/PickersActionBar.js +8 -1
  88. package/node/PickersLayout/PickersLayout.js +2 -2
  89. package/node/PickersLayout/usePickerLayout.js +3 -3
  90. package/node/PickersShortcuts/PickersShortcuts.js +8 -1
  91. package/node/TimeClock/Clock.js +18 -21
  92. package/node/TimeClock/ClockNumber.js +15 -11
  93. package/node/TimeClock/ClockPointer.js +14 -10
  94. package/node/TimeClock/TimeClock.js +9 -8
  95. package/node/TimePicker/TimePickerToolbar.js +14 -17
  96. package/node/hooks/useClearableField.js +4 -2
  97. package/node/index.js +1 -1
  98. package/node/internals/components/PickersPopper.js +18 -20
  99. package/node/internals/components/PickersToolbar.js +15 -12
  100. package/node/internals/components/PickersToolbarButton.js +4 -6
  101. package/node/internals/components/PickersToolbarText.js +10 -12
  102. package/node/internals/hooks/useOpenState.js +10 -9
  103. package/node/internals/hooks/usePicker/usePicker.js +3 -3
  104. package/node/internals/hooks/usePicker/usePickerProvider.js +15 -13
  105. package/node/internals/hooks/usePicker/usePickerValue.js +22 -11
  106. package/node/internals/hooks/usePicker/usePickerViews.js +5 -6
  107. package/node/internals/hooks/useToolbarOwnerState.js +21 -0
  108. package/node/internals/index.js +15 -1
  109. package/node/locales/roRO.js +15 -18
  110. package/package.json +1 -1
@@ -1,17 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["children", "className", "toolbarTitle", "hidden", "titleId", "isLandscape", "classes", "landscapeDirection"];
3
+ const _excluded = ["children", "className", "classes", "toolbarTitle", "hidden", "titleId", "isLandscape", "classes", "landscapeDirection"];
4
4
  import * as React from 'react';
5
5
  import clsx from 'clsx';
6
6
  import Typography from '@mui/material/Typography';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import composeClasses from '@mui/utils/composeClasses';
9
+ import { shouldForwardProp } from '@mui/system/createStyled';
9
10
  import { getPickersToolbarUtilityClass } from "./pickersToolbarClasses.js";
11
+ import { useToolbarOwnerState } from "../hooks/useToolbarOwnerState.js";
10
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- const useUtilityClasses = ownerState => {
12
- const {
13
- classes
14
- } = ownerState;
13
+ const useUtilityClasses = classes => {
15
14
  const slots = {
16
15
  root: ['root'],
17
16
  content: ['content']
@@ -32,7 +31,7 @@ const PickersToolbarRoot = styled('div', {
32
31
  padding: theme.spacing(2, 3),
33
32
  variants: [{
34
33
  props: {
35
- isLandscape: true
34
+ pickerOrientation: 'landscape'
36
35
  },
37
36
  style: {
38
37
  height: 'auto',
@@ -46,7 +45,8 @@ const PickersToolbarRoot = styled('div', {
46
45
  const PickersToolbarContent = styled('div', {
47
46
  name: 'MuiPickersToolbar',
48
47
  slot: 'Content',
49
- overridesResolver: (props, styles) => styles.content
48
+ overridesResolver: (props, styles) => styles.content,
49
+ shouldForwardProp: prop => shouldForwardProp(prop) && prop !== 'landscapeDirection'
50
50
  })({
51
51
  display: 'flex',
52
52
  flexWrap: 'wrap',
@@ -57,7 +57,7 @@ const PickersToolbarContent = styled('div', {
57
57
  flexDirection: 'row',
58
58
  variants: [{
59
59
  props: {
60
- isLandscape: true
60
+ pickerOrientation: 'landscape'
61
61
  },
62
62
  style: {
63
63
  justifyContent: 'flex-start',
@@ -66,7 +66,7 @@ const PickersToolbarContent = styled('div', {
66
66
  }
67
67
  }, {
68
68
  props: {
69
- isLandscape: true,
69
+ pickerOrientation: 'landscape',
70
70
  landscapeDirection: 'row'
71
71
  },
72
72
  style: {
@@ -82,13 +82,15 @@ export const PickersToolbar = /*#__PURE__*/React.forwardRef(function PickersTool
82
82
  const {
83
83
  children,
84
84
  className,
85
+ classes: classesProp,
85
86
  toolbarTitle,
86
87
  hidden,
87
- titleId
88
+ titleId,
89
+ landscapeDirection
88
90
  } = props,
89
91
  other = _objectWithoutPropertiesLoose(props, _excluded);
90
- const ownerState = props;
91
- const classes = useUtilityClasses(ownerState);
92
+ const ownerState = useToolbarOwnerState();
93
+ const classes = useUtilityClasses(classesProp);
92
94
  if (hidden) {
93
95
  return null;
94
96
  }
@@ -105,6 +107,7 @@ export const PickersToolbar = /*#__PURE__*/React.forwardRef(function PickersTool
105
107
  }), /*#__PURE__*/_jsx(PickersToolbarContent, {
106
108
  className: classes.content,
107
109
  ownerState: ownerState,
110
+ landscapeDirection: landscapeDirection,
108
111
  children: children
109
112
  })]
110
113
  }));
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["align", "className", "selected", "typographyClassName", "value", "variant", "width"];
3
+ const _excluded = ["align", "className", "classes", "selected", "typographyClassName", "value", "variant", "width"];
4
4
  import * as React from 'react';
5
5
  import clsx from 'clsx';
6
6
  import Button from '@mui/material/Button';
@@ -9,10 +9,7 @@ import composeClasses from '@mui/utils/composeClasses';
9
9
  import { PickersToolbarText } from "./PickersToolbarText.js";
10
10
  import { getPickersToolbarUtilityClass } from "./pickersToolbarClasses.js";
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
- const useUtilityClasses = ownerState => {
13
- const {
14
- classes
15
- } = ownerState;
12
+ const useUtilityClasses = classes => {
16
13
  const slots = {
17
14
  root: ['root']
18
15
  };
@@ -35,6 +32,7 @@ export const PickersToolbarButton = /*#__PURE__*/React.forwardRef(function Picke
35
32
  const {
36
33
  align,
37
34
  className,
35
+ classes: classesProp,
38
36
  selected,
39
37
  typographyClassName,
40
38
  value,
@@ -42,7 +40,7 @@ export const PickersToolbarButton = /*#__PURE__*/React.forwardRef(function Picke
42
40
  width
43
41
  } = props,
44
42
  other = _objectWithoutPropertiesLoose(props, _excluded);
45
- const classes = useUtilityClasses(props);
43
+ const classes = useUtilityClasses(classesProp);
46
44
  return /*#__PURE__*/_jsx(PickersToolbarButtonRoot, _extends({
47
45
  variant: "text",
48
46
  ref: ref,
@@ -1,35 +1,29 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["className", "selected", "value"];
3
+ const _excluded = ["className", "classes", "selected", "value"];
4
4
  import * as React from 'react';
5
5
  import clsx from 'clsx';
6
6
  import Typography from '@mui/material/Typography';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import composeClasses from '@mui/utils/composeClasses';
9
- import { getPickersToolbarTextUtilityClass, pickersToolbarTextClasses } from "./pickersToolbarTextClasses.js";
9
+ import { getPickersToolbarTextUtilityClass } from "./pickersToolbarTextClasses.js";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
- const useUtilityClasses = ownerState => {
12
- const {
13
- classes,
14
- selected
15
- } = ownerState;
11
+ const useUtilityClasses = classes => {
16
12
  const slots = {
17
- root: ['root', selected && 'selected']
13
+ root: ['root']
18
14
  };
19
15
  return composeClasses(slots, getPickersToolbarTextUtilityClass, classes);
20
16
  };
21
17
  const PickersToolbarTextRoot = styled(Typography, {
22
18
  name: 'MuiPickersToolbarText',
23
19
  slot: 'Root',
24
- overridesResolver: (_, styles) => [styles.root, {
25
- [`&.${pickersToolbarTextClasses.selected}`]: styles.selected
26
- }]
20
+ overridesResolver: (_, styles) => [styles.root]
27
21
  })(({
28
22
  theme
29
23
  }) => ({
30
24
  transition: theme.transitions.create('color'),
31
25
  color: (theme.vars || theme).palette.text.secondary,
32
- [`&.${pickersToolbarTextClasses.selected}`]: {
26
+ [`&[data-selected]`]: {
33
27
  color: (theme.vars || theme).palette.text.primary
34
28
  }
35
29
  }));
@@ -40,14 +34,18 @@ export const PickersToolbarText = /*#__PURE__*/React.forwardRef(function Pickers
40
34
  });
41
35
  const {
42
36
  className,
37
+ classes: classesProp,
38
+ selected,
43
39
  value
44
40
  } = props,
45
41
  other = _objectWithoutPropertiesLoose(props, _excluded);
46
- const classes = useUtilityClasses(props);
42
+ const classes = useUtilityClasses(classesProp);
47
43
  return /*#__PURE__*/_jsx(PickersToolbarTextRoot, _extends({
48
44
  ref: ref,
49
45
  className: clsx(classes.root, className),
50
46
  component: "span"
47
+ }, selected && {
48
+ 'data-selected': true
51
49
  }, other, {
52
50
  children: value
53
51
  }));
@@ -9,10 +9,11 @@ import { UsePickerParams } from '../usePicker';
9
9
  import { FieldOwnerState, PickerFieldSlotProps, PickerOwnerState, PickerValidDate } from '../../../models';
10
10
  import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from '../../../PickersLayout/PickersLayout.types';
11
11
  import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue.types';
12
- import { UsePickerViewsNonStaticProps, UsePickerViewsProps } from '../usePicker/usePickerViews';
12
+ import { UsePickerViewsProps } from '../usePicker/usePickerViews';
13
13
  import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
14
14
  import { UseClearableFieldSlots, UseClearableFieldSlotProps } from '../../../hooks/useClearableField';
15
15
  import { PickersTextFieldProps } from '../../../PickersTextField';
16
+ import { UsePickerProviderNonStaticProps } from '../usePicker/usePickerProvider';
16
17
  export interface UseDesktopPickerSlots<TView extends DateOrTimeViewWithMeridiem> extends Pick<PickersPopperSlots, 'desktopPaper' | 'desktopTransition' | 'desktopTrapFocus' | 'popper'>, ExportedPickersLayoutSlots<PickerValue, TView>, UseClearableFieldSlots {
17
18
  /**
18
19
  * Component used to enter the date with the keyboard.
@@ -47,7 +48,7 @@ export interface ExportedUseDesktopPickerSlotProps<TView extends DateOrTimeViewW
47
48
  openPickerButton?: SlotComponentPropsFromProps<IconButtonProps, {}, PickerOwnerState>;
48
49
  openPickerIcon?: SlotComponentPropsFromProps<Record<string, any>, {}, PickerOwnerState>;
49
50
  }
50
- export interface DesktopOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerViewsNonStaticProps {
51
+ export interface DesktopOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {
51
52
  /**
52
53
  * If `true`, the `input` element is focused during the first mount.
53
54
  * @default false
@@ -7,9 +7,10 @@ import { UsePickerParams } from '../usePicker';
7
7
  import { FieldOwnerState, PickerFieldSlotProps, PickerOwnerState, PickerValidDate } from '../../../models';
8
8
  import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from '../../../PickersLayout/PickersLayout.types';
9
9
  import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue.types';
10
- import { UsePickerViewsNonStaticProps, UsePickerViewsProps } from '../usePicker/usePickerViews';
10
+ import { UsePickerViewsProps } from '../usePicker/usePickerViews';
11
11
  import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
12
12
  import { PickersTextFieldProps } from '../../../PickersTextField';
13
+ import { UsePickerProviderNonStaticProps } from '../usePicker/usePickerProvider';
13
14
  export interface UseMobilePickerSlots<TView extends DateOrTimeViewWithMeridiem> extends PickersModalDialogSlots, ExportedPickersLayoutSlots<PickerValue, TView> {
14
15
  /**
15
16
  * Component used to enter the date with the keyboard.
@@ -27,7 +28,7 @@ export interface ExportedUseMobilePickerSlotProps<TView extends DateOrTimeViewWi
27
28
  }
28
29
  export interface UseMobilePickerSlotProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseMobilePickerSlotProps<TView, TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue, TView>, 'toolbar'> {
29
30
  }
30
- export interface MobileOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerViewsNonStaticProps {
31
+ export interface MobileOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {
31
32
  }
32
33
  export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerViewsProps<any, TView, any, any>> extends BasePickerProps<PickerValue, TView, TError, TExternalProps, {}>, MakeRequired<MobileOnlyPickerProps, 'format'> {
33
34
  /**
@@ -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
- isOpen: boolean;
8
- setIsOpen: (newIsOpen: boolean) => void;
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, setIsOpenState] = React.useState(false);
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
- setIsOpenState(open);
17
+ setOpenState(open);
18
18
  }
19
19
  }, [isControllingOpenProp, open]);
20
- const setIsOpen = React.useCallback(newIsOpen => {
20
+ const setOpen = React.useCallback(action => {
21
+ const newOpen = typeof action === 'function' ? action(openState) : action;
21
22
  if (!isControllingOpenProp) {
22
- setIsOpenState(newIsOpen);
23
+ setOpenState(newOpen);
23
24
  }
24
- if (newIsOpen && onOpen) {
25
+ if (newOpen && onOpen) {
25
26
  onOpen();
26
27
  }
27
- if (!newIsOpen && onClose) {
28
+ if (!newOpen && onClose) {
28
29
  onClose();
29
30
  }
30
- }, [isControllingOpenProp, onOpen, onClose]);
31
+ }, [isControllingOpenProp, onOpen, onClose, openState]);
31
32
  return {
32
- isOpen: openState,
33
- setIsOpen
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
+ paramsFromUsePickerValue: pickerValueResponse.provider,
44
+ paramsFromUsePickerViews: pickerViewsResponse.provider
45
45
  });
46
46
  return {
47
47
  // Picker value
@@ -50,7 +50,7 @@ export const usePicker = ({
50
50
  fieldProps: pickerValueResponse.fieldProps,
51
51
  // Picker views
52
52
  renderCurrentView: pickerViewsResponse.renderCurrentView,
53
- hasUIView: pickerViewsResponse.hasUIView,
53
+ hasUIView: pickerViewsResponse.provider.hasUIView,
54
54
  shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
55
55
  // Picker layout
56
56
  layoutProps: _extends({}, pickerViewsResponse.layoutProps, pickerValueResponse.layoutProps),
@@ -10,11 +10,12 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
10
10
  }
11
11
  export interface UsePickerProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueProps<TValue, TError>, UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerProviderProps {
12
12
  }
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'> {
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, TView>, 'localeText'> {
14
14
  props: TExternalProps;
15
15
  }
16
- export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Omit<UsePickerValueResponse<TValue, TError>, 'viewProps' | 'layoutProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps' | 'views'> {
16
+ export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<UsePickerValueResponse<TValue, TError>, 'open' | 'actions' | 'fieldProps'>, Pick<UsePickerViewsResponse<TView>, 'shouldRestoreFocus' | 'renderCurrentView'> {
17
17
  ownerState: PickerOwnerState;
18
18
  providerProps: UsePickerProviderReturnValue;
19
19
  layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps'] & UsePickerViewsResponse<TView>['layoutProps'];
20
+ hasUIView: boolean;
20
21
  }
@@ -1,20 +1,21 @@
1
- import { PickerValueManager, UsePickerValueResponse } from './usePickerValue.types';
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';
5
+ import { UsePickerViewsProviderParams } from './usePickerViews';
5
6
  export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined) => PickerOrientation;
6
- export declare function usePickerProvider<TValue extends PickerValidValue>(parameters: UsePickerProviderParameters<TValue>): UsePickerProviderReturnValue;
7
- export interface UsePickerProviderParameters<TValue extends PickerValidValue> extends Pick<PickerProviderProps, 'localeText'> {
7
+ export declare function usePickerProvider<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem>(parameters: UsePickerProviderParameters<TValue, TView>): UsePickerProviderReturnValue;
8
+ export interface UsePickerProviderParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem> extends Pick<PickerProviderProps, 'localeText'> {
8
9
  props: UsePickerProps<TValue, any, any, any, any>;
9
- pickerValueResponse: UsePickerValueResponse<TValue, any>;
10
10
  valueManager: PickerValueManager<TValue, any>;
11
11
  variant: PickerVariant;
12
- views: readonly DateOrTimeViewWithMeridiem[];
12
+ paramsFromUsePickerValue: UsePickerValueProviderParams<TValue>;
13
+ paramsFromUsePickerViews: UsePickerViewsProviderParams<TView>;
13
14
  }
14
15
  export interface UsePickerProviderReturnValue extends Omit<PickerProviderProps, 'children'> {
15
16
  }
16
17
  /**
17
- * Props used to create the private context.
18
+ * Props used to create the picker's contexts.
18
19
  * Those props are exposed on all the pickers.
19
20
  */
20
21
  export interface UsePickerProviderProps extends FormProps {
@@ -23,3 +24,13 @@ export interface UsePickerProviderProps extends FormProps {
23
24
  */
24
25
  orientation?: PickerOrientation;
25
26
  }
27
+ /**
28
+ * Props used to create the picker's contexts and that are not available on static pickers.
29
+ */
30
+ export interface UsePickerProviderNonStaticProps {
31
+ /**
32
+ * If `true`, the open picker button will not be rendered (renders only the field).
33
+ * @default false
34
+ */
35
+ disableOpenPicker?: boolean;
36
+ }
@@ -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
+ paramsFromUsePickerValue,
44
+ paramsFromUsePickerViews
44
45
  } = parameters;
45
46
  const utils = useUtils();
46
- const orientation = usePickerOrientation(views, props.orientation);
47
+ const orientation = usePickerOrientation(paramsFromUsePickerViews.views, props.orientation);
47
48
  const ownerState = React.useMemo(() => ({
48
- isPickerValueEmpty: valueManager.areValuesEqual(utils, pickerValueResponse.viewProps.value, valueManager.emptyValue),
49
- isPickerOpen: pickerValueResponse.open,
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, pickerValueResponse.viewProps.value, pickerValueResponse.open, orientation, variant, props.disabled, props.readOnly]);
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
- }), [pickerValueResponse.actions.onOpen, pickerValueResponse.actions.onClose, pickerValueResponse.open, variant, orientation, props.disabled, props.readOnly]);
61
+ }), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
64
62
  const privateContextValue = React.useMemo(() => ({
65
63
  ownerState
66
64
  }), [ownerState]);
@@ -72,6 +70,10 @@ export function usePickerProvider(parameters) {
72
70
  }
73
71
 
74
72
  /**
75
- * Props used to create the private context.
73
+ * Props used to create the picker's contexts.
76
74
  * Those props are exposed on all the pickers.
75
+ */
76
+
77
+ /**
78
+ * Props used to create the picker's contexts and that are not available on static pickers.
77
79
  */
@@ -150,8 +150,8 @@ export const usePickerValue = ({
150
150
  const utils = useUtils();
151
151
  const adapter = useLocalizationContext();
152
152
  const {
153
- isOpen,
154
- setIsOpen
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
- setIsOpen(false);
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
- setIsOpen(true);
291
+ setOpen(true);
292
292
  });
293
293
  const handleClose = useEventCallback(event => {
294
294
  event?.preventDefault();
295
- setIsOpen(false);
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 viewValue = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
326
+ const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
327
327
  const viewResponse = {
328
- value: viewValue,
328
+ value: valueWithoutError,
329
329
  onChange: handleChange,
330
330
  onClose: handleClose,
331
- open: isOpen
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: viewValue,
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: isOpen,
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
  }
@@ -39,16 +39,6 @@ export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView
39
39
  */
40
40
  referenceDate?: PickerValidDate;
41
41
  }
42
- /**
43
- * Props used to handle the views of the pickers.
44
- */
45
- export interface UsePickerViewsNonStaticProps {
46
- /**
47
- * If `true`, the open picker button will not be rendered (renders only the field).
48
- * @default false
49
- */
50
- disableOpenPicker?: boolean;
51
- }
52
42
  /**
53
43
  * Props used to handle the value of the pickers.
54
44
  */
@@ -73,20 +63,20 @@ export interface UsePickerViewParams<TValue extends PickerValidValue, TView exte
73
63
  rendererInterceptor?: (viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps, TAdditionalProps>, popperView: TView, rendererProps: PickerViewsRendererProps<TValue, TView, TExternalProps, TAdditionalProps>) => React.ReactNode;
74
64
  }
75
65
  export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem> {
76
- /**
77
- * Indicates if the the picker has at least one view that should be rendered in UI.
78
- */
79
- hasUIView: boolean;
80
- views: readonly TView[];
81
66
  renderCurrentView: () => React.ReactNode;
82
67
  shouldRestoreFocus: () => boolean;
83
68
  layoutProps: UsePickerViewsLayoutResponse<TView>;
69
+ provider: UsePickerViewsProviderParams<TView>;
84
70
  }
85
71
  export interface UsePickerViewsLayoutResponse<TView extends DateOrTimeViewWithMeridiem> {
86
72
  view: TView | null;
87
73
  onViewChange: (view: TView) => void;
88
74
  views: readonly TView[];
89
75
  }
76
+ export interface UsePickerViewsProviderParams<TView extends DateOrTimeViewWithMeridiem> {
77
+ hasUIView: boolean;
78
+ views: readonly TView[];
79
+ }
90
80
  /**
91
81
  * Manage the views of all the pickers:
92
82
  * - Handles the view switch
@@ -11,10 +11,6 @@ import { isTimeView } from "../../utils/time-utils.js";
11
11
  * Props used to handle the views that are common to all pickers.
12
12
  */
13
13
 
14
- /**
15
- * Props used to handle the views of the pickers.
16
- */
17
-
18
14
  /**
19
15
  * Props used to handle the value of the pickers.
20
16
  */
@@ -132,11 +128,14 @@ export const usePickerViews = ({
132
128
  view: popperView,
133
129
  onViewChange: setView
134
130
  };
135
- return {
131
+ const providerParams = {
136
132
  hasUIView,
137
- views,
133
+ views
134
+ };
135
+ return {
138
136
  shouldRestoreFocus,
139
137
  layoutProps,
138
+ provider: providerParams,
140
139
  renderCurrentView: () => {
141
140
  if (popperView == null) {
142
141
  return null;
@@ -0,0 +1,10 @@
1
+ import { PickerOwnerState } from '../../models';
2
+ export declare function useToolbarOwnerState(): PickerToolbarOwnerState;
3
+ export interface PickerToolbarOwnerState extends PickerOwnerState {
4
+ /**
5
+ * The direction of the toolbar.
6
+ * Is equal to "ltr" when the toolbar is in left-to-right direction.
7
+ * Is equal to "rtl" when the toolbar is in right-to-left direction.
8
+ */
9
+ toolbarDirection: 'ltr' | 'rtl';
10
+ }
@@ -0,0 +1,13 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { useRtl } from '@mui/system/RtlProvider';
4
+ import { usePickerPrivateContext } from "./usePickerPrivateContext.js";
5
+ export function useToolbarOwnerState() {
6
+ const {
7
+ ownerState: pickerOwnerState
8
+ } = usePickerPrivateContext();
9
+ const isRtl = useRtl();
10
+ return React.useMemo(() => _extends({}, pickerOwnerState, {
11
+ toolbarDirection: isRtl ? 'rtl' : 'ltr'
12
+ }), [pickerOwnerState, isRtl]);
13
+ }