Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 13, 2024
1 parent 66574c3 commit c7e9186
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const useDesktopRangePicker = <
typeof Field,
UseDesktopRangePickerSlotProps<TDate, TView, TEnableAccessibleFieldDOMStructure>['field'],
RangePickerPropsForFieldSlot<
boolean,
TDate,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
Expand Down Expand Up @@ -169,8 +170,7 @@ export const useDesktopRangePicker = <
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>,
typeof fieldProps
InferError<TExternalProps>
>({
wrapperVariant: 'desktop',
fieldType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,36 @@ export interface RangePickerFieldSlotProps<
}

export type RangePickerPropsForFieldSlot<
TIsSingleInput extends boolean,
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
> =
| BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
| BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>;
| (TIsSingleInput extends true
? BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
: never)
| (TIsSingleInput extends false
? BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
: never);

export interface UseEnrichedRangePickerFieldPropsParams<
TIsSingleInput extends boolean,
TDate extends PickerValidDate,
TView extends DateOrTimeViewWithMeridiem,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
FieldProps extends RangePickerPropsForFieldSlot<
TDate,
TEnableAccessibleFieldDOMStructure,
TError
>,
> extends Pick<
UsePickerResponse<DateRange<TDate>, TView, RangeFieldSection, any>,
'open' | 'actions'
Expand All @@ -128,7 +129,12 @@ export interface UseEnrichedRangePickerFieldPropsParams<
localeText: PickersInputLocaleText<TDate> | undefined;
pickerSlotProps: RangePickerFieldSlotProps<TDate, TEnableAccessibleFieldDOMStructure> | undefined;
pickerSlots: RangePickerFieldSlots | undefined;
fieldProps: FieldProps;
fieldProps: RangePickerPropsForFieldSlot<
TIsSingleInput,
TDate,
TEnableAccessibleFieldDOMStructure,
TError
>;
anchorRef?: React.Ref<HTMLDivElement>;
currentView?: TView | null;
initialView?: TView;
Expand Down Expand Up @@ -163,17 +169,11 @@ const useMultiInputFieldSlotProps = <
startFieldRef,
endFieldRef,
}: UseEnrichedRangePickerFieldPropsParams<
false,
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError,
BaseMultiInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
TError
>) => {
type ReturnType = BaseMultiInputFieldProps<
DateRange<TDate>,
Expand Down Expand Up @@ -348,17 +348,11 @@ const useSingleInputFieldSlotProps = <
anchorRef,
currentView,
}: UseEnrichedRangePickerFieldPropsParams<
true,
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError,
BaseSingleInputFieldProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
TError
>
TError
>) => {
type ReturnType = BaseSingleInputFieldProps<
DateRange<TDate>,
Expand Down Expand Up @@ -463,18 +457,13 @@ export const useEnrichedRangePickerFieldProps = <
TView extends DateOrTimeViewWithMeridiem,
TEnableAccessibleFieldDOMStructure extends boolean,
TError,
FieldProps extends RangePickerPropsForFieldSlot<
TDate,
TEnableAccessibleFieldDOMStructure,
TError
>,
>(
params: UseEnrichedRangePickerFieldPropsParams<
boolean,
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError,
FieldProps
TError
>,
) => {
/* eslint-disable react-hooks/rules-of-hooks */
Expand All @@ -488,9 +477,25 @@ export const useEnrichedRangePickerFieldProps = <
}

if (params.fieldType === 'multi-input') {
return useMultiInputFieldSlotProps(params);
return useMultiInputFieldSlotProps(
params as unknown as UseEnrichedRangePickerFieldPropsParams<
false,
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError
>,
);
}

return useSingleInputFieldSlotProps(params);
return useSingleInputFieldSlotProps(
params as UseEnrichedRangePickerFieldPropsParams<
true,
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
TError
>,
);
/* eslint-enable react-hooks/rules-of-hooks */
};
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const useMobileRangePicker = <
typeof Field,
UseMobileRangePickerSlotProps<TDate, TView, TEnableAccessibleFieldDOMStructure>['field'],
RangePickerPropsForFieldSlot<
boolean,
TDate,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>
Expand Down Expand Up @@ -145,8 +146,7 @@ export const useMobileRangePicker = <
TDate,
TView,
TEnableAccessibleFieldDOMStructure,
InferError<TExternalProps>,
typeof fieldProps
InferError<TExternalProps>
>({
wrapperVariant: 'mobile',
fieldType,
Expand Down

0 comments on commit c7e9186

Please sign in to comment.