mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 01:13:58 +08:00
chore: refactor message types implementation (#34654)
This commit is contained in:
parent
b77a8fdce3
commit
2282b1c580
@ -12,7 +12,7 @@ import {
|
||||
attachTypeApi,
|
||||
ThenableArgument,
|
||||
getKeyThenIncreaseKey,
|
||||
NoticeType,
|
||||
typeList,
|
||||
} from '..';
|
||||
|
||||
export default function createUseMessage(
|
||||
@ -78,9 +78,7 @@ export default function createUseMessage(
|
||||
|
||||
hookApiRef.current.open = notify;
|
||||
|
||||
(['success', 'info', 'warning', 'error', 'loading'] as NoticeType[]).forEach(type =>
|
||||
attachTypeApi(hookApiRef.current, type),
|
||||
);
|
||||
typeList.forEach(type => attachTypeApi(hookApiRef.current, type));
|
||||
|
||||
return [
|
||||
hookApiRef.current,
|
||||
|
@ -13,8 +13,6 @@ import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
|
||||
import createUseMessage from './hooks/useMessage';
|
||||
import ConfigProvider, { globalConfig } from '../config-provider';
|
||||
|
||||
export type NoticeType = 'info' | 'success' | 'error' | 'warning' | 'loading';
|
||||
|
||||
let messageInstance: RCNotificationInstance | null;
|
||||
let defaultDuration = 3;
|
||||
let defaultTop: number;
|
||||
@ -128,6 +126,11 @@ const typeToIcon = {
|
||||
warning: ExclamationCircleFilled,
|
||||
loading: LoadingOutlined,
|
||||
};
|
||||
|
||||
export type NoticeType = keyof typeof typeToIcon;
|
||||
|
||||
export const typeList = Object.keys(typeToIcon) as NoticeType[];
|
||||
|
||||
export interface ArgsProps {
|
||||
content: React.ReactNode;
|
||||
duration?: number;
|
||||
@ -247,9 +250,7 @@ export function attachTypeApi(originalApi: MessageApi, type: NoticeType) {
|
||||
};
|
||||
}
|
||||
|
||||
(['success', 'info', 'warning', 'error', 'loading'] as NoticeType[]).forEach(type =>
|
||||
attachTypeApi(api, type),
|
||||
);
|
||||
typeList.forEach(type => attachTypeApi(api, type));
|
||||
|
||||
api.warn = api.warning;
|
||||
api.useMessage = createUseMessage(getRCNotificationInstance, getRCNoticeProps);
|
||||
|
Loading…
Reference in New Issue
Block a user