mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
chore: code optimization (#49894)
This commit is contained in:
parent
0e9de2e070
commit
a9d3939136
5
components/date-picker/generatePicker/constant.ts
Normal file
5
components/date-picker/generatePicker/constant.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export const [WEEK, WEEKPICKER] = ['week', 'WeekPicker'] as const;
|
||||
export const [MONTH, MONTHPICKER] = ['month', 'MonthPicker'] as const;
|
||||
export const [YEAR, YEARPICKER] = ['year', 'YearPicker'] as const;
|
||||
export const [QUARTER, QUARTERPICKER] = ['quarter', 'QuarterPicker'] as const;
|
||||
export const [TIME, TIMEPICKER] = ['time', 'TimePicker'] as const;
|
@ -24,6 +24,7 @@ import { useCompactItemContext } from '../../space/Compact';
|
||||
import enUS from '../locale/en_US';
|
||||
import useStyle from '../style';
|
||||
import { getRangePlaceholder, transPlacement2DropdownAlign, useIcons } from '../util';
|
||||
import { TIME } from './constant';
|
||||
import type { RangePickerProps } from './interface';
|
||||
import useComponents from './useComponents';
|
||||
|
||||
@ -49,6 +50,7 @@ export default function generateRangePicker<DateType extends AnyObject>(
|
||||
status: customStatus,
|
||||
rootClassName,
|
||||
variant: customVariant,
|
||||
picker,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
@ -56,7 +58,6 @@ export default function generateRangePicker<DateType extends AnyObject>(
|
||||
const { getPrefixCls, direction, getPopupContainer, rangePicker } = useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('picker', customizePrefixCls);
|
||||
const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction);
|
||||
const { picker } = props;
|
||||
const rootPrefixCls = getPrefixCls();
|
||||
|
||||
const [variant, enableVariantCls] = useVariant('rangePicker', customVariant, bordered);
|
||||
@ -92,7 +93,7 @@ export default function generateRangePicker<DateType extends AnyObject>(
|
||||
|
||||
const suffixNode = (
|
||||
<>
|
||||
{picker === 'time' ? <ClockCircleOutlined /> : <CalendarOutlined />}
|
||||
{picker === TIME ? <ClockCircleOutlined /> : <CalendarOutlined />}
|
||||
{hasFeedback && feedbackIcon}
|
||||
</>
|
||||
);
|
||||
@ -125,6 +126,7 @@ export default function generateRangePicker<DateType extends AnyObject>(
|
||||
superPrevIcon={<span className={`${prefixCls}-super-prev-icon`} />}
|
||||
superNextIcon={<span className={`${prefixCls}-super-next-icon`} />}
|
||||
transitionName={`${rootPrefixCls}-slide-up`}
|
||||
picker={picker}
|
||||
{...restProps}
|
||||
className={classNames(
|
||||
{
|
||||
|
@ -24,21 +24,27 @@ import { useCompactItemContext } from '../../space/Compact';
|
||||
import enUS from '../locale/en_US';
|
||||
import useStyle from '../style';
|
||||
import { getPlaceholder, transPlacement2DropdownAlign, useIcons } from '../util';
|
||||
import {
|
||||
MONTH,
|
||||
MONTHPICKER,
|
||||
QUARTER,
|
||||
QUARTERPICKER,
|
||||
TIME,
|
||||
TIMEPICKER,
|
||||
WEEK,
|
||||
WEEKPICKER,
|
||||
YEAR,
|
||||
YEARPICKER,
|
||||
} from './constant';
|
||||
import type { GenericTimePickerProps, PickerProps, PickerPropsWithMultiple } from './interface';
|
||||
import useComponents from './useComponents';
|
||||
|
||||
const [WEEK, WEEKPICKER] = ['week', 'WeekPicker'] as const;
|
||||
const [MONTH, MONTHPICKER] = ['month', 'MonthPicker'] as const;
|
||||
const [YEAR, YEARPICKER] = ['year', 'YearPicker'] as const;
|
||||
const [QUARTER, QUARTERPICKER] = ['quarter', 'QuarterPicker'] as const;
|
||||
const [TIME, TIMEPICKER] = ['time', 'TimePicker'] as const;
|
||||
|
||||
const generatePicker = <DateType extends AnyObject>(generateConfig: GenerateConfig<DateType>) => {
|
||||
type DatePickerProps = PickerProps<DateType>;
|
||||
type TimePickerProps = GenericTimePickerProps<DateType>;
|
||||
|
||||
const getPicker = <P extends DatePickerProps>(picker?: PickerMode, displayName?: string) => {
|
||||
const consumerName = displayName === 'TimePicker' ? 'timePicker' : 'datePicker';
|
||||
const consumerName = displayName === TIMEPICKER ? 'timePicker' : 'datePicker';
|
||||
const Picker = forwardRef<PickerRef, P>((props, ref) => {
|
||||
const {
|
||||
prefixCls: customizePrefixCls,
|
||||
|
Loading…
Reference in New Issue
Block a user