From 48b28e52694c4181fd36282408f3c565c77a7385 Mon Sep 17 00:00:00 2001 From: DctMaZiYo <74136983+Dmaziyo@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:31:20 +0800 Subject: [PATCH] refactor: remove redundant code(#50845) (#51507) Co-authored-by: liangjunqi Co-authored-by: afc163 --- .../generatePicker/generateRangePicker.tsx | 3 +- .../generatePicker/generateSinglePicker.tsx | 3 +- components/date-picker/index.tsx | 18 +------ components/date-picker/util.ts | 50 ------------------- 4 files changed, 4 insertions(+), 70 deletions(-) diff --git a/components/date-picker/generatePicker/generateRangePicker.tsx b/components/date-picker/generatePicker/generateRangePicker.tsx index c9e7d5f49c..7784d1ea6f 100644 --- a/components/date-picker/generatePicker/generateRangePicker.tsx +++ b/components/date-picker/generatePicker/generateRangePicker.tsx @@ -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 = ( } disabled={mergedDisabled} ref={innerRef as any} // Need to modify PickerRef - popupAlign={transPlacement2DropdownAlign(direction, placement)} placement={placement} placeholder={getRangePlaceholder(locale, picker, placeholder)} suffixIcon={suffixNode} diff --git a/components/date-picker/generatePicker/generateSinglePicker.tsx b/components/date-picker/generatePicker/generateSinglePicker.tsx index 6c189b57fd..1fb7f8fb1e 100644 --- a/components/date-picker/generatePicker/generateSinglePicker.tsx +++ b/components/date-picker/generatePicker/generateSinglePicker.tsx @@ -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 = ( ref={innerRef} placeholder={getPlaceholder(locale, mergedPicker, placeholder)} suffixIcon={suffixNode} - dropdownAlign={transPlacement2DropdownAlign(direction, placement)} placement={placement} prevIcon={} nextIcon={} diff --git a/components/date-picker/index.tsx b/components/date-picker/index.tsx index e897918e95..f9bb811cf5 100755 --- a/components/date-picker/index.tsx +++ b/components/date-picker/index.tsx @@ -8,7 +8,6 @@ import type { PickerProps, PickerPropsWithMultiple, } from './generatePicker/interface'; -import { transPlacement2DropdownAlign } from './util'; export type DatePickerProps = 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; diff --git a/components/date-picker/util.ts b/components/date-picker/util.ts index b35d7e73cf..a9fbb25a66 100644 --- a/components/date-picker/util.ts +++ b/components/date-picker/util.ts @@ -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, prefixCls: string) { const { allowClear = true } = props;