mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
chore: fix merge conflict
This commit is contained in:
parent
8749c1ae04
commit
07520b44c4
@ -48,7 +48,7 @@ type InternalMenuProps = MenuProps &
|
||||
};
|
||||
|
||||
const InternalMenu = forwardRef<MenuRef, InternalMenuProps>((props, ref) => {
|
||||
const override = React.useContext(OverrideContext) || {};
|
||||
const override = React.useContext(OverrideContext);
|
||||
const overrideObj = override || {};
|
||||
|
||||
const { getPrefixCls, getPopupContainer, direction } = React.useContext(ConfigContext);
|
||||
@ -102,7 +102,7 @@ const InternalMenu = forwardRef<MenuRef, InternalMenuProps>((props, ref) => {
|
||||
// Tell dropdown that item clicked
|
||||
const onItemClick = useEvent<Required<MenuProps>['onClick']>((...args) => {
|
||||
onClick?.(...args);
|
||||
override?.onClick?.();
|
||||
overrideObj.onClick?.();
|
||||
});
|
||||
|
||||
// ========================== Mode ===========================
|
||||
|
@ -1,90 +0,0 @@
|
||||
import type {
|
||||
HolderReadyCallback as RCHolderReadyCallback,
|
||||
NoticeContent as RCNoticeContent,
|
||||
NotificationInstance as RCNotificationInstance,
|
||||
} from 'rc-notification/lib/Notification';
|
||||
import useRCNotification from 'rc-notification/lib/useNotification';
|
||||
import * as React from 'react';
|
||||
import type { ArgsProps, MessageInstance, ThenableArgument } from '..';
|
||||
import { attachTypeApi, getKeyThenIncreaseKey, typeList } from '..';
|
||||
import type { ConfigConsumerProps } from '../../config-provider';
|
||||
import { ConfigConsumer } from '../../config-provider';
|
||||
|
||||
export default function createUseMessage(
|
||||
getRcNotificationInstance: (
|
||||
args: ArgsProps,
|
||||
callback: (info: { prefixCls: string; instance: RCNotificationInstance }) => void,
|
||||
) => void,
|
||||
getRCNoticeProps: (args: ArgsProps, prefixCls: string) => RCNoticeContent,
|
||||
) {
|
||||
const useMessage = (): [MessageInstance, React.ReactElement] => {
|
||||
// We can only get content by render
|
||||
let getPrefixCls: ConfigConsumerProps['getPrefixCls'];
|
||||
let getPopupContainer: ConfigConsumerProps['getPopupContainer'];
|
||||
|
||||
// We create a proxy to handle delay created instance
|
||||
let innerInstance: RCNotificationInstance | null = null;
|
||||
const proxy = {
|
||||
add: (noticeProps: RCNoticeContent, holderCallback?: RCHolderReadyCallback) => {
|
||||
innerInstance?.component.add(noticeProps, holderCallback);
|
||||
},
|
||||
} as any;
|
||||
|
||||
const [hookNotify, holder] = useRCNotification(proxy);
|
||||
|
||||
function notify(args: ArgsProps) {
|
||||
const { prefixCls: customizePrefixCls } = args;
|
||||
const mergedPrefixCls = getPrefixCls('message', customizePrefixCls);
|
||||
const rootPrefixCls = getPrefixCls();
|
||||
const target = args.key || getKeyThenIncreaseKey();
|
||||
const closePromise = new Promise(resolve => {
|
||||
const callback = () => {
|
||||
if (typeof args.onClose === 'function') {
|
||||
args.onClose();
|
||||
}
|
||||
return resolve(true);
|
||||
};
|
||||
getRcNotificationInstance(
|
||||
{
|
||||
...args,
|
||||
prefixCls: mergedPrefixCls,
|
||||
rootPrefixCls,
|
||||
getPopupContainer,
|
||||
},
|
||||
({ prefixCls, instance }) => {
|
||||
innerInstance = instance;
|
||||
hookNotify(getRCNoticeProps({ ...args, key: target, onClose: callback }, prefixCls));
|
||||
},
|
||||
);
|
||||
});
|
||||
const result: any = () => {
|
||||
if (innerInstance) {
|
||||
innerInstance.removeNotice(target);
|
||||
}
|
||||
};
|
||||
result.then = (filled: ThenableArgument, rejected: ThenableArgument) =>
|
||||
closePromise.then(filled, rejected);
|
||||
result.promise = closePromise;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Fill functions
|
||||
const hookApiRef = React.useRef<any>({});
|
||||
|
||||
hookApiRef.current.open = notify;
|
||||
|
||||
typeList.forEach(type => attachTypeApi(hookApiRef.current, type));
|
||||
|
||||
return [
|
||||
hookApiRef.current,
|
||||
<ConfigConsumer key="holder">
|
||||
{(context: ConfigConsumerProps) => {
|
||||
({ getPrefixCls, getPopupContainer } = context);
|
||||
return holder;
|
||||
}}
|
||||
</ConfigConsumer>,
|
||||
];
|
||||
};
|
||||
|
||||
return useMessage;
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
import type {
|
||||
HolderReadyCallback as RCHolderReadyCallback,
|
||||
NoticeContent as RCNoticeContent,
|
||||
NotificationInstance as RCNotificationInstance,
|
||||
} from 'rc-notification/lib/Notification';
|
||||
import useRCNotification from 'rc-notification/lib/useNotification';
|
||||
import * as React from 'react';
|
||||
import type { ArgsProps, NotificationInstance } from '..';
|
||||
import type { ConfigConsumerProps } from '../../config-provider';
|
||||
import { ConfigConsumer } from '../../config-provider';
|
||||
|
||||
export default function createUseNotification(
|
||||
getNotificationInstance: (
|
||||
args: ArgsProps,
|
||||
callback: (info: { prefixCls: string; instance: RCNotificationInstance }) => void,
|
||||
) => void,
|
||||
getRCNoticeProps: (args: ArgsProps, prefixCls: string) => RCNoticeContent,
|
||||
) {
|
||||
const useNotification = (): [NotificationInstance, React.ReactElement] => {
|
||||
// We can only get content by render
|
||||
let getPrefixCls: ConfigConsumerProps['getPrefixCls'];
|
||||
|
||||
// We create a proxy to handle delay created instance
|
||||
let innerInstance: RCNotificationInstance | null = null;
|
||||
const proxy = {
|
||||
add: (noticeProps: RCNoticeContent, holderCallback?: RCHolderReadyCallback) => {
|
||||
innerInstance?.component.add(noticeProps, holderCallback);
|
||||
},
|
||||
} as any;
|
||||
|
||||
const [hookNotify, holder] = useRCNotification(proxy);
|
||||
|
||||
function notify(args: ArgsProps) {
|
||||
const { prefixCls: customizePrefixCls } = args;
|
||||
const mergedPrefixCls = getPrefixCls('notification', customizePrefixCls);
|
||||
|
||||
getNotificationInstance(
|
||||
{
|
||||
...args,
|
||||
prefixCls: mergedPrefixCls,
|
||||
},
|
||||
({ prefixCls, instance }) => {
|
||||
innerInstance = instance;
|
||||
hookNotify(getRCNoticeProps(args, prefixCls));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Fill functions
|
||||
const hookApiRef = React.useRef<any>({});
|
||||
|
||||
hookApiRef.current.open = notify;
|
||||
|
||||
['success', 'info', 'warning', 'error'].forEach(type => {
|
||||
hookApiRef.current[type] = (args: ArgsProps) =>
|
||||
hookApiRef.current.open({
|
||||
...args,
|
||||
type,
|
||||
});
|
||||
});
|
||||
|
||||
return [
|
||||
hookApiRef.current,
|
||||
<ConfigConsumer key="holder">
|
||||
{(context: ConfigConsumerProps) => {
|
||||
({ getPrefixCls } = context);
|
||||
return holder;
|
||||
}}
|
||||
</ConfigConsumer>,
|
||||
];
|
||||
};
|
||||
|
||||
return useNotification;
|
||||
}
|
@ -87,5 +87,3 @@
|
||||
font-size: @font-size-base;
|
||||
}
|
||||
}
|
||||
|
||||
@import './rtl';
|
||||
|
Loading…
Reference in New Issue
Block a user