Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 13, 2024
1 parent c7a1032 commit 66574c3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ import {
DateOrTimeViewWithMeridiem,
ExportedBaseTabsProps,
} from '@mui/x-date-pickers/internals';
import {
PickerValidDate,
FieldRef,
BaseSingleInputFieldProps,
InferError,
} from '@mui/x-date-pickers/models';
import { PickerValidDate, FieldRef, InferError } from '@mui/x-date-pickers/models';
import {
DesktopRangePickerAdditionalViewProps,
UseDesktopRangePickerParams,
UseDesktopRangePickerProps,
UseDesktopRangePickerSlotProps,
} from './useDesktopRangePicker.types';
import { useEnrichedRangePickerFieldProps } from '../useEnrichedRangePickerFieldProps';
import {
RangePickerPropsForFieldSlot,
useEnrichedRangePickerFieldProps,
} from '../useEnrichedRangePickerFieldProps';
import { getReleaseInfo } from '../../utils/releaseInfo';
import { DateRange, BaseMultiInputFieldProps, RangeFieldSection } from '../../../models';
import { DateRange, RangeFieldSection } from '../../../models';
import { useRangePosition } from '../useRangePosition';

const releaseInfo = getReleaseInfo();
Expand Down Expand Up @@ -138,24 +136,11 @@ export const useDesktopRangePicker = <
const fieldProps = useSlotProps<
typeof Field,
UseDesktopRangePickerSlotProps<TDate, TView, TEnableAccessibleFieldDOMStructure>['field'],
| Partial<
BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>
>
| Partial<
BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>
>,
RangePickerPropsForFieldSlot<
TDate,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>,
TExternalProps
>({
elementType: Field,
Expand All @@ -172,6 +157,7 @@ export const useDesktopRangePicker = <
selectedSections,
onSelectedSectionsChange,
timezone,
onOpen: actions.onOpen,
autoFocus: autoFocus && !props.open,
ref: fieldContainerRef,
...(fieldType === 'single-input' ? { inputRef, name } : {}),
Expand All @@ -183,7 +169,8 @@ export const useDesktopRangePicker = <
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
InferError<TExternalProps>,
typeof fieldProps
>({
wrapperVariant: 'desktop',
fieldType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from '@mui/x-date-pickers/hooks';
import { PickersInputLocaleText } from '@mui/x-date-pickers/locales';
import {
BaseFieldProps,
onSpaceOrEnter,
UsePickerResponse,
WrapperVariant,
Expand All @@ -36,6 +35,7 @@ import {
RangePosition,
FieldType,
UseDateRangeFieldProps,
BaseMultiInputFieldPropsInPickerSlots,
} from '../../models';
import { UseRangePositionResponse } from './useRangePosition';

Expand Down Expand Up @@ -64,7 +64,7 @@ export interface RangePickerFieldSlotProps<
TEnableAccessibleFieldDOMStructure extends boolean,
> extends UseClearableFieldSlotProps {
field?: SlotComponentPropsFromProps<
BaseMultiInputFieldProps<
BaseMultiInputFieldPropsInPickerSlots<
DateRange<TDate>,
TDate,
RangeFieldSection,
Expand All @@ -83,21 +83,33 @@ export interface RangePickerFieldSlotProps<
>;
}

export type RangePickerPropsForFieldSlot<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
> =
| BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
| BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>;

export interface UseEnrichedRangePickerFieldPropsParams<
TDate extends PickerValidDate,
TView extends DateOrTimeViewWithMeridiem,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
FieldProps extends BaseFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
> = BaseFieldProps<
DateRange<TDate>,
FieldProps extends RangePickerPropsForFieldSlot<
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>,
Expand Down Expand Up @@ -451,12 +463,18 @@ export const useEnrichedRangePickerFieldProps = <
TView extends DateOrTimeViewWithMeridiem,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
FieldProps extends RangePickerPropsForFieldSlot<
TDate,
TEnableAccessibleFieldDOMStructure,
TError
>,
>(
params: UseEnrichedRangePickerFieldPropsParams<
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError
TError,
FieldProps
>,
) => {
/* eslint-disable react-hooks/rules-of-hooks */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ import {
ExportedBaseTabsProps,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import {
PickerValidDate,
FieldRef,
BaseSingleInputFieldProps,
InferError,
} from '@mui/x-date-pickers/models';
import { PickerValidDate, FieldRef, InferError } from '@mui/x-date-pickers/models';
import useId from '@mui/utils/useId';
import {
MobileRangePickerAdditionalViewProps,
UseMobileRangePickerParams,
UseMobileRangePickerProps,
UseMobileRangePickerSlotProps,
} from './useMobileRangePicker.types';
import { useEnrichedRangePickerFieldProps } from '../useEnrichedRangePickerFieldProps';
import {
RangePickerPropsForFieldSlot,
useEnrichedRangePickerFieldProps,
} from '../useEnrichedRangePickerFieldProps';
import { getReleaseInfo } from '../../utils/releaseInfo';
import { DateRange, BaseMultiInputFieldProps, RangeFieldSection } from '../../../models';
import { DateRange, RangeFieldSection } from '../../../models';
import { useRangePosition } from '../useRangePosition';

const releaseInfo = getReleaseInfo();
Expand Down Expand Up @@ -114,24 +112,11 @@ export const useMobileRangePicker = <
const fieldProps = useSlotProps<
typeof Field,
UseMobileRangePickerSlotProps<TDate, TView, TEnableAccessibleFieldDOMStructure>['field'],
| Partial<
BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>
>
| Partial<
BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>
>,
RangePickerPropsForFieldSlot<
TDate,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
>,
TExternalProps
>({
elementType: Field,
Expand All @@ -148,6 +133,7 @@ export const useMobileRangePicker = <
selectedSections,
onSelectedSectionsChange,
timezone,
onOpen: actions.onOpen,
...(fieldType === 'single-input' ? { inputRef, name } : {}),
},
ownerState: props,
Expand All @@ -159,7 +145,8 @@ export const useMobileRangePicker = <
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
InferError<TExternalProps>,
typeof fieldProps
>({
wrapperVariant: 'mobile',
fieldType,
Expand Down
11 changes: 11 additions & 0 deletions packages/x-date-pickers-pro/src/models/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ export interface BaseMultiInputFieldProps<
};
}

export type BaseMultiInputFieldPropsInPickerSlots<
TValue,
TDate extends PickerValidDate,
TSection extends FieldSection,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
> = Omit<
BaseMultiInputFieldProps<TValue, TDate, TSection, TEnableAccessibleFieldDOMStructure, TError>,
'onOpen'
>;

/**
* Props the text field receives when used with a multi input picker.
* Only contains what the MUI components are passing to the text field, not what users can pass using the `props.slotProps.textField`.
Expand Down

0 comments on commit 66574c3

Please sign in to comment.