refactor: remove redundant code(#50845) (#51507)

Co-authored-by: liangjunqi <liangjunqi@hmntech.com>
Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
DctMaZiYo 2024-11-08 10:31:20 +08:00 committed by GitHub
parent 6a62d9e7ea
commit 48b28e5269
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 4 additions and 70 deletions

View File

@ -23,7 +23,7 @@ import { useLocale } from '../../locale';
import { useCompactItemContext } from '../../space/Compact';
import enUS from '../locale/en_US';
import useStyle from '../style';
import { getRangePlaceholder, transPlacement2DropdownAlign, useIcons } from '../util';
import { getRangePlaceholder, useIcons } from '../util';
import { TIME } from './constant';
import type { RangePickerProps } from './interface';
import useComponents from './useComponents';
@ -117,7 +117,6 @@ const generateRangePicker = <DateType extends AnyObject = AnyObject>(
}
disabled={mergedDisabled}
ref={innerRef as any} // Need to modify PickerRef
popupAlign={transPlacement2DropdownAlign(direction, placement)}
placement={placement}
placeholder={getRangePlaceholder(locale, picker, placeholder)}
suffixIcon={suffixNode}

View File

@ -23,7 +23,7 @@ import { useLocale } from '../../locale';
import { useCompactItemContext } from '../../space/Compact';
import enUS from '../locale/en_US';
import useStyle from '../style';
import { getPlaceholder, transPlacement2DropdownAlign, useIcons } from '../util';
import { getPlaceholder, useIcons } from '../util';
import {
MONTH,
MONTHPICKER,
@ -160,7 +160,6 @@ const generatePicker = <DateType extends AnyObject = AnyObject>(
ref={innerRef}
placeholder={getPlaceholder(locale, mergedPicker, placeholder)}
suffixIcon={suffixNode}
dropdownAlign={transPlacement2DropdownAlign(direction, placement)}
placement={placement}
prevIcon={<span className={`${prefixCls}-prev-icon`} />}
nextIcon={<span className={`${prefixCls}-next-icon`} />}

View File

@ -8,7 +8,6 @@ import type {
PickerProps,
PickerPropsWithMultiple,
} from './generatePicker/interface';
import { transPlacement2DropdownAlign } from './util';
export type DatePickerProps<ValueType = Dayjs | Dayjs> = PickerPropsWithMultiple<
Dayjs,
@ -30,24 +29,11 @@ export type DatePickerType = typeof DatePicker & {
generatePicker: typeof generatePicker;
};
function postPureProps(props: DatePickerProps) {
const dropdownAlign = transPlacement2DropdownAlign(props.direction, props.placement);
dropdownAlign.overflow!.adjustY = false;
dropdownAlign.overflow!.adjustX = false;
return {
...props,
dropdownAlign,
popupAlign: dropdownAlign,
};
}
// We don't care debug panel
/* istanbul ignore next */
const PurePanel = genPurePanel(DatePicker, 'picker', null, postPureProps);
const PurePanel = genPurePanel(DatePicker, 'picker', null);
(DatePicker as DatePickerType)._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
const PureRangePanel = genPurePanel(DatePicker.RangePicker, 'picker', null, postPureProps);
const PureRangePanel = genPurePanel(DatePicker.RangePicker, 'picker', null);
(DatePicker as DatePickerType)._InternalRangePanelDoNotUseOrYouWillBeFired = PureRangePanel;
(DatePicker as DatePickerType).generatePicker = generatePicker;

View File

@ -1,9 +1,6 @@
import * as React from 'react';
import type { AlignType } from '@rc-component/trigger';
import type { PickerMode } from 'rc-picker/lib/interface';
import type { SelectCommonPlacement } from '../_util/motion';
import type { DirectionType } from '../config-provider';
import useSelectIcons from '../select/useIcons';
import type { PickerLocale, PickerProps } from './generatePicker';
@ -61,53 +58,6 @@ export function getRangePlaceholder(
return locale.lang.rangePlaceholder;
}
export function transPlacement2DropdownAlign(
direction: DirectionType,
placement?: SelectCommonPlacement,
): AlignType {
const overflow = {
adjustX: 1,
adjustY: 1,
};
switch (placement) {
case 'bottomLeft': {
return {
points: ['tl', 'bl'],
offset: [0, 4],
overflow,
};
}
case 'bottomRight': {
return {
points: ['tr', 'br'],
offset: [0, 4],
overflow,
};
}
case 'topLeft': {
return {
points: ['bl', 'tl'],
offset: [0, -4],
overflow,
};
}
case 'topRight': {
return {
points: ['br', 'tr'],
offset: [0, -4],
overflow,
};
}
default: {
return {
points: direction === 'rtl' ? ['tr', 'br'] : ['tl', 'bl'],
offset: [0, 4],
overflow,
};
}
}
}
export function useIcons(props: Pick<PickerProps, 'allowClear' | 'removeIcon'>, prefixCls: string) {
const { allowClear = true } = props;