Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Introduce a new concept of manager #15339

Merged
merged 86 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
5d145b6
[pickers] Replace TValue and TSection generics with TIsRange
flaviendelangle Nov 5, 2024
a8f316d
Merge branch 'master' into tisrange
flaviendelangle Nov 6, 2024
6ed4952
Fix CI
flaviendelangle Nov 6, 2024
5904738
Merge
flaviendelangle Nov 6, 2024
5419886
Merge branch 'master' into tisrange
flaviendelangle Nov 7, 2024
5c34425
Merge branch 'master' into tisrange
flaviendelangle Nov 8, 2024
bbd4fe2
[pickers] Introduce an improved version of the value manager
flaviendelangle Nov 8, 2024
7821632
Work on value manager usage
flaviendelangle Nov 12, 2024
3a73dd3
Merge
flaviendelangle Nov 12, 2024
dc89d3c
Merge branch 'tisrange' into v8-value-manager
flaviendelangle Nov 12, 2024
eda4787
Work
flaviendelangle Nov 13, 2024
f7ee409
Fix
flaviendelangle Nov 13, 2024
b04e5bb
Merge branch 'master' into tisrange
flaviendelangle Nov 13, 2024
cae8762
Work
flaviendelangle Nov 13, 2024
f06c8ca
Work
flaviendelangle Nov 13, 2024
48c9261
Merge branch 'tisrange' into v8-value-manager
flaviendelangle Nov 13, 2024
20805bd
Fix'
flaviendelangle Nov 13, 2024
f6b78d9
Work
flaviendelangle Nov 13, 2024
d47da98
Fix
flaviendelangle Nov 13, 2024
7eebeb7
Merge
flaviendelangle Nov 14, 2024
3493484
Merge branch 'tisrange' into v8-value-manager
flaviendelangle Nov 14, 2024
3a52a82
Review: Lukas
flaviendelangle Nov 14, 2024
3e18240
Review: Lukas
flaviendelangle Nov 14, 2024
8aae145
Remove as
flaviendelangle Nov 14, 2024
49b7030
Merge branch 'tisrange' into v8-value-manager
flaviendelangle Nov 14, 2024
ae71f10
Move value manager to hookss
flaviendelangle Nov 14, 2024
4dbfd03
xImprove internals
flaviendelangle Nov 14, 2024
6993047
Merge branch 'master' into tisrange
flaviendelangle Nov 14, 2024
9e7e9aa
Fix
flaviendelangle Nov 14, 2024
0d6562c
Merge branch 'master' into tisrange
flaviendelangle Nov 15, 2024
6066a59
Work
flaviendelangle Nov 15, 2024
d1ca6a4
Fix
flaviendelangle Nov 15, 2024
407ec45
[pickers] Remove TSection and stictly type TValue
flaviendelangle Nov 15, 2024
d7661ae
Merge
flaviendelangle Nov 15, 2024
b7ac3ee
Fix
flaviendelangle Nov 18, 2024
db88d0e
Fix
flaviendelangle Nov 18, 2024
8c30f22
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 18, 2024
78df9d0
Fix
flaviendelangle Nov 18, 2024
5625c29
Merge branch 'master' into tvalue
flaviendelangle Nov 18, 2024
25bb456
Fix
flaviendelangle Nov 18, 2024
2bab784
Add migration guide
flaviendelangle Nov 18, 2024
3f8e296
Improve migration guide
flaviendelangle Nov 18, 2024
24dbb6d
Merge branch 'master' into v8-value-manager
flaviendelangle Nov 18, 2024
b866d81
Remove useless changes
flaviendelangle Nov 18, 2024
bea99a0
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 18, 2024
c39d33f
Fix
flaviendelangle Nov 18, 2024
0429717
Work
flaviendelangle Nov 18, 2024
59dc346
Improve JSDoc
flaviendelangle Nov 18, 2024
f895380
Merge branch 'master' into tvalue
flaviendelangle Nov 18, 2024
81643d9
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 18, 2024
21c8518
Work
flaviendelangle Nov 18, 2024
74df222
WOrk
flaviendelangle Nov 18, 2024
fe6d825
Merge branch 'master' into tvalue
flaviendelangle Nov 19, 2024
0d60ce3
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 19, 2024
b0e3265
Merge
flaviendelangle Nov 19, 2024
c0c7db8
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 19, 2024
e7f5500
Fix
flaviendelangle Nov 19, 2024
eb563eb
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 19, 2024
f6b087a
Merge
flaviendelangle Nov 20, 2024
4dd3038
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 20, 2024
3eb5a04
Fix
flaviendelangle Nov 20, 2024
745524d
Merge
flaviendelangle Nov 22, 2024
18b3087
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 22, 2024
04657b1
Merge
flaviendelangle Nov 22, 2024
01fd0cb
Merge branch 'master' into tvalue
flaviendelangle Nov 25, 2024
f941b8e
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 25, 2024
a1a048d
Fix
flaviendelangle Nov 25, 2024
8b742d8
Merge
flaviendelangle Nov 26, 2024
43b1180
Merge
flaviendelangle Nov 26, 2024
e47e9fd
Update docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
flaviendelangle Nov 28, 2024
4452039
Merge branch 'master' into tvalue
flaviendelangle Nov 28, 2024
e5406e7
Fix
flaviendelangle Nov 28, 2024
2823188
Merge branch 'master' into tvalue
flaviendelangle Nov 28, 2024
f653f35
Merge branch 'tvalue' into v8-value-manager
flaviendelangle Nov 28, 2024
4efb66d
Merge
flaviendelangle Nov 28, 2024
45ec78d
Merge branch 'master' into v8-value-manager
flaviendelangle Nov 28, 2024
0d7063a
Merge branch 'master' into v8-value-manager
flaviendelangle Nov 28, 2024
00b9085
Merge branch 'master' into v8-value-manager
flaviendelangle Dec 4, 2024
317cbcf
Merge remote-tracking branch 'origin/v8-value-manager' into v8-value-…
flaviendelangle Dec 4, 2024
ca36470
Merge branch 'master' into v8-value-manager
flaviendelangle Dec 4, 2024
6f7c7f3
Merge branch 'master' into v8-value-manager
flaviendelangle Dec 9, 2024
f1527a1
Fix
flaviendelangle Dec 9, 2024
a2ebfed
Merge branch 'master' into v8-value-manager
flaviendelangle Dec 13, 2024
3230e1d
Merge
flaviendelangle Dec 19, 2024
4d63e80
Merge
flaviendelangle Dec 30, 2024
245c08f
Merge branch 'master' into v8-value-manager
flaviendelangle Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
'use client';
import * as React from 'react';
import { useField, useDefaultizedDateField, PickerRangeValue } from '@mui/x-date-pickers/internals';
import {
useField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputDateRangeFieldProps } from './SingleInputDateRangeField.types';
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers';
import { validateDateRange } from '../validation';
import { useDateRangeManager } from '../managers';

export const useSingleInputDateRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
TAllProps extends UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
>(
inProps: TAllProps,
props: TAllProps,
) => {
const props = useDefaultizedDateField<
UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
TAllProps
>(inProps);

const manager = useDateRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');

const fieldValueManager = React.useMemo(
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }),
[internalProps.dateSeparator],
);
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalProps
typeof internalPropsWithDefaults
>({
forwardedProps,
internalProps,
valueManager: rangeValueManager,
fieldValueManager,
validator: validateDateRange,
valueType: 'date',
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
});
};
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
'use client';
import * as React from 'react';
import {
useField,
useDefaultizedDateTimeField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputDateTimeRangeFieldProps } from './SingleInputDateTimeRangeField.types';
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers';
import { validateDateTimeRange } from '../validation';
import { useDateTimeRangeManager } from '../managers';

export const useSingleInputDateTimeRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
TAllProps extends UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
>(
inProps: TAllProps,
props: TAllProps,
) => {
const props = useDefaultizedDateTimeField<
UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
TAllProps
>(inProps);

const manager = useDateTimeRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date-time');

const fieldValueManager = React.useMemo(
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }),
[internalProps.dateSeparator],
);
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalProps
typeof internalPropsWithDefaults
>({
forwardedProps,
internalProps,
valueManager: rangeValueManager,
fieldValueManager,
validator: validateDateTimeRange,
valueType: 'date-time',
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
});
};
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
'use client';
import * as React from 'react';
import { useField, useDefaultizedTimeField, PickerRangeValue } from '@mui/x-date-pickers/internals';
import {
useField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputTimeRangeFieldProps } from './SingleInputTimeRangeField.types';
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers';
import { validateTimeRange } from '../validation';
import { useTimeRangeManager } from '../managers';

export const useSingleInputTimeRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
TAllProps extends UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
>(
inProps: TAllProps,
props: TAllProps,
) => {
const props = useDefaultizedTimeField<
UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
TAllProps
>(inProps);

const manager = useTimeRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'time');

const fieldValueManager = React.useMemo(
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }),
[internalProps.dateSeparator],
);
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalProps
typeof internalPropsWithDefaults
>({
forwardedProps,
internalProps,
valueManager: rangeValueManager,
fieldValueManager,
validator: validateTimeRange,
valueType: 'time',
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
});
};
1 change: 1 addition & 0 deletions packages/x-date-pickers-pro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from './dateRangeViewRenderers';
export * from './models';
export * from './hooks';
export * from './validation';
export * from './managers';
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ import {
PickerValue,
UseFieldResponse,
useControlledValueWithTimezone,
useDefaultizedDateField,
useFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
import { useValidation } from '@mui/x-date-pickers/validation';
import { DateValidationError } from '@mui/x-date-pickers/models';
import {
UseMultiInputDateRangeFieldParams,
UseMultiInputDateRangeFieldProps,
} from '../../../MultiInputDateRangeField/MultiInputDateRangeField.types';
import { UseMultiInputDateRangeFieldParams } from '../../../MultiInputDateRangeField/MultiInputDateRangeField.types';
import { validateDateRange } from '../../../validation';
import { rangeValueManager } from '../../utils/valueManagers';
import type { UseMultiInputRangeFieldResponse } from './useMultiInputRangeField.types';
import { DateRangeValidationError } from '../../../models';
import { excludeProps } from './shared';
import { useMultiInputFieldSelectedSections } from '../useMultiInputFieldSelectedSections';
import { useDateRangeManager } from '../../../managers';

export const useMultiInputDateRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
TTextFieldSlotProps extends {},
>({
sharedProps: inSharedProps,
sharedProps,
startTextFieldProps,
unstableStartFieldRef,
endTextFieldProps,
Expand All @@ -35,10 +33,11 @@ export const useMultiInputDateRangeField = <
TEnableAccessibleFieldDOMStructure,
TTextFieldSlotProps
>): UseMultiInputRangeFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps> => {
const sharedProps = useDefaultizedDateField<
UseMultiInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
typeof inSharedProps
>(inSharedProps);
const manager = useDateRangeManager(sharedProps);
const sharedPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps: sharedProps,
});

const {
value: valueProp,
Expand All @@ -55,7 +54,7 @@ export const useMultiInputDateRangeField = <
timezone: timezoneProp,
enableAccessibleFieldDOMStructure,
autoFocus,
} = sharedProps;
} = sharedPropsWithDefaults;

const { value, handleValueChange, timezone } = useControlledValueWithTimezone({
name: 'useMultiInputDateRangeField',
Expand All @@ -68,11 +67,11 @@ export const useMultiInputDateRangeField = <
});

const { validationError, getValidationErrorForNewValue } = useValidation({
props: sharedProps,
props: sharedPropsWithDefaults,
value,
timezone,
validator: validateDateRange,
onError: sharedProps.onError,
onError: sharedPropsWithDefaults.onError,
});

// TODO: Maybe export utility from `useField` instead of copy/pasting the logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ import {
PickerValue,
UseFieldResponse,
useControlledValueWithTimezone,
useDefaultizedDateTimeField,
useFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
import { DateTimeValidationError } from '@mui/x-date-pickers/models';
import { useValidation } from '@mui/x-date-pickers/validation';
import type {
UseMultiInputDateTimeRangeFieldParams,
UseMultiInputDateTimeRangeFieldProps,
} from '../../../MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types';
import { DateTimeRangeValidationError } from '../../../models';
import { DateTimeValidationError } from '@mui/x-date-pickers/models';
import { UseMultiInputDateTimeRangeFieldParams } from '../../../MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types';
import { validateDateTimeRange } from '../../../validation';
import { rangeValueManager } from '../../utils/valueManagers';
import type { UseMultiInputRangeFieldResponse } from './useMultiInputRangeField.types';
import { DateTimeRangeValidationError } from '../../../models';
import { excludeProps } from './shared';
import { useMultiInputFieldSelectedSections } from '../useMultiInputFieldSelectedSections';
import { useDateTimeRangeManager } from '../../../managers';

export const useMultiInputDateTimeRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
TTextFieldSlotProps extends {},
>({
sharedProps: inSharedProps,
sharedProps,
startTextFieldProps,
unstableStartFieldRef,
endTextFieldProps,
Expand All @@ -35,10 +33,11 @@ export const useMultiInputDateTimeRangeField = <
TEnableAccessibleFieldDOMStructure,
TTextFieldSlotProps
>): UseMultiInputRangeFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps> => {
const sharedProps = useDefaultizedDateTimeField<
UseMultiInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
typeof inSharedProps
>(inSharedProps);
const manager = useDateTimeRangeManager(sharedProps);
const sharedPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps: sharedProps,
});

const {
value: valueProp,
Expand All @@ -55,10 +54,10 @@ export const useMultiInputDateTimeRangeField = <
timezone: timezoneProp,
enableAccessibleFieldDOMStructure,
autoFocus,
} = sharedProps;
} = sharedPropsWithDefaults;

const { value, handleValueChange, timezone } = useControlledValueWithTimezone({
name: 'useMultiInputDateRangeField',
name: 'useMultiInputDateTimeRangeField',
timezone: timezoneProp,
value: valueProp,
defaultValue,
Expand All @@ -68,11 +67,11 @@ export const useMultiInputDateTimeRangeField = <
});

const { validationError, getValidationErrorForNewValue } = useValidation({
props: sharedProps,
props: sharedPropsWithDefaults,
value,
timezone,
validator: validateDateTimeRange,
onError: sharedProps.onError,
onError: sharedPropsWithDefaults.onError,
});

// TODO: Maybe export utility from `useField` instead of copy/pasting the logic
Expand Down
Loading
Loading