@@ -22,7 +22,7 @@ export interface NotificationStyles {
2222
2323export interface NotificationProps {
2424 // Style
25- prefixCls ? : string ;
25+ prefixCls : string ;
2626 className ?: string ;
2727 style ?: React . CSSProperties ;
2828 classNames ?: NotificationClassNames ;
@@ -31,7 +31,6 @@ export interface NotificationProps {
3131 // UI
3232 content ?: React . ReactNode ;
3333 actions ?: React . ReactNode ;
34- close ?: React . ReactNode ;
3534 closable ?: ClosableType ;
3635 offset ?: {
3736 x : number ;
@@ -50,13 +49,14 @@ export interface NotificationProps {
5049 onClick ?: React . MouseEventHandler < HTMLDivElement > ;
5150 onMouseEnter ?: React . MouseEventHandler < HTMLDivElement > ;
5251 onMouseLeave ?: React . MouseEventHandler < HTMLDivElement > ;
52+ /** @deprecated Please use `closable.onClose` instead. */
5353 onClose ?: ( ) => void ;
5454}
5555
5656const Notification = React . forwardRef < HTMLDivElement , NotificationProps > ( ( props , ref ) => {
5757 const {
5858 // Style
59- prefixCls = 'rc-notification' ,
59+ prefixCls,
6060 className,
6161 style,
6262 classNames,
@@ -65,7 +65,6 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
6565 // UI
6666 content,
6767 actions,
68- close,
6968 closable,
7069 offset,
7170 props : rootProps ,
@@ -87,24 +86,16 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
8786 const noticePrefixCls = `${ prefixCls } -notice` ;
8887
8988 // ========================= Close ==========================
90- const onEventClose = useEvent ( onClose ) ;
91-
92- const [ closableEnabled , closableConfig , closeBtnAriaProps ] = useClosable ( closable ) ;
93- const closeContent = close === undefined ? closableConfig . closeIcon : close ;
94- const mergedClosable = close !== undefined ? close !== null : closableEnabled ;
89+ const [ mergedClosable , closableConfig , closeBtnAriaProps ] = useClosable ( closable ) ;
90+ const onInternalClose = useEvent ( ( ) => {
91+ closableConfig . onClose ?. ( ) ;
92+ onClose ?. ( ) ;
93+ } ) ;
9594
9695 // ======================== Duration ========================
9796 const [ hovering , setHovering ] = React . useState ( false ) ;
9897
99- const [ onResume , onPause ] = useNoticeTimer (
100- duration ,
101- ( ) => {
102- closableConfig . onClose ?.( ) ;
103- onEventClose ( ) ;
104- } ,
105- setPercent ,
106- ! ! showProgress ,
107- ) ;
98+ const [ onResume , onPause ] = useNoticeTimer ( duration , onInternalClose , setPercent , ! ! showProgress ) ;
10899
109100 const validPercent = 100 - Math . min ( Math . max ( percent * 100 , 0 ) , 100 ) ;
110101
@@ -137,6 +128,12 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
137128 onMouseLeave ?.( event ) ;
138129 }
139130
131+ function onInternalCloseClick ( event : React . MouseEvent < HTMLButtonElement > ) {
132+ event . preventDefault ( ) ;
133+ event . stopPropagation ( ) ;
134+ onInternalClose ( ) ;
135+ }
136+
140137 // ======================== Position ========================
141138 const offsetRef = React . useRef ( offset ) ;
142139 if ( offset ) {
@@ -182,35 +179,22 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
182179 aria-label = "Close"
183180 { ...closeBtnAriaProps }
184181 style = { styles ?. close }
185- onKeyDown = { ( event ) => {
186- if ( event . key === 'Enter' || event . code === 'Enter' ) {
187- closableConfig . onClose ?.( ) ;
188- onEventClose ( ) ;
189- }
190- } }
191- onClick = { ( e ) => {
192- e . preventDefault ( ) ;
193- e . stopPropagation ( ) ;
194- closableConfig . onClose ?.( ) ;
195- onEventClose ( ) ;
196- } }
182+ onClick = { onInternalCloseClick }
197183 >
198- { closeContent }
184+ { closableConfig . closeIcon }
199185 </ button >
200186 ) }
201187
188+ { actions && < div className = "actions" > { actions } </ div > }
189+
202190 { showProgress && typeof duration === 'number' && duration > 0 && (
203191 < progress
204192 className = { clsx ( `${ noticePrefixCls } -progress` , classNames ?. progress ) }
205193 max = "100"
206194 value = { validPercent }
207195 style = { styles ?. progress }
208- >
209- { validPercent } %
210- </ progress >
196+ />
211197 ) }
212-
213- { actions && < div className = "actions" > { actions } </ div > }
214198 </ div >
215199 ) ;
216200} ) ;
0 commit comments