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

[fields] Pass the manager directly to useField #16060

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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,12 +1,14 @@
'use client';
import {
useField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputDateRangeFieldProps } from './SingleInputDateRangeField.types';
import { useDateRangeManager } from '../managers';
import { DateRangeValidationError } from '../models';

export const useSingleInputDateRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -16,22 +18,17 @@ export const useSingleInputDateRangeField = <
) => {
const manager = useDateRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
DateRangeValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use client';
import {
useField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputDateTimeRangeFieldProps } from './SingleInputDateTimeRangeField.types';
import { useDateTimeRangeManager } from '../managers';
import { DateTimeRangeValidationError } from '../models';

export const useSingleInputDateTimeRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -16,22 +18,17 @@ export const useSingleInputDateTimeRangeField = <
) => {
const manager = useDateTimeRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date-time');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
DateTimeRangeValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use client';
import {
useField,
useFieldInternalPropsWithDefaults,
PickerRangeValue,
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { UseSingleInputTimeRangeFieldProps } from './SingleInputTimeRangeField.types';
import { useTimeRangeManager } from '../managers';
import { TimeRangeValidationError } from '../models';

export const useSingleInputTimeRangeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -16,22 +18,17 @@ export const useSingleInputTimeRangeField = <
) => {
const manager = useTimeRangeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'time');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerRangeValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
TimeRangeValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FieldChangeHandlerContext,
PickerRangeValue,
PickerValue,
UseFieldResponse,
UseFieldReturnValue,
useControlledValueWithTimezone,
useFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
Expand Down Expand Up @@ -137,11 +137,14 @@ export const useMultiInputDateRangeField = <
const startDateResponse = useDateField<
TEnableAccessibleFieldDOMStructure,
typeof startFieldProps
>(startFieldProps) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
>(startFieldProps) as UseFieldReturnValue<
TEnableAccessibleFieldDOMStructure,
TTextFieldSlotProps
>;

const endDateResponse = useDateField<TEnableAccessibleFieldDOMStructure, typeof endFieldProps>(
endFieldProps,
) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
) as UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;

/* TODO: Undo this change when a clearable behavior for multiple input range fields is implemented */
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FieldChangeHandlerContext,
PickerRangeValue,
PickerValue,
UseFieldResponse,
UseFieldReturnValue,
useControlledValueWithTimezone,
useFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
Expand Down Expand Up @@ -137,12 +137,15 @@ export const useMultiInputDateTimeRangeField = <
const startDateResponse = useDateTimeField<
TEnableAccessibleFieldDOMStructure,
typeof startFieldProps
>(startFieldProps) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
>(startFieldProps) as UseFieldReturnValue<
TEnableAccessibleFieldDOMStructure,
TTextFieldSlotProps
>;

const endDateResponse = useDateTimeField<
TEnableAccessibleFieldDOMStructure,
typeof endFieldProps
>(endFieldProps) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
>(endFieldProps) as UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;

/* TODO: Undo this change when a clearable behavior for multiple input range fields is implemented */
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UseFieldResponse } from '@mui/x-date-pickers/internals';
import { UseFieldReturnValue } from '@mui/x-date-pickers/internals';
import { MultiInputFieldRefs } from '../../../models';

export interface UseMultiInputRangeFieldParams<
Expand All @@ -14,6 +14,6 @@ export interface UseMultiInputRangeFieldResponse<
TEnableAccessibleFieldDOMStructure extends boolean,
TForwardedProps extends {},
> {
startDate: UseFieldResponse<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
endDate: UseFieldResponse<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
startDate: UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
endDate: UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FieldChangeHandlerContext,
PickerRangeValue,
PickerValue,
UseFieldResponse,
UseFieldReturnValue,
useControlledValueWithTimezone,
useFieldInternalPropsWithDefaults,
} from '@mui/x-date-pickers/internals';
Expand Down Expand Up @@ -137,11 +137,14 @@ export const useMultiInputTimeRangeField = <
const startDateResponse = useTimeField<
TEnableAccessibleFieldDOMStructure,
typeof startFieldProps
>(startFieldProps) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
>(startFieldProps) as UseFieldReturnValue<
TEnableAccessibleFieldDOMStructure,
TTextFieldSlotProps
>;

const endDateResponse = useTimeField<TEnableAccessibleFieldDOMStructure, typeof endFieldProps>(
endFieldProps,
) as UseFieldResponse<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;
) as UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, TTextFieldSlotProps>;

/* TODO: Undo this change when a clearable behavior for multiple input range fields is implemented */
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/x-date-pickers-pro/src/models/fields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import {
UseFieldResponse,
UseFieldReturnValue,
FormProps,
PickerValue,
PickerRangeValue,
Expand Down Expand Up @@ -63,5 +63,5 @@ export type PickerRangeFieldSlotProps<TEnableAccessibleFieldDOMStructure extends
export type BaseMultiInputPickersTextFieldProps<
TEnableAccessibleFieldDOMStructure extends boolean,
> = UseClearableFieldResponse<
UseFieldResponse<TEnableAccessibleFieldDOMStructure, MultiInputFieldSlotTextFieldProps>
UseFieldReturnValue<TEnableAccessibleFieldDOMStructure, MultiInputFieldSlotTextFieldProps>
>;
26 changes: 13 additions & 13 deletions packages/x-date-pickers/src/DateField/useDateField.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';
import { useField, useFieldInternalPropsWithDefaults } from '../internals/hooks/useField';
import { useField } from '../internals/hooks/useField';
import { UseDateFieldProps } from './DateField.types';
import { useSplitFieldProps } from '../hooks';
import { useDateManager } from '../managers';
import { PickerValue } from '../internals/models';
import {
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
PickerValue,
} from '../internals/models';
import { DateValidationError } from '../models/validation';

export const useDateField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -13,22 +18,17 @@ export const useDateField = <
) => {
const manager = useDateManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
DateValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
26 changes: 13 additions & 13 deletions packages/x-date-pickers/src/DateTimeField/useDateTimeField.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';
import { useField, useFieldInternalPropsWithDefaults } from '../internals/hooks/useField';
import { useField } from '../internals/hooks/useField';
import { UseDateTimeFieldProps } from './DateTimeField.types';
import { useSplitFieldProps } from '../hooks';
import { useDateTimeManager } from '../managers';
import { PickerValue } from '../internals/models';
import {
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
PickerValue,
} from '../internals/models';
import { DateTimeValidationError } from '../models/validation';

export const useDateTimeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -13,22 +18,17 @@ export const useDateTimeField = <
) => {
const manager = useDateTimeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date-time');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
DateTimeValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
26 changes: 13 additions & 13 deletions packages/x-date-pickers/src/TimeField/useTimeField.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use client';
import { useField, useFieldInternalPropsWithDefaults } from '../internals/hooks/useField';
import { useField } from '../internals/hooks/useField';
import { UseTimeFieldProps } from './TimeField.types';
import { useSplitFieldProps } from '../hooks';
import { useTimeManager } from '../managers';
import { PickerValue } from '../internals/models';
import {
PickerManagerFieldInternalProps,
PickerManagerFieldInternalPropsWithDefaults,
PickerValue,
} from '../internals/models';
import { TimeValidationError } from '../models/validation';

export const useTimeField = <
TEnableAccessibleFieldDOMStructure extends boolean,
Expand All @@ -13,22 +18,17 @@ export const useTimeField = <
) => {
const manager = useTimeManager(props);
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'time');
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
manager,
internalProps,
});

return useField<
PickerValue,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalPropsWithDefaults
TimeValidationError,
PickerManagerFieldInternalProps<typeof manager>,
PickerManagerFieldInternalPropsWithDefaults<typeof manager>,
typeof forwardedProps
>({
manager,
forwardedProps,
internalProps: internalPropsWithDefaults,
valueManager: manager.internal_valueManager,
fieldValueManager: manager.internal_fieldValueManager,
validator: manager.validator,
valueType: manager.valueType,
internalProps,
});
};
4 changes: 2 additions & 2 deletions packages/x-date-pickers/src/internals/hooks/useField/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export { useField, useFieldInternalPropsWithDefaults } from './useField';
export type {
FieldValueManager,
UseFieldInternalProps,
UseFieldParams,
UseFieldResponse,
UseFieldParameters,
UseFieldReturnValue,
FieldChangeHandler,
FieldChangeHandlerContext,
} from './useField.types';
Expand Down
Loading
Loading