1+ import { CSSMotionList } from '@rc-component/motion' ;
12import type { CSSMotionProps } from '@rc-component/motion' ;
3+ import { clsx } from 'clsx' ;
24import * as React from 'react' ;
5+ import Notification , {
6+ type NotificationClassNames ,
7+ type NotificationProps ,
8+ type NotificationStyles ,
9+ } from './Notification' ;
310
411export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' ;
512
@@ -11,18 +18,69 @@ export type StackConfig =
1118 gap ?: number ;
1219 } ;
1320
21+ export interface NotificationListConfig extends NotificationProps {
22+ key : React . Key ;
23+ }
24+
1425export interface NotificationListProps {
26+ configList ?: NotificationListConfig [ ] ;
1527 prefixCls ?: string ;
1628 getContainer ?: ( ) => HTMLElement | ShadowRoot ;
1729 placement ?: Placement ;
1830 pauseOnHover ?: boolean ;
31+ classNames ?: NotificationClassNames ;
32+ styles ?: NotificationStyles ;
1933 stack ?: StackConfig ;
2034 maxCount ?: number ;
2135 motion ?: CSSMotionProps | ( ( placement : Placement ) => CSSMotionProps ) ;
2236}
2337
24- const NotificationList : React . FC < NotificationListProps > = ( ) => {
25- return null ;
38+ const NotificationList : React . FC < NotificationListProps > = ( props ) => {
39+ const { configList = [ ] , pauseOnHover, classNames, styles, maxCount, motion, placement } = props ;
40+
41+ // ========================== Data ==========================
42+ const mergedConfigList =
43+ typeof maxCount === 'number' && maxCount > 0 ? configList . slice ( - maxCount ) : configList ;
44+
45+ const keys = mergedConfigList . map ( ( config ) => ( {
46+ config,
47+ key : String ( config . key ) ,
48+ } ) ) ;
49+
50+ // ========================= Motion =========================
51+ const placementMotion = typeof motion === 'function' ? motion ( placement ) : motion ;
52+
53+ // ========================= Render =========================
54+ return (
55+ < CSSMotionList component = "div" keys = { keys } motionAppear { ...placementMotion } >
56+ { ( { config, className, style } , nodeRef ) => (
57+ < Notification
58+ { ...config }
59+ ref = { nodeRef }
60+ className = { clsx ( className , config . className ) }
61+ style = { {
62+ ...style ,
63+ ...config . style ,
64+ } }
65+ classNames = { {
66+ root : clsx ( classNames ?. root , config . classNames ?. root ) ,
67+ close : clsx ( classNames ?. close , config . classNames ?. close ) ,
68+ } }
69+ styles = { {
70+ root : {
71+ ...styles ?. root ,
72+ ...config . styles ?. root ,
73+ } ,
74+ close : {
75+ ...styles ?. close ,
76+ ...config . styles ?. close ,
77+ } ,
78+ } }
79+ pauseOnHover = { config . pauseOnHover ?? pauseOnHover }
80+ />
81+ ) }
82+ </ CSSMotionList >
83+ ) ;
2684} ;
2785
2886export default NotificationList ;
0 commit comments