From 4740d8cae6f53023040ccf4a6636b72dae33f127 Mon Sep 17 00:00:00 2001 From: yinkaihui Date: Fri, 26 Apr 2024 16:22:39 +0800 Subject: [PATCH] feat: message.config supports closable --- components/Message/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/Message/index.tsx b/components/Message/index.tsx index 28ea0cb40b..9fa9bb3ae5 100644 --- a/components/Message/index.tsx +++ b/components/Message/index.tsx @@ -22,6 +22,7 @@ export type ConfigProps = { getContainer?: () => HTMLElement; duration?: number; rtl?: boolean; + closable?: boolean; }; let maxCount; @@ -29,6 +30,7 @@ let prefixCls; let duration; let container; let rtl; +let closable; export interface MessageType { (): void; @@ -138,6 +140,9 @@ class Message extends BaseNotification { if (typeof options.rtl === 'boolean') { rtl = options.rtl; } + if (typeof options.closable === 'boolean') { + closable = options.closable; + } if (options.getContainer && options.getContainer() !== container) { container = options.getContainer(); Object.values(messageInstance).forEach(({ instance }) => instance?.clear()); @@ -174,10 +179,12 @@ class Message extends BaseNotification { transitionTimeout: _transitionTimeout, prefixCls: _prefixCls, rtl: _rtl, + closable: _closable, } = this.props; const { notices, position } = this.state; const mergedPrefixCls = _prefixCls || prefixCls; const mergedRtl = !isUndefined(_rtl) ? _rtl : rtl; + const mergeClosable = !isUndefined(_closable) ? _closable : closable; const prefixClsMessage = mergedPrefixCls ? `${mergedPrefixCls}-message` : 'arco-message'; const transitionTimeout = { enter: isNumber(_transitionTimeout?.enter) ? _transitionTimeout?.enter : 100, @@ -212,6 +219,7 @@ class Message extends BaseNotification { onClose={this.remove} noticeType="message" rtl={mergedRtl} + {...(isUndefined(mergeClosable) ? {} : { closable: mergeClosable })} /> ))}