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 bffb149 commit 8a5805d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 41 deletions.
21 changes: 3 additions & 18 deletions src/NewPicker/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import PickerTrigger from '../PickerTrigger';
import { fillIndex } from '../util';
import PickerContext from './context';
import useCellRender from './hooks/useCellRender';
import useDisabledBoundary from './hooks/useDisabledBoundary';
import useFilledProps from './hooks/useFilledProps';
import useInputReadOnly from './hooks/useInputReadOnly';
import useInvalidate from './hooks/useInvalidate';
import useOpen from './hooks/useOpen';
import { usePickerRef } from './hooks/usePickerRef';
Expand Down Expand Up @@ -187,7 +185,6 @@ function RangePicker<DateType extends object = any>(
onPickerValueChange,

// Format
format,
inputReadOnly,

// Motion
Expand Down Expand Up @@ -285,20 +282,8 @@ function RangePicker<DateType extends object = any>(
// ======================= Show Now =======================
const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday);

// ======================= ReadOnly =======================
const mergedInputReadOnly = useInputReadOnly(formatList, inputReadOnly);

// ======================= Boundary =======================
const disabledBoundaryDate = useDisabledBoundary(
generateConfig,
locale,
disabledDate,
minDate,
maxDate,
);

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

// ======================== Value =========================
const [
Expand Down Expand Up @@ -326,7 +311,7 @@ function RangePicker<DateType extends object = any>(
activeIndexList,
generateConfig,
locale,
disabledBoundaryDate,
disabledDate,
// minDate,
// maxDate,
);
Expand Down Expand Up @@ -747,7 +732,7 @@ function RangePicker<DateType extends object = any>(
onInputChange={onSelectorInputChange}
// Format
format={formatList}
inputReadOnly={mergedInputReadOnly}
inputReadOnly={inputReadOnly}
// Disabled
disabled={disabled}
// Open
Expand Down
27 changes: 5 additions & 22 deletions src/NewPicker/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import PickerTrigger from '../PickerTrigger';
import { fillIndex } from '../util';
import PickerContext from './context';
import useCellRender from './hooks/useCellRender';
import useDisabledBoundary from './hooks/useDisabledBoundary';
import useFilledProps from './hooks/useFilledProps';
import useInputReadOnly from './hooks/useInputReadOnly';
import useInvalidate from './hooks/useInvalidate';
import useOpen from './hooks/useOpen';
import { usePickerRef } from './hooks/usePickerRef';
Expand Down Expand Up @@ -95,10 +93,7 @@ export type PickerProps<DateType extends object = any> =
| SinglePickerProps<DateType>
| MultiplePickerProps<DateType>;

type InternalPickerProps<DateType extends object = any> = Omit<
MultiplePickerProps<DateType>,
'onChange' | 'onCalendarChange'
> & {
type ReplacedPickerProps<DateType extends object = any> = {
onChange?: (date: DateType | DateType[], dateString: string | string[]) => void;
onCalendarChange?: (
date: DateType | DateType[],
Expand Down Expand Up @@ -159,7 +154,6 @@ function Picker<DateType extends object = any>(
onPickerValueChange,

// Format
format,
inputReadOnly,

// Motion
Expand All @@ -183,7 +177,8 @@ function Picker<DateType extends object = any>(

// Native
onClick,
} = filledProps as InternalPickerProps<DateType>;
} = filledProps as Omit<typeof filledProps, keyof ReplacedPickerProps<DateType>> &
ReplacedPickerProps<DateType>;

// ========================= Refs =========================
const selectorRef = usePickerRef(ref);
Expand Down Expand Up @@ -252,20 +247,8 @@ function Picker<DateType extends object = any>(
// ======================= Show Now =======================
const mergedShowNow = useShowNow(internalPicker, mergedMode, showNow, showToday);

// ======================= ReadOnly =======================
const mergedInputReadOnly = useInputReadOnly(formatList, inputReadOnly);

// ======================= Boundary =======================
const disabledBoundaryDate = useDisabledBoundary(
generateConfig,
locale,
disabledDate,
minDate,
maxDate,
);

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

// ======================== Value =========================
const [
Expand Down Expand Up @@ -667,7 +650,7 @@ function Picker<DateType extends object = any>(
onInputChange={onSelectorInputChange}
// Format
format={formatList}
inputReadOnly={mergedInputReadOnly}
inputReadOnly={inputReadOnly}
// Disabled
disabled={disabled}
// Open
Expand Down
28 changes: 27 additions & 1 deletion src/NewPicker/PickerInput/hooks/useFilledProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { getTimeConfig } from '../../hooks/useTimeConfig';
import type { FormatType, InternalMode } from '../../interface';
import type { RangePickerProps } from '../RangePicker';
import { fillClearIcon } from '../Selector/hooks/useClearIcon';
import useDisabledBoundary from './useDisabledBoundary';
import { useFieldFormat } from './useFieldFormat';
import useInputReadOnly from './useInputReadOnly';

type PickedProps<DateType extends object = any> = Pick<
RangePickerProps<DateType>,
| 'generateConfig'
| 'locale'
| 'picker'
| 'prefixCls'
Expand All @@ -20,6 +23,10 @@ type PickedProps<DateType extends object = any> = Pick<
| 'allowClear'
| 'needConfirm'
| 'format'
| 'inputReadOnly'
| 'disabledDate'
| 'minDate'
| 'maxDate'
> & {
multiple?: boolean;
// RangePicker showTime definition is different with Picker
Expand Down Expand Up @@ -58,6 +65,7 @@ export default function useFilledProps<
maskFormat: string,
] {
const {
generateConfig,
locale,
picker = 'date',
prefixCls = 'rc-picker',
Expand All @@ -72,6 +80,10 @@ export default function useFilledProps<
defaultValue,
multiple,
format,
inputReadOnly,
disabledDate,
minDate,
maxDate,
} = props;

const values = React.useMemo(() => (value ? toArray(value) : value), [value]);
Expand Down Expand Up @@ -110,13 +122,27 @@ export default function useFilledProps<
// ======================== Format ========================
const [formatList, maskFormat] = useFieldFormat<DateType>(internalPicker, mergedLocale, format);

// ======================= ReadOnly =======================
const mergedInputReadOnly = useInputReadOnly(formatList, inputReadOnly);

// ======================= Boundary =======================
const disabledBoundaryDate = useDisabledBoundary(
generateConfig,
locale,
disabledDate,
minDate,
maxDate,
);

// ======================== Merged ========================
const mergedProps = React.useMemo(
() => ({
...filledProps,
needConfirm: mergedNeedConfirm,
inputReadOnly: mergedInputReadOnly,
disabledDate: disabledBoundaryDate,
}),
[filledProps, mergedNeedConfirm],
[filledProps, mergedNeedConfirm, mergedInputReadOnly, disabledBoundaryDate],
);

return [mergedProps, internalPicker, complexPicker, formatList, maskFormat];
Expand Down

0 comments on commit 8a5805d

Please sign in to comment.