Skip to content

Commit

Permalink
[fields] Pass the manager directly to useField
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Jan 2, 2025
1 parent d85fff1 commit 08e9825
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 192 deletions.
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,
});
};
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 as UseFieldParams,
UseFieldReturnValue as UseFieldResponse,
FieldChangeHandler,
FieldChangeHandlerContext,
} from './useField.types';
Expand Down
Loading

0 comments on commit 08e9825

Please sign in to comment.