Skip to content

Commit

Permalink
chore: move more
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Dec 7, 2023
1 parent a0ecd44 commit d673310
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default () => {
// input: MyInput,
// }}
// showTime
disabled
panelRender={(ori) => <>2333{ori}</>}
placeholder={['Start', 'End']}
suffixIcon="🧶"
Expand Down
12 changes: 3 additions & 9 deletions src/NewPicker/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { fillIndex } from '../util';
import PickerContext from './context';
import useCellRender from './hooks/useCellRender';
import useFilledProps from './hooks/useFilledProps';
import useInvalidate from './hooks/useInvalidate';
import useOpen from './hooks/useOpen';
import { usePickerRef } from './hooks/usePickerRef';
import usePresets from './hooks/usePresets';
Expand Down Expand Up @@ -126,9 +125,8 @@ function RangePicker<DateType extends object = any>(
ref: React.Ref<PickerRef>,
) {
// ========================= Prop =========================
const [filledProps, internalPicker, complexPicker, formatList, maskFormat] = useFilledProps(
props,
() => {
const [filledProps, internalPicker, complexPicker, formatList, maskFormat, isInvalidateDate] =
useFilledProps(props, () => {
const { disabled, allowEmpty } = props;

const mergedDisabled = separateConfig(disabled, false);
Expand All @@ -138,8 +136,7 @@ function RangePicker<DateType extends object = any>(
disabled: mergedDisabled,
allowEmpty: mergedAllowEmpty,
};
},
);
});

const {
// Style
Expand Down Expand Up @@ -282,9 +279,6 @@ function RangePicker<DateType extends object = any>(
// ======================= Show Now =======================
const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday);

// ====================== Invalidate ======================
const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, showTime);

// ======================== Value =========================
const [
/** Trigger `onChange` by check `disabledDate` */
Expand Down
8 changes: 2 additions & 6 deletions src/NewPicker/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { fillIndex } from '../util';
import PickerContext from './context';
import useCellRender from './hooks/useCellRender';
import useFilledProps from './hooks/useFilledProps';
import useInvalidate from './hooks/useInvalidate';
import useOpen from './hooks/useOpen';
import { usePickerRef } from './hooks/usePickerRef';
import usePresets from './hooks/usePresets';
Expand Down Expand Up @@ -108,7 +107,7 @@ function Picker<DateType extends object = any>(
ref: React.Ref<PickerRef>,
) {
// ========================= Prop =========================
const [filledProps, internalPicker, complexPicker, formatList, maskFormat] =
const [filledProps, internalPicker, complexPicker, formatList, maskFormat, isInvalidateDate] =
useFilledProps(props);

const {
Expand Down Expand Up @@ -248,9 +247,6 @@ function Picker<DateType extends object = any>(
// ======================= Show Now =======================
const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday);

// ====================== Invalidate ======================
const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, showTime);

// ======================== Value =========================
const [
/** Trigger `onChange` by check `disabledDate` */
Expand All @@ -263,7 +259,7 @@ function Picker<DateType extends object = any>(
setInnerValue,
getCalendarValue,
triggerCalendarChange,
disabled,
[], //disabled,
formatList,
focused,
mergedOpen,
Expand Down
12 changes: 10 additions & 2 deletions src/NewPicker/PickerInput/hooks/useFilledProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { fillClearIcon } from '../Selector/hooks/useClearIcon';
import useDisabledBoundary from './useDisabledBoundary';
import { useFieldFormat } from './useFieldFormat';
import useInputReadOnly from './useInputReadOnly';
import useInvalidate from './useInvalidate';

type UseInvalidate<DateType extends object = any> = typeof useInvalidate<DateType>;

type PickedProps<DateType extends object = any> = Pick<
RangePickerProps<DateType>,
Expand Down Expand Up @@ -63,6 +66,7 @@ export default function useFilledProps<
complexPicker: boolean,
formatList: FormatType<DateType>[],
maskFormat: string,
isInvalidateDate: ReturnType<UseInvalidate<DateType>>,
] {
const {
generateConfig,
Expand Down Expand Up @@ -90,6 +94,7 @@ export default function useFilledProps<
const defaultValues = React.useMemo(() => toArray(defaultValue), [defaultValue]);

const mergedLocale = fillLocale(locale);
const mergedShowTime = getTimeConfig(props);

const filledProps = React.useMemo(
() => ({
Expand All @@ -102,7 +107,7 @@ export default function useFilledProps<
order,
components,
clearIcon: fillClearIcon(prefixCls, allowClear, clearIcon),
showTime: getTimeConfig(props),
showTime: mergedShowTime,
value: values,
defaultValue: defaultValues,
...updater?.(),
Expand Down Expand Up @@ -134,6 +139,9 @@ export default function useFilledProps<
maxDate,
);

// ====================== Invalidate ======================
const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, mergedShowTime);

// ======================== Merged ========================
const mergedProps = React.useMemo(
() => ({
Expand All @@ -145,5 +153,5 @@ export default function useFilledProps<
[filledProps, mergedNeedConfirm, mergedInputReadOnly, disabledBoundaryDate],
);

return [mergedProps, internalPicker, complexPicker, formatList, maskFormat];
return [mergedProps, internalPicker, complexPicker, formatList, maskFormat, isInvalidateDate];
}
10 changes: 5 additions & 5 deletions src/NewPicker/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const EMPTY_VALUE: any[] = [];

type TriggerCalendarChange<ValueType extends object[]> = (calendarValues: ValueType) => void;

type Replace2String<T> = {
[P in keyof T]: string;
type ReplaceListType<List, Type> = {
[P in keyof List]: Type;
};

export function useUtil<
Expand All @@ -45,7 +45,7 @@ export function useUtil<
const getDateTexts = (dates: MergedValueType) => {
return dates.map((date) =>
formatValue(date, { generateConfig, locale, format: formatList[0] }),
) as any as Replace2String<Required<MergedValueType>>;
) as any as ReplaceListType<Required<MergedValueType>, string>;
};

const isSameDates = (source: MergedValueType, target: MergedValueType) => {
Expand Down Expand Up @@ -95,7 +95,7 @@ export function useInnerValue<ValueType extends DateType[], DateType extends obj
value?: ValueType,
onCalendarChange?: (
dates: ValueType,
dateStrings: Replace2String<Required<ValueType>>,
dateStrings: ReplaceListType<Required<ValueType>, string>,
info: BaseInfo,
) => void,
/** Used for RangePicker */
Expand Down Expand Up @@ -153,7 +153,7 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
setInnerValue: (nextValue: ValueType) => void,
getCalendarValue: () => ValueType,
triggerCalendarChange: TriggerCalendarChange<ValueType>,
disabled: [boolean, boolean],
disabled: ReplaceListType<Required<ValueType>, boolean>,
formatList: FormatType[],
focused: boolean,
open: boolean,
Expand Down

0 comments on commit d673310

Please sign in to comment.