Skip to content

Commit

Permalink
chore: unique
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Dec 7, 2023
1 parent a4c2bf7 commit c23740e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
28 changes: 21 additions & 7 deletions src/NewPicker/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,22 @@ export interface MultiplePickerProps<DateType extends object> extends BasePicker
onCalendarChange?: (date: DateType[], dateString: string[], info: BaseInfo) => void;
}

export type PickerProps<DateType extends object> =
export type PickerProps<DateType extends object = any> =
| SinglePickerProps<DateType>
| MultiplePickerProps<DateType>;

type InternalPickerProps<DateType extends object = any> = Omit<
MultiplePickerProps<DateType>,
'onChange' | 'onCalendarChange'
> & {
onChange?: (date: DateType | DateType[], dateString: string | string[]) => void;
onCalendarChange?: (
date: DateType | DateType[],
dateString: string | string[],
info: BaseInfo,
) => void;
};

function Picker<DateType extends object = any>(
props: PickerProps<DateType>,
ref: React.Ref<PickerRef>,
Expand Down Expand Up @@ -171,7 +183,7 @@ function Picker<DateType extends object = any>(

// Native
onClick,
} = filledProps;
} = filledProps as InternalPickerProps<DateType>;

// ========================= Refs =========================
const selectorRef = usePickerRef(ref);
Expand All @@ -185,11 +197,13 @@ function Picker<DateType extends object = any>(
const [formatList, maskFormat] = useFieldFormat(internalPicker, locale, format);

// ======================= Calendar =======================
const onInternalCalendarChange: any = (
dates: DateType[],
dateStrings: string[],
info: BaseInfo,
) => {};
function pickerParam<T>(values: T | T[]) {
return multiple ? values : values[0];
}

const onInternalCalendarChange = (dates: DateType[], dateStrings: string[], info: BaseInfo) => {
onCalendarChange?.(pickerParam(dates), pickerParam(dateStrings), info);
};

// ======================== Values ========================
const [mergedValue, setInnerValue, getCalendarValue, triggerCalendarChange] = useInnerValue(
Expand Down
5 changes: 3 additions & 2 deletions src/NewPicker/PickerInput/hooks/useFilledProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type ToArrayType<T> = T extends any[] ? T : [T];

/**
* Align the outer props with unique typed and fill undefined props.
* This is shared with both RangePicker and Picker.
* This will auto handle the legacy props fill like `clearIcon` + `allowClear` = `clearIcon`
* This is shared with both RangePicker and Picker. This will do:
* - Convert `value` & `defaultValue` to array
* - handle the legacy props fill like `clearIcon` + `allowClear` = `clearIcon`
*/
export default function useFilledProps<
DateType extends object,
Expand Down

0 comments on commit c23740e

Please sign in to comment.