@mui/x-date-pickers-pro 6.0.3 → 6.1.0

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 (111) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/DateRangeCalendar/useDragRange.d.ts +1 -1
  3. package/DateRangePicker/DateRangePicker.js +12 -0
  4. package/DateRangePicker/DateRangePickerToolbar.d.ts +1 -1
  5. package/DateRangePicker/shared.d.ts +1 -1
  6. package/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
  7. package/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
  8. package/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -0
  9. package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +1 -1
  10. package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -0
  11. package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +1 -1
  12. package/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -0
  13. package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +1 -1
  14. package/README.md +2 -2
  15. package/SingleInputDateRangeField/SingleInputDateRangeField.d.ts +1 -0
  16. package/SingleInputDateRangeField/SingleInputDateRangeField.js +23 -11
  17. package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.d.ts +1 -0
  18. package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +27 -15
  19. package/SingleInputTimeRangeField/SingleInputTimeRangeField.d.ts +1 -0
  20. package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +27 -15
  21. package/dateRangeViewRenderers/dateRangeViewRenderers.d.ts +1 -1
  22. package/index.js +1 -1
  23. package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.d.ts +1 -1
  24. package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +32 -40
  25. package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.types.d.ts +9 -29
  26. package/internal/hooks/useEnrichedRangePickerFieldProps.d.ts +53 -0
  27. package/internal/hooks/useEnrichedRangePickerFieldProps.js +202 -0
  28. package/internal/hooks/useMobileRangePicker/useMobileRangePicker.d.ts +1 -1
  29. package/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +36 -39
  30. package/internal/hooks/useMobileRangePicker/useMobileRangePicker.types.d.ts +9 -28
  31. package/internal/hooks/useMultiInputRangeField/useMultiInputDateRangeField.d.ts +1 -1
  32. package/internal/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.d.ts +1 -1
  33. package/internal/hooks/useMultiInputRangeField/useMultiInputRangeField.types.d.ts +3 -3
  34. package/internal/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.d.ts +1 -1
  35. package/internal/hooks/useRangePosition.d.ts +4 -0
  36. package/internal/hooks/useRangePosition.js +16 -1
  37. package/internal/hooks/useStaticRangePicker/useStaticRangePicker.d.ts +1 -1
  38. package/internal/hooks/useStaticRangePicker/useStaticRangePicker.types.d.ts +3 -2
  39. package/internal/hooks/validation/useDateRangeValidation.d.ts +2 -1
  40. package/internal/hooks/validation/useDateTimeRangeValidation.d.ts +2 -1
  41. package/internal/hooks/validation/useTimeRangeValidation.d.ts +2 -1
  42. package/internal/models/fields.d.ts +7 -2
  43. package/internal/models/index.d.ts +1 -0
  44. package/internal/models/index.js +2 -1
  45. package/internal/models/rangePickerProps.d.ts +17 -0
  46. package/internal/models/rangePickerProps.js +1 -0
  47. package/internal/utils/date-range-manager.d.ts +1 -1
  48. package/internal/utils/date-utils.d.ts +1 -1
  49. package/internal/utils/releaseInfo.js +1 -1
  50. package/internal/utils/valueManagers.d.ts +1 -1
  51. package/internal/utils/valueManagers.js +23 -21
  52. package/legacy/DateRangePicker/DateRangePicker.js +12 -0
  53. package/legacy/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
  54. package/legacy/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
  55. package/legacy/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -0
  56. package/legacy/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -0
  57. package/legacy/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -0
  58. package/legacy/SingleInputDateRangeField/SingleInputDateRangeField.js +20 -10
  59. package/legacy/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +24 -14
  60. package/legacy/SingleInputTimeRangeField/SingleInputTimeRangeField.js +24 -14
  61. package/legacy/index.js +1 -1
  62. package/legacy/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +32 -40
  63. package/legacy/internal/hooks/useEnrichedRangePickerFieldProps.js +200 -0
  64. package/legacy/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +36 -39
  65. package/legacy/internal/hooks/useRangePosition.js +16 -1
  66. package/legacy/internal/models/index.js +2 -1
  67. package/legacy/internal/models/rangePickerProps.js +1 -0
  68. package/legacy/internal/utils/releaseInfo.js +1 -1
  69. package/legacy/internal/utils/valueManagers.js +24 -22
  70. package/modern/DateRangePicker/DateRangePicker.js +12 -0
  71. package/modern/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
  72. package/modern/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
  73. package/modern/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -0
  74. package/modern/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -0
  75. package/modern/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -0
  76. package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +23 -11
  77. package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +27 -15
  78. package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +27 -15
  79. package/modern/index.js +1 -1
  80. package/modern/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +30 -38
  81. package/modern/internal/hooks/useEnrichedRangePickerFieldProps.js +195 -0
  82. package/modern/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +35 -38
  83. package/modern/internal/hooks/useRangePosition.js +16 -1
  84. package/modern/internal/models/index.js +2 -1
  85. package/modern/internal/models/rangePickerProps.js +1 -0
  86. package/modern/internal/utils/releaseInfo.js +1 -1
  87. package/modern/internal/utils/valueManagers.js +23 -21
  88. package/node/DateRangePicker/DateRangePicker.js +12 -0
  89. package/node/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
  90. package/node/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
  91. package/node/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -0
  92. package/node/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -0
  93. package/node/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -0
  94. package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +23 -11
  95. package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +26 -14
  96. package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +26 -14
  97. package/node/index.js +1 -1
  98. package/node/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +29 -37
  99. package/node/internal/hooks/useEnrichedRangePickerFieldProps.js +205 -0
  100. package/node/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +34 -37
  101. package/node/internal/hooks/useRangePosition.js +18 -1
  102. package/node/internal/models/index.js +11 -0
  103. package/node/internal/models/rangePickerProps.js +5 -0
  104. package/node/internal/utils/releaseInfo.js +1 -1
  105. package/node/internal/utils/valueManagers.js +22 -20
  106. package/package.json +5 -5
  107. package/internal/hooks/useRangePickerInputProps.d.ts +0 -19
  108. package/internal/hooks/useRangePickerInputProps.js +0 -89
  109. package/legacy/internal/hooks/useRangePickerInputProps.js +0 -88
  110. package/modern/internal/hooks/useRangePickerInputProps.js +0 -86
  111. package/node/internal/hooks/useRangePickerInputProps.js +0 -96
@@ -1,4 +1,4 @@
1
1
  import type { UseMultiInputDateTimeRangeFieldDefaultizedProps, UseMultiInputDateTimeRangeFieldParams, UseMultiInputDateTimeRangeFieldProps } from '../../../MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types';
2
2
  import type { UseMultiInputRangeFieldResponse } from './useMultiInputRangeField.types';
3
3
  export declare const useDefaultizedDateTimeRangeFieldProps: <TDate, AdditionalProps extends {}>(props: UseMultiInputDateTimeRangeFieldProps<TDate>) => UseMultiInputDateTimeRangeFieldDefaultizedProps<TDate, AdditionalProps>;
4
- export declare const useMultiInputDateTimeRangeField: <TDate, TTextFieldProps extends {}>({ sharedProps: inSharedProps, startTextFieldProps, startInputRef, unstableStartFieldRef, endTextFieldProps, endInputRef, unstableEndFieldRef, }: UseMultiInputDateTimeRangeFieldParams<TDate, TTextFieldProps>) => UseMultiInputRangeFieldResponse<TTextFieldProps>;
4
+ export declare const useMultiInputDateTimeRangeField: <TDate, TTextFieldSlotProps extends {}>({ sharedProps: inSharedProps, startTextFieldProps, startInputRef, unstableStartFieldRef, endTextFieldProps, endInputRef, unstableEndFieldRef, }: UseMultiInputDateTimeRangeFieldParams<TDate, TTextFieldSlotProps>) => UseMultiInputRangeFieldResponse<TTextFieldSlotProps>;
@@ -2,12 +2,12 @@ import * as React from 'react';
2
2
  import { FieldRef } from '@mui/x-date-pickers/models';
3
3
  import { UseFieldResponse } from '@mui/x-date-pickers/internals';
4
4
  import { RangeFieldSection } from '../../models/fields';
5
- export interface UseMultiInputRangeFieldParams<TSharedProps extends {}, TTextFieldProps extends {}> {
5
+ export interface UseMultiInputRangeFieldParams<TSharedProps extends {}, TTextFieldSlotProps extends {}> {
6
6
  sharedProps: TSharedProps;
7
- startTextFieldProps: TTextFieldProps;
7
+ startTextFieldProps: TTextFieldSlotProps;
8
8
  startInputRef?: React.Ref<HTMLInputElement>;
9
9
  unstableStartFieldRef?: React.Ref<FieldRef<RangeFieldSection>>;
10
- endTextFieldProps: TTextFieldProps;
10
+ endTextFieldProps: TTextFieldSlotProps;
11
11
  endInputRef?: React.Ref<HTMLInputElement>;
12
12
  unstableEndFieldRef?: React.Ref<FieldRef<RangeFieldSection>>;
13
13
  }
@@ -1,4 +1,4 @@
1
1
  import type { UseMultiInputTimeRangeFieldDefaultizedProps, UseMultiInputTimeRangeFieldParams, UseMultiInputTimeRangeFieldProps } from '../../../MultiInputTimeRangeField/MultiInputTimeRangeField.types';
2
2
  import type { UseMultiInputRangeFieldResponse } from './useMultiInputRangeField.types';
3
3
  export declare const useDefaultizedTimeRangeFieldProps: <TDate, AdditionalProps extends {}>(props: UseMultiInputTimeRangeFieldProps<TDate>) => UseMultiInputTimeRangeFieldDefaultizedProps<TDate, AdditionalProps>;
4
- export declare const useMultiInputTimeRangeField: <TDate, TTextFieldProps extends {}>({ sharedProps: inSharedProps, startTextFieldProps, startInputRef, unstableStartFieldRef, endTextFieldProps, endInputRef, unstableEndFieldRef, }: UseMultiInputTimeRangeFieldParams<TDate, TTextFieldProps>) => UseMultiInputRangeFieldResponse<TTextFieldProps>;
4
+ export declare const useMultiInputTimeRangeField: <TDate, TTextFieldSlotProps extends {}>({ sharedProps: inSharedProps, startTextFieldProps, startInputRef, unstableStartFieldRef, endTextFieldProps, endInputRef, unstableEndFieldRef, }: UseMultiInputTimeRangeFieldParams<TDate, TTextFieldSlotProps>) => UseMultiInputRangeFieldResponse<TTextFieldSlotProps>;
@@ -1,4 +1,7 @@
1
+ import * as React from 'react';
2
+ import { FieldRef } from '@mui/x-date-pickers/models';
1
3
  import { RangePosition } from '../models/range';
4
+ import { RangeFieldSection } from '../models/fields';
2
5
  export interface UseRangePositionProps {
3
6
  /**
4
7
  * The position in the currently edited date range.
@@ -20,5 +23,6 @@ export interface UseRangePositionProps {
20
23
  export interface UseRangePositionResponse {
21
24
  rangePosition: RangePosition;
22
25
  onRangePositionChange: (newPosition: RangePosition) => void;
26
+ singleInputFieldRef: React.MutableRefObject<FieldRef<RangeFieldSection> | undefined>;
23
27
  }
24
28
  export declare const useRangePosition: (props: UseRangePositionProps) => UseRangePositionResponse;
@@ -1,20 +1,35 @@
1
+ import * as React from 'react';
1
2
  import useControlled from '@mui/utils/useControlled';
2
3
  import useEventCallback from '@mui/utils/useEventCallback';
3
4
  export const useRangePosition = props => {
4
5
  var _props$defaultRangePo;
6
+ const singleInputFieldRef = React.useRef();
5
7
  const [rangePosition, setRangePosition] = useControlled({
6
8
  name: 'useRangePosition',
7
9
  state: 'rangePosition',
8
10
  controlled: props.rangePosition,
9
11
  default: (_props$defaultRangePo = props.defaultRangePosition) != null ? _props$defaultRangePo : 'start'
10
12
  });
13
+
14
+ // When using a single input field,
15
+ // we want to select the 1st section of the edited date when updating the range position.
16
+ const syncRangePositionWithSingleInputField = newRangePosition => {
17
+ if (singleInputFieldRef.current == null) {
18
+ return;
19
+ }
20
+ const sections = singleInputFieldRef.current.getSections();
21
+ const targetActiveSectionIndex = newRangePosition === 'start' ? 0 : sections.length / 2;
22
+ singleInputFieldRef.current.setSelectedSections(targetActiveSectionIndex);
23
+ };
11
24
  const handleRangePositionChange = useEventCallback(newRangePosition => {
12
25
  var _props$onRangePositio;
13
26
  setRangePosition(newRangePosition);
14
27
  (_props$onRangePositio = props.onRangePositionChange) == null ? void 0 : _props$onRangePositio.call(props, newRangePosition);
28
+ syncRangePositionWithSingleInputField(newRangePosition);
15
29
  });
16
30
  return {
17
31
  rangePosition,
18
- onRangePositionChange: handleRangePositionChange
32
+ onRangePositionChange: handleRangePositionChange,
33
+ singleInputFieldRef
19
34
  };
20
35
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { DateOrTimeView } from '@mui/x-date-pickers/internals';
2
+ import { DateOrTimeView } from '@mui/x-date-pickers/models';
3
3
  import { UseStaticRangePickerParams, UseStaticRangePickerProps } from './useStaticRangePicker.types';
4
4
  /**
5
5
  * Hook managing all the range static pickers:
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
- import { ExportedPickersLayoutSlotsComponent, ExportedPickersLayoutSlotsComponentsProps } from '@mui/x-date-pickers/PickersLayout/PickersLayout.types';
3
- import { DateOrTimeView, BasePickerProps, UsePickerParams, ExportedBaseToolbarProps, StaticOnlyPickerProps, UncapitalizeObjectKeys } from '@mui/x-date-pickers/internals';
2
+ import { BasePickerProps, UsePickerParams, ExportedBaseToolbarProps, StaticOnlyPickerProps, UncapitalizeObjectKeys } from '@mui/x-date-pickers/internals';
3
+ import { ExportedPickersLayoutSlotsComponent, ExportedPickersLayoutSlotsComponentsProps } from '@mui/x-date-pickers/PickersLayout';
4
+ import { DateOrTimeView } from '@mui/x-date-pickers/models';
4
5
  import { DateRange } from '../../models/range';
5
6
  import { UseRangePositionProps } from '../useRangePosition';
6
7
  import { RangeFieldSection } from '../../models/fields';
@@ -1,4 +1,5 @@
1
- import { Validator, DateValidationError, BaseDateValidationProps } from '@mui/x-date-pickers/internals';
1
+ import { Validator, BaseDateValidationProps } from '@mui/x-date-pickers/internals';
2
+ import { DateValidationError } from '@mui/x-date-pickers/models';
2
3
  import { DateRange, DayRangeValidationProps } from '../../models';
3
4
  export interface DateRangeComponentValidationProps<TDate> extends DayRangeValidationProps<TDate>, Required<BaseDateValidationProps<TDate>> {
4
5
  }
@@ -1,4 +1,5 @@
1
- import { Validator, DateTimeValidationError, BaseDateValidationProps, TimeValidationProps, ValidationProps } from '@mui/x-date-pickers/internals';
1
+ import { Validator, BaseDateValidationProps, TimeValidationProps, ValidationProps } from '@mui/x-date-pickers/internals';
2
+ import { DateTimeValidationError } from '@mui/x-date-pickers/models';
2
3
  import { DayRangeValidationProps } from '../../models/dateRange';
3
4
  import { DateRange } from '../../models/range';
4
5
  export interface DateTimeRangeComponentValidationProps<TDate> extends DayRangeValidationProps<TDate>, TimeValidationProps<TDate>, Required<BaseDateValidationProps<TDate>> {
@@ -1,4 +1,5 @@
1
- import { Validator, TimeValidationError, BaseTimeValidationProps, ValidationProps } from '@mui/x-date-pickers/internals';
1
+ import { Validator, BaseTimeValidationProps, ValidationProps } from '@mui/x-date-pickers/internals';
2
+ import { TimeValidationError } from '@mui/x-date-pickers/models';
2
3
  import { DateRange } from '../../models/range';
3
4
  export interface TimeRangeComponentValidationProps extends Required<BaseTimeValidationProps> {
4
5
  }
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { SlotComponentProps } from '@mui/base/utils';
3
- import { BaseFieldProps, FieldSection } from '@mui/x-date-pickers/internals';
3
+ import { BaseFieldProps } from '@mui/x-date-pickers/internals';
4
+ import { FieldSection } from '@mui/x-date-pickers/models';
4
5
  export interface RangeFieldSection extends FieldSection {
5
6
  dateName: 'start' | 'end';
6
7
  }
@@ -28,7 +29,11 @@ export interface MultiInputFieldSlotRootProps {
28
29
  * Only contains what the MUI component are passing to the field, not what users can pass using the `props.slotProps.field`.
29
30
  */
30
31
  export interface BaseMultiInputFieldProps<TValue, TSection extends FieldSection, TError> extends BaseFieldProps<TValue, TSection, TError> {
31
- slots?: {};
32
+ slots?: {
33
+ root?: React.ElementType;
34
+ separator?: React.ElementType;
35
+ textField?: React.ElementType;
36
+ };
32
37
  slotProps?: {
33
38
  root?: SlotComponentProps<React.ElementType<MultiInputFieldSlotRootProps>, {}, Record<string, any>>;
34
39
  textField?: SlotComponentProps<React.ElementType<MultiInputFieldSlotTextFieldProps>, {}, {
@@ -3,3 +3,4 @@ export * from './range';
3
3
  export * from './dateTimeRange';
4
4
  export * from './timeRange';
5
5
  export * from './fields';
6
+ export * from './rangePickerProps';
@@ -2,4 +2,5 @@ export * from './dateRange';
2
2
  export * from './range';
3
3
  export * from './dateTimeRange';
4
4
  export * from './timeRange';
5
- export * from './fields';
5
+ export * from './fields';
6
+ export * from './rangePickerProps';
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Props common to all range non-static pickers.
4
+ * These props are handled by the headless wrappers.
5
+ */
6
+ export interface BaseRangeNonStaticPickerProps {
7
+ /**
8
+ * The label content.
9
+ * Ignored if the field has several inputs.
10
+ */
11
+ label?: React.ReactNode;
12
+ /**
13
+ * Pass a ref to the `input` element.
14
+ * Ignored if the field has several inputs.
15
+ */
16
+ inputRef?: React.Ref<HTMLInputElement>;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { MuiPickersAdapter } from '@mui/x-date-pickers/internals';
1
+ import { MuiPickersAdapter } from '@mui/x-date-pickers/models';
2
2
  import { DateRange, RangePosition } from '../models/range';
3
3
  interface CalculateRangeChangeOptions<TDate> {
4
4
  utils: MuiPickersAdapter<TDate>;
@@ -1,4 +1,4 @@
1
- import { MuiPickersAdapter } from '@mui/x-date-pickers/internals';
1
+ import { MuiPickersAdapter } from '@mui/x-date-pickers/models';
2
2
  import { DateRange, NonEmptyDateRange } from '../models/range';
3
3
  export declare const isRangeValid: <TDate>(utils: MuiPickersAdapter<TDate>, range: DateRange<TDate> | null) => range is NonEmptyDateRange<TDate>;
4
4
  export declare const isWithinRange: <TDate>(utils: MuiPickersAdapter<TDate>, day: TDate, range: DateRange<TDate> | null) => boolean;
@@ -1,6 +1,6 @@
1
1
  import { ponyfillGlobal } from '@mui/utils';
2
2
  export const getReleaseInfo = () => {
3
- const releaseInfo = "MTY3OTUyNjAwMDAwMA==";
3
+ const releaseInfo = "MTY4MTA3NDAwMDAwMA==";
4
4
  if (process.env.NODE_ENV !== 'production') {
5
5
  // A simple hack to set the value in the test environment (has no build step).
6
6
  // eslint-disable-next-line no-useless-concat
@@ -6,4 +6,4 @@ import type { DateTimeRangeValidationError } from '../hooks/validation/useDateTi
6
6
  import { RangeFieldSection } from '../models/fields';
7
7
  export type RangePickerValueManager<TValue = [any, any], TDate = any, TError extends DateRangeValidationError | TimeRangeValidationError | DateTimeRangeValidationError = any> = PickerValueManager<TValue, TDate, TError>;
8
8
  export declare const rangeValueManager: RangePickerValueManager;
9
- export declare const rangeFieldValueManager: FieldValueManager<DateRange<any>, any, RangeFieldSection, DateRangeValidationError | TimeRangeValidationError | DateTimeRangeValidationError>;
9
+ export declare const rangeFieldValueManager: FieldValueManager<DateRange<any>, any, RangeFieldSection>;
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { replaceInvalidDateByNull, splitFormatIntoSections, addPositionPropertiesToSections, createDateStrForInputFromSections, areDatesEqual } from '@mui/x-date-pickers/internals';
2
+ import { replaceInvalidDateByNull, addPositionPropertiesToSections, createDateStrForInputFromSections, areDatesEqual } from '@mui/x-date-pickers/internals';
3
3
  import { splitDateRangeSections, removeLastSeparator } from './date-fields-utils';
4
4
  export const rangeValueManager = {
5
5
  emptyValue: [null, null],
@@ -7,6 +7,7 @@ export const rangeValueManager = {
7
7
  cleanValue: (utils, value) => value.map(date => replaceInvalidDateByNull(utils, date)),
8
8
  areValuesEqual: (utils, a, b) => areDatesEqual(utils, a[0], b[0]) && areDatesEqual(utils, a[1], b[1]),
9
9
  isSameError: (a, b) => b !== null && a[1] === b[1] && a[0] === b[0],
10
+ hasError: error => error[0] != null || error[1] != null,
10
11
  defaultErrorState: [null, null]
11
12
  };
12
13
  export const rangeFieldValueManager = {
@@ -24,17 +25,17 @@ export const rangeFieldValueManager = {
24
25
  }
25
26
  return [prevReferenceValue[1], value[1]];
26
27
  },
27
- getSectionsFromValue: (utils, localeText, prevSections, [start, end], format) => {
28
- const prevDateRangeSections = prevSections == null ? {
28
+ getSectionsFromValue: (utils, [start, end], fallbackSections, isRTL, getSectionsFromDate) => {
29
+ const separatedFallbackSections = fallbackSections == null ? {
29
30
  startDate: null,
30
31
  endDate: null
31
- } : splitDateRangeSections(prevSections);
32
- const getSections = (newDate, prevDateSections, position) => {
33
- const shouldReUsePrevDateSections = !utils.isValid(newDate) && !!prevDateSections;
32
+ } : splitDateRangeSections(fallbackSections);
33
+ const getSections = (newDate, fallbackDateSections, position) => {
34
+ const shouldReUsePrevDateSections = !utils.isValid(newDate) && !!fallbackDateSections;
34
35
  if (shouldReUsePrevDateSections) {
35
- return prevDateSections;
36
+ return fallbackDateSections;
36
37
  }
37
- const sections = splitFormatIntoSections(utils, localeText, format, newDate);
38
+ const sections = getSectionsFromDate(newDate);
38
39
  return sections.map((section, sectionIndex) => {
39
40
  if (sectionIndex === sections.length - 1 && position === 'start') {
40
41
  return _extends({}, section, {
@@ -47,16 +48,11 @@ export const rangeFieldValueManager = {
47
48
  });
48
49
  });
49
50
  };
50
- return addPositionPropertiesToSections([...getSections(start, prevDateRangeSections.startDate, 'start'), ...getSections(end, prevDateRangeSections.endDate, 'end')]);
51
+ return addPositionPropertiesToSections([...getSections(start, separatedFallbackSections.startDate, 'start'), ...getSections(end, separatedFallbackSections.endDate, 'end')], isRTL);
51
52
  },
52
- getValueStrFromSections: sections => {
53
+ getValueStrFromSections: (sections, isRTL) => {
53
54
  const dateRangeSections = splitDateRangeSections(sections);
54
- return createDateStrForInputFromSections([...dateRangeSections.startDate, ...dateRangeSections.endDate]);
55
- },
56
- getActiveDateSections: (sections, activeSection) => {
57
- const index = activeSection.dateName === 'start' ? 0 : 1;
58
- const dateRangeSections = splitDateRangeSections(sections);
59
- return index === 0 ? removeLastSeparator(dateRangeSections.startDate) : dateRangeSections.endDate;
55
+ return createDateStrForInputFromSections([...dateRangeSections.startDate, ...dateRangeSections.endDate], isRTL);
60
56
  },
61
57
  parseValueStr: (valueStr, referenceValue, parseDate) => {
62
58
  // TODO: Improve because it would not work if the date format has `–` as a separator.
@@ -72,13 +68,19 @@ export const rangeFieldValueManager = {
72
68
  const index = activeSection.dateName === 'start' ? 0 : 1;
73
69
  const updateDateInRange = (newDate, prevDateRange) => index === 0 ? [newDate, prevDateRange[1]] : [prevDateRange[0], newDate];
74
70
  return {
75
- activeDate: state.value[index],
76
- referenceActiveDate: state.referenceValue[index],
77
- getNewValueFromNewActiveDate: newActiveDate => ({
71
+ date: state.value[index],
72
+ referenceDate: state.referenceValue[index],
73
+ getSections: sections => {
74
+ const dateRangeSections = splitDateRangeSections(sections);
75
+ if (index === 0) {
76
+ return removeLastSeparator(dateRangeSections.startDate);
77
+ }
78
+ return dateRangeSections.endDate;
79
+ },
80
+ getNewValuesFromNewActiveDate: newActiveDate => ({
78
81
  value: updateDateInRange(newActiveDate, state.value),
79
82
  referenceValue: newActiveDate == null || !utils.isValid(newActiveDate) ? state.referenceValue : updateDateInRange(newActiveDate, state.referenceValue)
80
83
  })
81
84
  };
82
- },
83
- hasError: error => error[0] != null || error[1] != null
85
+ }
84
86
  };
@@ -146,6 +146,18 @@ process.env.NODE_ENV !== "production" ? DateRangePicker.propTypes = {
146
146
  * Defaults to localized format based on the used `views`.
147
147
  */
148
148
  format: PropTypes.string,
149
+ /**
150
+ * Pass a ref to the `input` element.
151
+ * Ignored if the field has several inputs.
152
+ */
153
+ inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
154
+ current: PropTypes.object
155
+ })]),
156
+ /**
157
+ * The label content.
158
+ * Ignored if the field has several inputs.
159
+ */
160
+ label: PropTypes.node,
149
161
  /**
150
162
  * If `true`, calls `renderLoading` instead of rendering the day calendar.
151
163
  * Can be used to preload information and show it in calendar.
@@ -154,6 +154,18 @@ DesktopDateRangePicker.propTypes = {
154
154
  * Defaults to localized format based on the used `views`.
155
155
  */
156
156
  format: PropTypes.string,
157
+ /**
158
+ * Pass a ref to the `input` element.
159
+ * Ignored if the field has several inputs.
160
+ */
161
+ inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
162
+ current: PropTypes.object
163
+ })]),
164
+ /**
165
+ * The label content.
166
+ * Ignored if the field has several inputs.
167
+ */
168
+ label: PropTypes.node,
157
169
  /**
158
170
  * If `true`, calls `renderLoading` instead of rendering the day calendar.
159
171
  * Can be used to preload information and show it in calendar.
@@ -159,6 +159,18 @@ MobileDateRangePicker.propTypes = {
159
159
  * Defaults to localized format based on the used `views`.
160
160
  */
161
161
  format: PropTypes.string,
162
+ /**
163
+ * Pass a ref to the `input` element.
164
+ * Ignored if the field has several inputs.
165
+ */
166
+ inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
167
+ current: PropTypes.object
168
+ })]),
169
+ /**
170
+ * The label content.
171
+ * Ignored if the field has several inputs.
172
+ */
173
+ label: PropTypes.node,
162
174
  /**
163
175
  * If `true`, calls `renderLoading` instead of rendering the day calendar.
164
176
  * Can be used to preload information and show it in calendar.
@@ -289,6 +289,16 @@ process.env.NODE_ENV !== "production" ? MultiInputDateRangeField.propTypes = {
289
289
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
290
290
  unstableEndFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
291
291
  unstableStartFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
292
+ /**
293
+ * If `true`, the CSS flexbox `gap` is used instead of applying `margin` to children.
294
+ *
295
+ * While CSS `gap` removes the [known limitations](https://mui.com/joy-ui/react-stack#limitations),
296
+ * it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag.
297
+ *
298
+ * To enable this flag globally, follow the [theme's default props](https://mui.com/material-ui/customization/theme-components/#default-props) configuration.
299
+ * @default false
300
+ */
301
+ useFlexGap: PropTypes.bool,
292
302
  /**
293
303
  * The selected value.
294
304
  * Used when the component is controlled.
@@ -355,6 +355,16 @@ process.env.NODE_ENV !== "production" ? MultiInputDateTimeRangeField.propTypes =
355
355
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
356
356
  unstableEndFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
357
357
  unstableStartFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
358
+ /**
359
+ * If `true`, the CSS flexbox `gap` is used instead of applying `margin` to children.
360
+ *
361
+ * While CSS `gap` removes the [known limitations](https://mui.com/joy-ui/react-stack#limitations),
362
+ * it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag.
363
+ *
364
+ * To enable this flag globally, follow the [theme's default props](https://mui.com/material-ui/customization/theme-components/#default-props) configuration.
365
+ * @default false
366
+ */
367
+ useFlexGap: PropTypes.bool,
358
368
  /**
359
369
  * The selected value.
360
370
  * Used when the component is controlled.
@@ -321,6 +321,16 @@ process.env.NODE_ENV !== "production" ? MultiInputTimeRangeField.propTypes = {
321
321
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
322
322
  unstableEndFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
323
323
  unstableStartFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
324
+ /**
325
+ * If `true`, the CSS flexbox `gap` is used instead of applying `margin` to children.
326
+ *
327
+ * While CSS `gap` removes the [known limitations](https://mui.com/joy-ui/react-stack#limitations),
328
+ * it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag.
329
+ *
330
+ * To enable this flag globally, follow the [theme's default props](https://mui.com/material-ui/customization/theme-components/#default-props) configuration.
331
+ * @default false
332
+ */
333
+ useFlexGap: PropTypes.bool,
324
334
  /**
325
335
  * The selected value.
326
336
  * Used when the component is controlled.
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["slots", "slotProps", "components", "componentsProps"],
4
- _excluded2 = ["ref", "onPaste", "inputMode", "readOnly"];
3
+ var _excluded = ["slots", "slotProps", "components", "componentsProps", "InputProps", "inputProps"],
4
+ _excluded2 = ["inputRef"],
5
+ _excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
5
6
  import * as React from 'react';
6
7
  import PropTypes from 'prop-types';
7
8
  import MuiTextField from '@mui/material/TextField';
@@ -19,24 +20,32 @@ var SingleInputDateRangeField = /*#__PURE__*/React.forwardRef(function SingleInp
19
20
  slotProps = themeProps.slotProps,
20
21
  components = themeProps.components,
21
22
  componentsProps = themeProps.componentsProps,
23
+ InputProps = themeProps.InputProps,
24
+ inputProps = themeProps.inputProps,
22
25
  other = _objectWithoutProperties(themeProps, _excluded);
23
26
  var ownerState = themeProps;
24
27
  var TextField = (_ref = (_slots$textField = slots == null ? void 0 : slots.textField) != null ? _slots$textField : components == null ? void 0 : components.TextField) != null ? _ref : MuiTextField;
25
- var textFieldProps = useSlotProps({
26
- elementType: TextField,
27
- externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
28
- externalForwardedProps: other,
29
- ownerState: ownerState
30
- });
28
+ var _useSlotProps = useSlotProps({
29
+ elementType: TextField,
30
+ externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
31
+ externalForwardedProps: other,
32
+ ownerState: ownerState
33
+ }),
34
+ externalInputRef = _useSlotProps.inputRef,
35
+ textFieldProps = _objectWithoutProperties(_useSlotProps, _excluded2);
36
+
37
+ // TODO: Remove when mui/material-ui#35088 will be merged
38
+ textFieldProps.inputProps = _extends({}, textFieldProps.inputProps, inputProps);
39
+ textFieldProps.InputProps = _extends({}, textFieldProps.InputProps, InputProps);
31
40
  var _useSingleInputDateRa = useSingleInputDateRangeField({
32
41
  props: textFieldProps,
33
- inputRef: textFieldProps.inputRef
42
+ inputRef: externalInputRef
34
43
  }),
35
44
  inputRef = _useSingleInputDateRa.ref,
36
45
  onPaste = _useSingleInputDateRa.onPaste,
37
46
  inputMode = _useSingleInputDateRa.inputMode,
38
47
  readOnly = _useSingleInputDateRa.readOnly,
39
- fieldProps = _objectWithoutProperties(_useSingleInputDateRa, _excluded2);
48
+ fieldProps = _objectWithoutProperties(_useSingleInputDateRa, _excluded3);
40
49
  return /*#__PURE__*/_jsx(TextField, _extends({
41
50
  ref: ref
42
51
  }, fieldProps, {
@@ -48,6 +57,7 @@ var SingleInputDateRangeField = /*#__PURE__*/React.forwardRef(function SingleInp
48
57
  })
49
58
  }));
50
59
  });
60
+ SingleInputDateRangeField.fieldType = 'single-input';
51
61
  process.env.NODE_ENV !== "production" ? SingleInputDateRangeField.propTypes = {
52
62
  // ----------------------------- Warning --------------------------------
53
63
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -1,10 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["slots", "slotProps", "components", "componentsProps"],
4
- _excluded2 = ["ref", "onPaste", "inputMode", "readOnly"];
3
+ var _excluded = ["slots", "slotProps", "components", "componentsProps", "InputProps", "inputProps"],
4
+ _excluded2 = ["inputRef"],
5
+ _excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
5
6
  import * as React from 'react';
6
7
  import PropTypes from 'prop-types';
7
- import TextField from '@mui/material/TextField';
8
+ import MuiTextField from '@mui/material/TextField';
8
9
  import { useThemeProps } from '@mui/material/styles';
9
10
  import { useSlotProps } from '@mui/base/utils';
10
11
  import { useSingleInputDateTimeRangeField } from './useSingleInputDateTimeRangeField';
@@ -19,25 +20,33 @@ var SingleInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function Singl
19
20
  slotProps = themeProps.slotProps,
20
21
  components = themeProps.components,
21
22
  componentsProps = themeProps.componentsProps,
23
+ InputProps = themeProps.InputProps,
24
+ inputProps = themeProps.inputProps,
22
25
  other = _objectWithoutProperties(themeProps, _excluded);
23
26
  var ownerState = themeProps;
24
- var Input = (_ref = (_slots$textField = slots == null ? void 0 : slots.textField) != null ? _slots$textField : components == null ? void 0 : components.TextField) != null ? _ref : TextField;
25
- var inputProps = useSlotProps({
26
- elementType: Input,
27
- externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
28
- externalForwardedProps: other,
29
- ownerState: ownerState
30
- });
27
+ var TextField = (_ref = (_slots$textField = slots == null ? void 0 : slots.textField) != null ? _slots$textField : components == null ? void 0 : components.TextField) != null ? _ref : MuiTextField;
28
+ var _useSlotProps = useSlotProps({
29
+ elementType: TextField,
30
+ externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
31
+ externalForwardedProps: other,
32
+ ownerState: ownerState
33
+ }),
34
+ externalInputRef = _useSlotProps.inputRef,
35
+ textFieldProps = _objectWithoutProperties(_useSlotProps, _excluded2);
36
+
37
+ // TODO: Remove when mui/material-ui#35088 will be merged
38
+ textFieldProps.inputProps = _extends({}, textFieldProps.inputProps, inputProps);
39
+ textFieldProps.InputProps = _extends({}, textFieldProps.InputProps, InputProps);
31
40
  var _useSingleInputDateTi = useSingleInputDateTimeRangeField({
32
- props: inputProps,
33
- inputRef: inputProps.inputRef
41
+ props: textFieldProps,
42
+ inputRef: externalInputRef
34
43
  }),
35
44
  inputRef = _useSingleInputDateTi.ref,
36
45
  onPaste = _useSingleInputDateTi.onPaste,
37
46
  inputMode = _useSingleInputDateTi.inputMode,
38
47
  readOnly = _useSingleInputDateTi.readOnly,
39
- fieldProps = _objectWithoutProperties(_useSingleInputDateTi, _excluded2);
40
- return /*#__PURE__*/_jsx(Input, _extends({
48
+ fieldProps = _objectWithoutProperties(_useSingleInputDateTi, _excluded3);
49
+ return /*#__PURE__*/_jsx(TextField, _extends({
41
50
  ref: ref
42
51
  }, fieldProps, {
43
52
  inputProps: _extends({}, fieldProps.inputProps, {
@@ -48,6 +57,7 @@ var SingleInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function Singl
48
57
  })
49
58
  }));
50
59
  });
60
+ SingleInputDateTimeRangeField.fieldType = 'single-input';
51
61
  process.env.NODE_ENV !== "production" ? SingleInputDateTimeRangeField.propTypes = {
52
62
  // ----------------------------- Warning --------------------------------
53
63
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -1,10 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["slots", "slotProps", "components", "componentsProps"],
4
- _excluded2 = ["ref", "onPaste", "inputMode", "readOnly"];
3
+ var _excluded = ["slots", "slotProps", "components", "componentsProps", "InputProps", "inputProps"],
4
+ _excluded2 = ["inputRef"],
5
+ _excluded3 = ["ref", "onPaste", "inputMode", "readOnly"];
5
6
  import * as React from 'react';
6
7
  import PropTypes from 'prop-types';
7
- import TextField from '@mui/material/TextField';
8
+ import MuiTextField from '@mui/material/TextField';
8
9
  import { useThemeProps } from '@mui/material/styles';
9
10
  import { useSlotProps } from '@mui/base/utils';
10
11
  import { useSingleInputTimeRangeField } from './useSingleInputTimeRangeField';
@@ -19,25 +20,33 @@ var SingleInputTimeRangeField = /*#__PURE__*/React.forwardRef(function SingleInp
19
20
  slotProps = themeProps.slotProps,
20
21
  components = themeProps.components,
21
22
  componentsProps = themeProps.componentsProps,
23
+ InputProps = themeProps.InputProps,
24
+ inputProps = themeProps.inputProps,
22
25
  other = _objectWithoutProperties(themeProps, _excluded);
23
26
  var ownerState = themeProps;
24
- var Input = (_ref = (_slots$textField = slots == null ? void 0 : slots.textField) != null ? _slots$textField : components == null ? void 0 : components.TextField) != null ? _ref : TextField;
25
- var inputProps = useSlotProps({
26
- elementType: Input,
27
- externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
28
- externalForwardedProps: other,
29
- ownerState: ownerState
30
- });
27
+ var TextField = (_ref = (_slots$textField = slots == null ? void 0 : slots.textField) != null ? _slots$textField : components == null ? void 0 : components.TextField) != null ? _ref : MuiTextField;
28
+ var _useSlotProps = useSlotProps({
29
+ elementType: TextField,
30
+ externalSlotProps: (_slotProps$textField = slotProps == null ? void 0 : slotProps.textField) != null ? _slotProps$textField : componentsProps == null ? void 0 : componentsProps.textField,
31
+ externalForwardedProps: other,
32
+ ownerState: ownerState
33
+ }),
34
+ externalInputRef = _useSlotProps.inputRef,
35
+ textFieldProps = _objectWithoutProperties(_useSlotProps, _excluded2);
36
+
37
+ // TODO: Remove when mui/material-ui#35088 will be merged
38
+ textFieldProps.inputProps = _extends({}, textFieldProps.inputProps, inputProps);
39
+ textFieldProps.InputProps = _extends({}, textFieldProps.InputProps, InputProps);
31
40
  var _useSingleInputTimeRa = useSingleInputTimeRangeField({
32
- props: inputProps,
33
- inputRef: inputProps.inputRef
41
+ props: textFieldProps,
42
+ inputRef: externalInputRef
34
43
  }),
35
44
  inputRef = _useSingleInputTimeRa.ref,
36
45
  onPaste = _useSingleInputTimeRa.onPaste,
37
46
  inputMode = _useSingleInputTimeRa.inputMode,
38
47
  readOnly = _useSingleInputTimeRa.readOnly,
39
- fieldProps = _objectWithoutProperties(_useSingleInputTimeRa, _excluded2);
40
- return /*#__PURE__*/_jsx(Input, _extends({
48
+ fieldProps = _objectWithoutProperties(_useSingleInputTimeRa, _excluded3);
49
+ return /*#__PURE__*/_jsx(TextField, _extends({
41
50
  ref: ref
42
51
  }, fieldProps, {
43
52
  inputProps: _extends({}, fieldProps.inputProps, {
@@ -48,6 +57,7 @@ var SingleInputTimeRangeField = /*#__PURE__*/React.forwardRef(function SingleInp
48
57
  })
49
58
  }));
50
59
  });
60
+ SingleInputTimeRangeField.fieldType = 'single-input';
51
61
  process.env.NODE_ENV !== "production" ? SingleInputTimeRangeField.propTypes = {
52
62
  // ----------------------------- Warning --------------------------------
53
63
  // | These PropTypes are generated from the TypeScript type definitions |
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers-pro v6.0.3
2
+ * @mui/x-date-pickers-pro v6.1.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the