diff --git a/components/message/__docs__/demo/withContext/index.tsx b/components/message/__docs__/demo/withContext/index.tsx index a3a0455584..2575ea009b 100644 --- a/components/message/__docs__/demo/withContext/index.tsx +++ b/components/message/__docs__/demo/withContext/index.tsx @@ -1,5 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; + ReactDOM.render( 点击查看 Message.withContext Demo diff --git a/components/message/__docs__/theme/index.tsx b/components/message/__docs__/theme/index.tsx index a180066cb0..236914b5b8 100644 --- a/components/message/__docs__/theme/index.tsx +++ b/components/message/__docs__/theme/index.tsx @@ -10,6 +10,7 @@ import { type DemoFunctionDefineForObject, } from '../../../demo-helper'; import Message from '../../index'; + const i18nMap = { 'en-us': { title: 'Title', @@ -85,11 +86,6 @@ class FunctionDemo extends React.Component { const title = demoFunction.hasTitle.value === 'true' ? i18n.title : null; const closeable = demoFunction.closeable.value === 'true'; - const style = { - lineHeight: 1.7, - margin: 0, - }; - const newChildren = shapes.map(shape => { const content = types.map(type => { const children = (['large', 'medium'] as const).map(size => ( diff --git a/components/message/__tests__/index-spec.tsx b/components/message/__tests__/index-spec.tsx index 2875011e7b..f7111a3fc0 100644 --- a/components/message/__tests__/index-spec.tsx +++ b/components/message/__tests__/index-spec.tsx @@ -1,5 +1,5 @@ -import React, { ReactElement } from 'react'; -import { MountReturn } from 'cypress/react'; +import React, { type ReactElement } from 'react'; +import { type MountReturn } from 'cypress/react'; import Button from '../../button'; import ConfigProvider from '../../config-provider'; import { env } from '../../util'; @@ -321,8 +321,8 @@ describe('toast quick-calling', () => { describe('Message v2', () => { it('should support config to open multiple instance', done => { Message.config({}); - const instance1 = Message.show('content'); - const instance2 = Message.success('content'); + Message.show('content'); + Message.success('content'); cy.get('.next-message-wrapper-v2 .next-message').should('have.length', 2); cy.clock(); Message.destory(); diff --git a/components/message/message.tsx b/components/message/message.tsx index 495f188d07..025bbc2f27 100644 --- a/components/message/message.tsx +++ b/components/message/message.tsx @@ -7,9 +7,9 @@ import Icon from '../icon'; import Animate from '../animate'; import ConfigProvider from '../config-provider'; import { obj } from '../util'; -import { MessageProps } from './types'; -import toast, { withContext } from './toast'; -import toast2 from './toast2'; +import type { MessageProps } from './types'; +import toast, { type withContext } from './toast'; +import type toast2 from './toast2'; type Toast = typeof toast; type Toast2 = typeof toast2; @@ -97,7 +97,6 @@ class Message extends Component { render() { const { prefix, - pure, className, style, type, @@ -105,11 +104,8 @@ class Message extends Component { size, title, children, - defaultVisible, - visible: propsVisible, iconType: icon, closeable, - onClose, afterClose, animation, rtl, diff --git a/components/message/toast.tsx b/components/message/toast.tsx index 26b85a1f6c..23a0afcec9 100644 --- a/components/message/toast.tsx +++ b/components/message/toast.tsx @@ -5,8 +5,8 @@ import Overlay from '../overlay'; import ConfigProvider from '../config-provider'; import { guid } from '../util'; import Message from './message'; -import { OpenProps, MessageQuickProps } from './types'; -import { ConfiguredComponent } from '../config-provider/types'; +import type { OpenProps, MessageQuickProps } from './types'; +import type { ConfiguredComponent } from '../config-provider/types'; type ConfigMask = ConfiguredComponent | null; @@ -125,11 +125,10 @@ const NewMask = config(Mask); const create = (props: MessageQuickProps) => { const { duration, afterClose, contextConfig, ...others } = props; - /* eslint-enable no-unused-vars */ - const div = document.createElement('div'); document.body.appendChild(div); const closeChain = function () { + // eslint-disable-next-line react/no-deprecated ReactDOM.unmountComponentAtNode(div); document.body.removeChild(div); afterClose && afterClose(); @@ -146,6 +145,7 @@ const create = (props: MessageQuickProps) => { destroyed = true; }; + // eslint-disable-next-line react/no-deprecated ReactDOM.render( { }; }; +function isObject(obj: unknown) { + return {}.toString.call(obj) === '[object Object]'; +} + function handleConfig(config: OpenProps, type?: MessageQuickProps['type']) { let newConfig: MessageQuickProps = {}; @@ -189,8 +193,11 @@ function handleConfig(config: OpenProps, type?: MessageQuickProps['type']) { return newConfig; } -function isObject(obj: unknown) { - return {}.toString.call(obj) === '[object Object]'; +function close() { + if (instance) { + instance.destroy(); + instance = null; + } } function open(config: OpenProps, type?: MessageQuickProps['type']) { @@ -205,17 +212,9 @@ function open(config: OpenProps, type?: MessageQuickProps['type']) { } } -function close() { - if (instance) { - instance.destroy(); - instance = null; - } -} - /** * 创建提示弹层 - * @exportName show - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function show(config: OpenProps) { open(config); @@ -223,7 +222,6 @@ function show(config: OpenProps) { /** * 关闭提示弹层 - * @exportName hide */ function hide() { close(); @@ -231,8 +229,7 @@ function hide() { /** * 创建成功提示弹层 - * @exportName success - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function success(config: OpenProps) { open(config, 'success'); @@ -240,8 +237,7 @@ function success(config: OpenProps) { /** * 创建警告提示弹层 - * @exportName warning - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function warning(config: OpenProps) { open(config, 'warning'); @@ -249,8 +245,7 @@ function warning(config: OpenProps) { /** * 创建错误提示弹层 - * @exportName error - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function error(config: OpenProps) { open(config, 'error'); @@ -258,8 +253,7 @@ function error(config: OpenProps) { /** * 创建帮助提示弹层 - * @exportName help - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function help(config: OpenProps) { open(config, 'help'); @@ -267,8 +261,7 @@ function help(config: OpenProps) { /** * 创建加载中提示弹层 - * @exportName loading - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function loading(config: OpenProps) { open(config, 'loading'); @@ -276,8 +269,7 @@ function loading(config: OpenProps) { /** * 创建通知提示弹层 - * @exportName notice - * @param {Object} props 属性对象 + * @param config - 属性对象 */ function notice(config: OpenProps) { open(config, 'notice'); @@ -294,9 +286,7 @@ export default { notice, }; -export const withContext = ( - WrappedComponent: React.ComponentType -) => { +export const withContext = (WrappedComponent: React.ComponentType) => { const HOC = (props: T) => { return ( diff --git a/components/message/toast2.tsx b/components/message/toast2.tsx index 1c7166c967..f32bf3cb01 100644 --- a/components/message/toast2.tsx +++ b/components/message/toast2.tsx @@ -4,7 +4,12 @@ import ConfigProvider from '../config-provider'; import Animate from '../animate'; import Message from './message'; import { obj, log, guid } from '../util'; -import { OpenProps, MessageQuickProps, MessageWrapperProps, MessageWrapperItem } from './types'; +import type { + OpenProps, + MessageQuickProps, + MessageWrapperProps, + MessageWrapperItem, +} from './types'; const config = { top: 8, @@ -92,6 +97,7 @@ const createMessage = (props: MessageQuickProps & { key?: string }) => { messageList.shift(); } + // eslint-disable-next-line react/no-deprecated ReactDOM.render( @@ -110,6 +116,7 @@ const createMessage = (props: MessageQuickProps & { key?: string }) => { typeof item.onClose === 'function' && item.onClose(); messageList.splice(idx, 1); + // eslint-disable-next-line react/no-deprecated ReactDOM.render( @@ -130,6 +137,7 @@ function close(key?: string) { } if (messageRootNode) { + // eslint-disable-next-line react/no-deprecated ReactDOM.render( @@ -165,6 +173,7 @@ function open(type?: MessageQuickProps['type']) { function destory() { if (!messageRootNode) return; if (messageRootNode) { + // eslint-disable-next-line react/no-deprecated ReactDOM.unmountComponentAtNode(messageRootNode); messageRootNode.parentNode!.removeChild(messageRootNode); messageRootNode = null; diff --git a/components/message/types.ts b/components/message/types.ts index 4f02e23dda..a965c1b650 100644 --- a/components/message/types.ts +++ b/components/message/types.ts @@ -1,10 +1,9 @@ -import React from 'react'; -import { CommonProps } from '../util'; -import { OverlayProps } from '../overlay'; -import { ConsumerState } from '../config-provider/consumer'; -interface HTMLAttributesWeak extends React.HTMLAttributes { - title?: any; -} +import type React from 'react'; +import type { CommonProps } from '../util'; +import type { OverlayProps } from '../overlay'; +import type { ConsumerState } from '../config-provider/consumer'; + +type HTMLAttributesWeak = Omit, 'title'>; /** * @api Message @@ -118,7 +117,7 @@ export interface MessageQuickProps extends Omit, /** * 弹层相对于参照元素定位的微调 */ - offset?: Array; + offset?: Array; /** * 是否显示遮罩 */