11import React from 'react'
2- import { REMOVAL , INSERTION , NOTIFICATION_CONTAINER , NOTIFICATION_TYPE } from 'src/utils/constants '
2+ import { iNotificationProps , iNotificationState , iNotificationParentStyle , NOTIFICATION_REMOVAL_SOURCE } from 'src'
33import {
44 getHtmlClassesForType ,
55 getTransition ,
@@ -8,92 +8,6 @@ import {
88} from 'src/utils/helpers'
99import Timer from 'src/utils/timer'
1010
11- export type { iNotification , iTransition , iTouchTransition , iDismiss , iNotificationCustomType }
12-
13- interface iNotification {
14- id ?: string
15- onRemoval ?: ( id : string , removalFlag : string ) => void
16- title ?: NotificationTitleMessage
17- message ?: NotificationTitleMessage
18- content ?: NotificationContent
19- type ?: NOTIFICATION_TYPE
20- container ?: NOTIFICATION_CONTAINER
21- insert ?: INSERTION
22- dismiss ?: iDismiss
23- animationIn ?: string [ ]
24- animationOut ?: string [ ]
25- slidingEnter ?: iTransition
26- slidingExit ?: iTransition
27- touchRevert ?: iTransition
28- touchSlidingExit ?: {
29- fade : iTransition
30- swipe : iTransition
31- }
32- userDefinedTypes ?: iNotificationCustomType [ ]
33- width ?: number
34- hasBeenRemoved ?: boolean
35- }
36-
37- export type NotificationTitleMessage = string | React . ReactNode | React . FunctionComponent
38- export type NotificationContent =
39- | React . ComponentClass < any , any >
40- | React . FunctionComponent < any >
41- | React . ReactElement
42-
43- interface iTransition {
44- duration : number
45- timingFunction : string
46- delay : number
47- }
48-
49- interface iTouchTransition {
50- swipe : iTransition
51- fade : iTransition
52- }
53-
54- interface iDismiss {
55- duration : number
56- onScreen : boolean
57- pauseOnHover : boolean
58- waitForAnimation : boolean
59- click : boolean
60- touch : boolean
61- showIcon : boolean
62- }
63-
64- interface iNotificationCustomType {
65- htmlClasses : string [ ]
66- name : string
67- }
68-
69- class iNotificationProps {
70- id : string
71- notification : iNotification
72- defaultNotificationWidth : number
73- notificationsCount : number
74- isMobile : boolean
75- hasBeenRemoved : boolean
76- toggleRemoval : ( id : string , callback : ( ) => void ) => void
77- }
78-
79- interface iNotificationState {
80- parentStyle ?: iParentStyle
81- htmlClassList ?: string [ ]
82- animationPlayState ?: string
83- touchEnabled ?: boolean
84- onTransitionEnd ?: ( event : React . TransitionEvent < HTMLDivElement > ) => void
85- onAnimationEnd ?: ( event : React . AnimationEvent < HTMLDivElement > ) => void
86- startX ?: number
87- currentX ?: number
88- }
89-
90- interface iParentStyle {
91- height ?: string
92- overflow ?: string
93- width ?: string
94- transition ?: string
95- }
96-
9711class Notification extends React . Component < iNotificationProps , iNotificationState > {
9812 constructor ( props : iNotificationProps ) {
9913 super ( props )
@@ -137,7 +51,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
13751
13852 const onTransitionEnd = ( ) => {
13953 if ( ! duration || onScreen ) return
140- const callback = ( ) => this . removeNotification ( REMOVAL . TIMEOUT )
54+ const callback = ( ) => this . removeNotification ( NOTIFICATION_REMOVAL_SOURCE . TIMEOUT )
14155 this . timer = new Timer ( callback , duration )
14256 }
14357
@@ -164,7 +78,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
16478
16579 componentDidUpdate ( prevProps : iNotificationProps ) {
16680 if ( this . props . hasBeenRemoved && ! prevProps . hasBeenRemoved ) {
167- this . removeNotification ( REMOVAL . MANUAL )
81+ this . removeNotification ( NOTIFICATION_REMOVAL_SOURCE . MANUAL )
16882 }
16983
17084 if ( prevProps !== this . props ) {
@@ -190,7 +104,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
190104
191105 const htmlClassList = [ ...notification . animationOut , ...getHtmlClassesForType ( notification ) ]
192106 const onTransitionEnd = ( ) => toggleRemoval ( id , ( ) => onRemoval ( id , removalFlag ) )
193- const parentStyle : iParentStyle = {
107+ const parentStyle : iNotificationParentStyle = {
194108 height : `0px` ,
195109 overflow : 'hidden' ,
196110 transition : getTransition ( notification . slidingExit , 'height' )
@@ -226,7 +140,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
226140 notification : { dismiss }
227141 } = this . props
228142 if ( dismiss . click || dismiss . showIcon ) {
229- this . removeNotification ( REMOVAL . CLICK )
143+ this . removeNotification ( NOTIFICATION_REMOVAL_SOURCE . CLICK )
230144 }
231145 }
232146
@@ -265,7 +179,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
265179 const t1 = getTransition ( swipe , 'left' )
266180 const t2 = getTransition ( fade , 'opacity' )
267181 const onTransitionEnd = ( ) => {
268- toggleRemoval ( id , ( ) => onRemoval ( id , REMOVAL . TOUCH ) )
182+ toggleRemoval ( id , ( ) => onRemoval ( id , NOTIFICATION_REMOVAL_SOURCE . TOUCH ) )
269183 }
270184
271185 return this . setState ( ( { parentStyle } ) => ( {
@@ -349,7 +263,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
349263 animationPlayState
350264 }
351265
352- const onAnimationEnd = ( ) => this . removeNotification ( REMOVAL . TIMEOUT )
266+ const onAnimationEnd = ( ) => this . removeNotification ( NOTIFICATION_REMOVAL_SOURCE . TIMEOUT )
353267 return (
354268 < div className = "rnc__notification-timer" >
355269 < div
0 commit comments