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