From d6733101eedd4a00d86022bc7d6cf4d409c4e6ec 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 13:56:40 +0800 Subject: [PATCH] chore: move more --- docs/examples/debug.tsx | 1 + src/NewPicker/PickerInput/RangePicker.tsx | 12 +++--------- src/NewPicker/PickerInput/SinglePicker.tsx | 8 ++------ src/NewPicker/PickerInput/hooks/useFilledProps.ts | 12 ++++++++++-- src/NewPicker/PickerInput/hooks/useRangeValue.ts | 10 +++++----- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/docs/examples/debug.tsx b/docs/examples/debug.tsx index 1dd1f04fc..525c2a53e 100644 --- a/docs/examples/debug.tsx +++ b/docs/examples/debug.tsx @@ -96,6 +96,7 @@ export default () => { // input: MyInput, // }} // showTime + disabled panelRender={(ori) => <>2333{ori}} placeholder={['Start', 'End']} suffixIcon="🧶" diff --git a/src/NewPicker/PickerInput/RangePicker.tsx b/src/NewPicker/PickerInput/RangePicker.tsx index fc7541ec7..7c7f4fd0c 100644 --- a/src/NewPicker/PickerInput/RangePicker.tsx +++ b/src/NewPicker/PickerInput/RangePicker.tsx @@ -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'; @@ -126,9 +125,8 @@ function RangePicker( ref: React.Ref, ) { // ========================= 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); @@ -138,8 +136,7 @@ function RangePicker( disabled: mergedDisabled, allowEmpty: mergedAllowEmpty, }; - }, - ); + }); const { // Style @@ -282,9 +279,6 @@ function RangePicker( // ======================= Show Now ======================= const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday); - // ====================== Invalidate ====================== - const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, showTime); - // ======================== Value ========================= const [ /** Trigger `onChange` by check `disabledDate` */ diff --git a/src/NewPicker/PickerInput/SinglePicker.tsx b/src/NewPicker/PickerInput/SinglePicker.tsx index 34f7ce966..a28a9c6d5 100644 --- a/src/NewPicker/PickerInput/SinglePicker.tsx +++ b/src/NewPicker/PickerInput/SinglePicker.tsx @@ -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'; @@ -108,7 +107,7 @@ function Picker( ref: React.Ref, ) { // ========================= Prop ========================= - const [filledProps, internalPicker, complexPicker, formatList, maskFormat] = + const [filledProps, internalPicker, complexPicker, formatList, maskFormat, isInvalidateDate] = useFilledProps(props); const { @@ -248,9 +247,6 @@ function Picker( // ======================= Show Now ======================= const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday); - // ====================== Invalidate ====================== - const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, showTime); - // ======================== Value ========================= const [ /** Trigger `onChange` by check `disabledDate` */ @@ -263,7 +259,7 @@ function Picker( setInnerValue, getCalendarValue, triggerCalendarChange, - disabled, + [], //disabled, formatList, focused, mergedOpen, diff --git a/src/NewPicker/PickerInput/hooks/useFilledProps.ts b/src/NewPicker/PickerInput/hooks/useFilledProps.ts index 3720cf4ca..05b47c892 100644 --- a/src/NewPicker/PickerInput/hooks/useFilledProps.ts +++ b/src/NewPicker/PickerInput/hooks/useFilledProps.ts @@ -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 = typeof useInvalidate; type PickedProps = Pick< RangePickerProps, @@ -63,6 +66,7 @@ export default function useFilledProps< complexPicker: boolean, formatList: FormatType[], maskFormat: string, + isInvalidateDate: ReturnType>, ] { const { generateConfig, @@ -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( () => ({ @@ -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?.(), @@ -134,6 +139,9 @@ export default function useFilledProps< maxDate, ); + // ====================== Invalidate ====================== + const isInvalidateDate = useInvalidate(generateConfig, picker, disabledDate, mergedShowTime); + // ======================== Merged ======================== const mergedProps = React.useMemo( () => ({ @@ -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]; } diff --git a/src/NewPicker/PickerInput/hooks/useRangeValue.ts b/src/NewPicker/PickerInput/hooks/useRangeValue.ts index ca8591191..19062729c 100644 --- a/src/NewPicker/PickerInput/hooks/useRangeValue.ts +++ b/src/NewPicker/PickerInput/hooks/useRangeValue.ts @@ -34,8 +34,8 @@ const EMPTY_VALUE: any[] = []; type TriggerCalendarChange = (calendarValues: ValueType) => void; -type Replace2String = { - [P in keyof T]: string; +type ReplaceListType = { + [P in keyof List]: Type; }; export function useUtil< @@ -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>; + ) as any as ReplaceListType, string>; }; const isSameDates = (source: MergedValueType, target: MergedValueType) => { @@ -95,7 +95,7 @@ export function useInnerValue>, + dateStrings: ReplaceListType, string>, info: BaseInfo, ) => void, /** Used for RangePicker */ @@ -153,7 +153,7 @@ export default function useRangeValue void, getCalendarValue: () => ValueType, triggerCalendarChange: TriggerCalendarChange, - disabled: [boolean, boolean], + disabled: ReplaceListType, boolean>, formatList: FormatType[], focused: boolean, open: boolean,