Revert "feat: Add okButtonProps to time picker (#49657)" (#49663)

This reverts commit 6c656c85f7.

Co-authored-by: 二货爱吃白萝卜 <smith3816@gmail.com>
This commit is contained in:
陈帅 2024-07-01 00:23:07 -07:00 committed by GitHub
parent a8e739848e
commit 09b86845a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 27 additions and 1601 deletions

View File

@ -0,0 +1,8 @@
import * as React from 'react';
import Button from '../button';
import type { ButtonProps } from '../button';
export default function PickerButton(props: ButtonProps) {
return <Button size="small" type="primary" {...props} />;
}

View File

@ -4,8 +4,8 @@ import CalendarOutlined from '@ant-design/icons/CalendarOutlined';
import ClockCircleOutlined from '@ant-design/icons/ClockCircleOutlined';
import SwapRightOutlined from '@ant-design/icons/SwapRightOutlined';
import classNames from 'classnames';
import type { PickerRef } from 'rc-picker';
import { RangePicker as RCRangePicker } from 'rc-picker';
import type { PickerRef } from 'rc-picker';
import type { GenerateConfig } from 'rc-picker/lib/generate/index';
import ContextIsolator from '../../_util/ContextIsolator';
@ -49,7 +49,6 @@ export default function generateRangePicker<DateType extends AnyObject>(
status: customStatus,
rootClassName,
variant: customVariant,
okButtonProps,
...restProps
} = props;
@ -78,7 +77,7 @@ export default function generateRangePicker<DateType extends AnyObject>(
const [mergedAllowClear] = useIcons(props, prefixCls);
// ================== components ==================
const mergedComponents = useComponents(components, okButtonProps);
const mergedComponents = useComponents(components);
// ===================== Size =====================
const mergedSize = useSize((ctx) => customizeSize ?? compactSize ?? ctx);

View File

@ -3,8 +3,8 @@ import { forwardRef, useContext, useImperativeHandle } from 'react';
import CalendarOutlined from '@ant-design/icons/CalendarOutlined';
import ClockCircleOutlined from '@ant-design/icons/ClockCircleOutlined';
import classNames from 'classnames';
import type { PickerRef } from 'rc-picker';
import RCPicker from 'rc-picker';
import type { PickerRef } from 'rc-picker';
import type { GenerateConfig } from 'rc-picker/lib/generate/index';
import type { PickerMode } from 'rc-picker/lib/interface';
@ -56,7 +56,6 @@ export default function generatePicker<DateType extends AnyObject>(
status: customStatus,
variant: customVariant,
onCalendarChange,
okButtonProps,
...restProps
} = props;
@ -120,7 +119,7 @@ export default function generatePicker<DateType extends AnyObject>(
const [mergedAllowClear, removeIcon] = useIcons(props, prefixCls);
// ================== components ==================
const mergedComponents = useComponents(components, okButtonProps);
const mergedComponents = useComponents(components);
// ===================== Size =====================
const mergedSize = useSize((ctx) => customizeSize ?? compactSize ?? ctx);

View File

@ -1,6 +1,6 @@
import type {
PickerProps as RcPickerProps,
PickerRef,
PickerProps as RcPickerProps,
RangePickerProps as RcRangePickerProps,
} from 'rc-picker';
import type { Locale as RcPickerLocale } from 'rc-picker/lib/interface';
@ -10,7 +10,6 @@ import type { AnyObject } from '../../_util/type';
import type { SizeType } from '../../config-provider/SizeContext';
import type { Variant } from '../../config-provider';
import type { TimePickerLocale } from '../../time-picker';
import type { ButtonProps } from '../../button/button';
const DataPickerPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
@ -62,7 +61,6 @@ type InjectDefaultProps<Props> = Omit<Props, 'locale' | 'generateConfig' | 'hide
popupClassName?: string;
rootClassName?: string;
popupStyle?: React.CSSProperties;
okButtonProps?: ButtonProps;
};
/** Base Single Picker props */

View File

@ -0,0 +1,14 @@
import { useMemo } from 'react';
import type { Components } from 'rc-picker/lib/interface';
import PickerButton from '../PickerButton';
export default function useComponents(components?: Components) {
return useMemo(
() => ({
button: PickerButton,
...components,
}),
[components],
);
}

View File

@ -1,21 +0,0 @@
import React, { useMemo } from 'react';
import type { Components } from 'rc-picker/lib/interface';
import type { ButtonProps } from '../../button/button';
import Button from '../../button/button';
export default function useComponents(components?: Components, buttonProps?: ButtonProps) {
function PickerButton(props: ButtonProps) {
const mergedProps = { size: 'small', type: 'primary', ...buttonProps, ...props } as ButtonProps;
return <Button {...mergedProps} />;
}
return useMemo(
() => ({
button: PickerButton,
...components,
}),
[components],
);
}

View File

@ -154,7 +154,6 @@ The following APIs are shared by DatePicker, RangePicker.
| value | To set date | [dayjs](https://day.js.org/) | - | |
| onChange | Callback function, can be executed when the selected time is changing | function(date: dayjs, dateString: string) | - | |
| onOk | Callback when click ok button | function() | - | |
| okButtonProps | The ok button props | [ButtonProps](/components/button/#api) | - | |
| onPanelChange | Callback function for panel changing | function(value, mode) | - | |
### DatePicker\[picker=year]

View File

@ -99,11 +99,4 @@ describe('TimePicker', () => {
);
expect(container.firstChild).toMatchSnapshot();
});
it('should modify the ok button', () => {
const { container } = render(
<TimePicker open okButtonProps={{ className: 'test-ok-button' }} />,
);
expect(Array.from(container.children)).toMatchSnapshot();
});
});

View File

@ -82,7 +82,6 @@ dayjs.extend(customParseFormat)
| onCalendarChange | Callback function, can be executed when the start time or the end time of the range is changing. `info` argument is added in 4.4.0 | function(dates: \[dayjs, dayjs], dateStrings: \[string, string], info: { range:`start`\|`end` }) | - | |
| onChange | A callback function, can be executed when the selected time is changing | function(time: dayjs, timeString: string): void | - | |
| onOpenChange | A callback function which will be called while panel opening/closing | (open: boolean) => void | - | |
| okButtonProps | The ok button props | [ButtonProps](/components/button/#api) | - | |
#### DisabledTime