@@ -11,24 +11,32 @@ import type { Placement, StackConfig } from '../NotificationList';
1111
1212const defaultGetContainer = ( ) => document . body ;
1313
14+ // ========================= Types ==========================
1415type OptionalConfig = Partial < NotificationListConfig > ;
16+ type SharedConfig = Pick < NotificationListConfig , 'placement' | 'closable' | 'duration' > ;
1517
1618export interface NotificationConfig {
19+ // Style
1720 prefixCls ?: string ;
21+ className ?: ( placement : Placement ) => string ;
22+ style ?: ( placement : Placement ) => React . CSSProperties ;
23+ classNames ?: NotificationClassNames ;
24+ styles ?: NotificationStyles ;
25+
26+ // UI
27+ placement ?: Placement ;
1828 getContainer ?: ( ) => HTMLElement | ShadowRoot ;
1929 motion ?: CSSMotionProps | ( ( placement : Placement ) => CSSMotionProps ) ;
20- placement ?: Placement ;
30+
31+ // Behavior
2132 closable ?: NotificationListConfig [ 'closable' ] ;
2233 duration ?: number | false | null ;
23- showProgress ?: boolean ;
2434 pauseOnHover ?: boolean ;
25- classNames ?: NotificationClassNames ;
26- styles ?: NotificationStyles ;
2735 maxCount ?: number ;
28- className ?: ( placement : Placement ) => string ;
29- style ?: ( placement : Placement ) => React . CSSProperties ;
30- onAllRemoved ?: VoidFunction ;
3136 stack ?: StackConfig ;
37+
38+ // Function
39+ onAllRemoved ?: VoidFunction ;
3240 renderNotifications ?: NotificationsProps [ 'renderNotifications' ] ;
3341}
3442
@@ -54,6 +62,7 @@ interface DestroyTask {
5462
5563type Task = OpenTask | CloseTask | DestroyTask ;
5664
65+ // ======================== Helper ==========================
5766let uniqueKey = 0 ;
5867
5968function mergeConfig < T > ( ...objList : Partial < T > [ ] ) : T {
@@ -79,28 +88,45 @@ function mergeConfig<T>(...objList: Partial<T>[]): T {
7988export default function useNotification (
8089 rootConfig : NotificationConfig = { } ,
8190) : [ NotificationAPI , React . ReactElement ] {
91+ // ========================= Config =========================
8292 const {
8393 getContainer = defaultGetContainer ,
8494 motion,
8595 prefixCls,
96+ placement,
97+ closable,
98+ duration,
99+ pauseOnHover,
100+ classNames,
101+ styles,
86102 maxCount,
87103 className,
88104 style,
89105 onAllRemoved,
90106 stack,
91107 renderNotifications,
92- ...shareConfig
93108 } = rootConfig ;
109+ const shareConfig : SharedConfig = {
110+ placement,
111+ closable,
112+ duration,
113+ } ;
94114
115+ // ========================= Holder =========================
95116 const [ container , setContainer ] = React . useState < HTMLElement | ShadowRoot > ( ) ;
96117 const notificationsRef = React . useRef < NotificationsRef | null > ( null ) ;
118+ const [ taskQueue , setTaskQueue ] = React . useState < Task [ ] > ( [ ] ) ;
119+
97120 const contextHolder = (
98121 < Notifications
99122 container = { container }
100123 ref = { notificationsRef }
101124 prefixCls = { prefixCls }
102125 motion = { motion }
103126 maxCount = { maxCount }
127+ pauseOnHover = { pauseOnHover }
128+ classNames = { classNames }
129+ styles = { styles }
104130 className = { className }
105131 style = { style }
106132 onAllRemoved = { onAllRemoved }
@@ -109,8 +135,7 @@ export default function useNotification(
109135 />
110136 ) ;
111137
112- const [ taskQueue , setTaskQueue ] = React . useState < Task [ ] > ( [ ] ) ;
113-
138+ // ========================== API ==========================
114139 const open = useEvent < NotificationAPI [ 'open' ] > ( ( config ) => {
115140 const mergedConfig = mergeConfig < NotificationListConfig > ( shareConfig , config ) ;
116141
@@ -135,6 +160,7 @@ export default function useNotification(
135160 [ open ] ,
136161 ) ;
137162
163+ // ======================== Effect =========================
138164 React . useEffect ( ( ) => {
139165 setContainer ( getContainer ( ) ) ;
140166 } ) ;
@@ -163,5 +189,6 @@ export default function useNotification(
163189 }
164190 } , [ taskQueue ] ) ;
165191
192+ // ======================== Return =========================
166193 return [ api , contextHolder ] ;
167194}
0 commit comments