From c23740e2f78c9bda2733cd1f17662ed11bf06546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 7 Dec 2023 10:46:58 +0800 Subject: [PATCH] chore: unique --- src/NewPicker/PickerInput/SinglePicker.tsx | 28 ++++++++++++++----- .../PickerInput/hooks/useFilledProps.ts | 5 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/NewPicker/PickerInput/SinglePicker.tsx b/src/NewPicker/PickerInput/SinglePicker.tsx index f83819116..02c1d9ace 100644 --- a/src/NewPicker/PickerInput/SinglePicker.tsx +++ b/src/NewPicker/PickerInput/SinglePicker.tsx @@ -92,10 +92,22 @@ export interface MultiplePickerProps extends BasePicker onCalendarChange?: (date: DateType[], dateString: string[], info: BaseInfo) => void; } -export type PickerProps = +export type PickerProps = | SinglePickerProps | MultiplePickerProps; +type InternalPickerProps = Omit< + MultiplePickerProps, + 'onChange' | 'onCalendarChange' +> & { + onChange?: (date: DateType | DateType[], dateString: string | string[]) => void; + onCalendarChange?: ( + date: DateType | DateType[], + dateString: string | string[], + info: BaseInfo, + ) => void; +}; + function Picker( props: PickerProps, ref: React.Ref, @@ -171,7 +183,7 @@ function Picker( // Native onClick, - } = filledProps; + } = filledProps as InternalPickerProps; // ========================= Refs ========================= const selectorRef = usePickerRef(ref); @@ -185,11 +197,13 @@ function Picker( const [formatList, maskFormat] = useFieldFormat(internalPicker, locale, format); // ======================= Calendar ======================= - const onInternalCalendarChange: any = ( - dates: DateType[], - dateStrings: string[], - info: BaseInfo, - ) => {}; + function pickerParam(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( diff --git a/src/NewPicker/PickerInput/hooks/useFilledProps.ts b/src/NewPicker/PickerInput/hooks/useFilledProps.ts index 158e704eb..43aa4bf9c 100644 --- a/src/NewPicker/PickerInput/hooks/useFilledProps.ts +++ b/src/NewPicker/PickerInput/hooks/useFilledProps.ts @@ -31,8 +31,9 @@ type ToArrayType = 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,