Skip to content

Commit

Permalink
chore: tmp of it
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Dec 7, 2023
1 parent 8a5805d commit 52dce60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/NewPicker/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export type PickerProps<DateType extends object = any> =
| SinglePickerProps<DateType>
| MultiplePickerProps<DateType>;

type ReplacedPickerProps<DateType extends object = any> = {
/** Internal usage. For cross function get same aligned props */
export type ReplacedPickerProps<DateType extends object = any> = {
onChange?: (date: DateType | DateType[], dateString: string | string[]) => void;
onCalendarChange?: (
date: DateType | DateType[],
Expand Down
39 changes: 17 additions & 22 deletions src/NewPicker/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { formatValue, isSame, isSameTimestamp } from '../../../utils/dateUtil';
import useSyncState from '../../hooks/useSyncState';
import type { BaseInfo, FormatType, Locale } from '../../interface';
import { fillIndex } from '../../util';
import type { RangePickerProps, RangeValueType } from '../RangePicker';
import type { RangePickerProps } from '../RangePicker';
import type { ReplacedPickerProps } from '../SinglePicker';
import useLockEffect from './useLockEffect';

const EMPTY_VALUE: any[] = [];
Expand Down Expand Up @@ -142,21 +143,19 @@ export function useInnerValue<ValueType extends object[], DateType extends Value
return [mergedValue, setInnerValue, calendarValue, triggerCalendarChange] as const;
}

export default function useRangeValue<DateType extends object = any>(
export default function useRangeValue<
ValueType extends object[],
DateType extends ValueType[number],
>(
info: Pick<
RangePickerProps<DateType>,
| 'generateConfig'
| 'locale'
| 'allowEmpty'
| 'order'
| 'onCalendarChange'
| 'onChange'
| 'picker'
>,
mergedValue: RangeValueType<DateType>,
setInnerValue: (nextValue: RangeValueType<DateType>) => void,
getCalendarValue: () => RangeValueType<DateType>,
triggerCalendarChange: TriggerCalendarChange<RangeValueType<DateType>>,
'generateConfig' | 'locale' | 'allowEmpty' | 'order' | 'picker'
> &
ReplacedPickerProps<DateType>,
mergedValue: ValueType,
setInnerValue: (nextValue: ValueType) => void,
getCalendarValue: () => ValueType,
triggerCalendarChange: TriggerCalendarChange<ValueType>,
disabled: [boolean, boolean],
formatList: FormatType[],
focused: boolean,
Expand All @@ -166,7 +165,7 @@ export default function useRangeValue<DateType extends object = any>(
/** Trigger `onChange` by check `disabledDate` */
flushSubmit: (index: number, needTriggerChange: boolean) => void,
/** Trigger `onChange` directly without check `disabledDate` */
triggerSubmitChange: (value: RangeValueType<DateType>) => boolean,
triggerSubmitChange: (value: ValueType) => boolean,
] {
const {
// MISC
Expand All @@ -185,11 +184,7 @@ export default function useRangeValue<DateType extends object = any>(
const orderOnChange = disabled.some((d) => d) ? false : order;

// ============================= Util =============================
const [getDateTexts, isSameDates] = useUtil<RangeValueType<DateType>>(
generateConfig,
locale,
formatList,
);
const [getDateTexts, isSameDates] = useUtil<ValueType>(generateConfig, locale, formatList);

// ============================ Values ============================
// Used for trigger `onChange` event.
Expand All @@ -206,10 +201,10 @@ export default function useRangeValue<DateType extends object = any>(
}, [mergedValue]);

// ============================ Submit ============================
const triggerSubmit = useEvent((nextValue?: RangeValueType<DateType>) => {
const triggerSubmit = useEvent((nextValue?: ValueType) => {
const isNullValue = nextValue === null;

const clone = [...(nextValue || submitValue())] as RangeValueType<DateType>;
const clone = [...(nextValue || submitValue())] as ValueType;

// Fill null value
if (isNullValue) {
Expand Down

0 comments on commit 52dce60

Please sign in to comment.