@@ -14,12 +14,38 @@ const classNames = require("classnames");
14
14
import SLDSButton from "../SLDSButton" ;
15
15
import { Icon } from "../SLDSIcons" ;
16
16
17
+ const displayName = 'SLDSNotification' ;
18
+ const propTypes = {
19
+ className : React . PropTypes . string ,
20
+ content : React . PropTypes . node ,
21
+ dismissible : React . PropTypes . bool ,
22
+ duration : React . PropTypes . number ,
23
+ icon : React . PropTypes . string ,
24
+ onDismiss : React . PropTypes . func ,
25
+ texture : React . PropTypes . bool ,
26
+ theme : React . PropTypes . oneOf ( [ "success" , "warning" , "error" , "offline" ] ) ,
27
+ variant : React . PropTypes . oneOf ( [ "alert" , "toast" ] ) ,
28
+ } ;
29
+
30
+ const defaultProps = {
31
+ dismissible : true ,
32
+ } ;
33
+
17
34
class SLDSNotification extends React . Component {
18
35
constructor ( props ) {
19
36
super ( props ) ;
20
37
this . state = { isOpen : true } ;
21
38
}
22
39
40
+ componentDidMount ( ) {
41
+ if ( this . props . duration ) {
42
+ const that = this ;
43
+ setTimeout ( function ( ) {
44
+ that . setState ( { isOpen : false } ) ;
45
+ } , that . props . duration ) ;
46
+ }
47
+ }
48
+
23
49
renderIcon ( ) {
24
50
if ( this . props . icon ) {
25
51
let classes = "" ;
@@ -57,7 +83,7 @@ class SLDSNotification extends React.Component {
57
83
58
84
onDismiss ( ) {
59
85
if ( this . props . onDismiss ) this . props . onDismiss ( ) ;
60
- this . setState ( { isOpen :false } ) ;
86
+ this . setState ( { isOpen : false } ) ;
61
87
}
62
88
63
89
renderAlertContent ( ) {
@@ -94,34 +120,25 @@ class SLDSNotification extends React.Component {
94
120
95
121
render ( ) {
96
122
if ( this . state . isOpen ) {
97
- return (
98
- < div className = "slds-notify-container" >
99
- < div className = { this . getClassName ( ) } role = "alert" >
100
- < span className = "slds-assistive-text" > { this . props . theme } </ span >
101
- { this . renderClose ( ) }
102
- { this . renderAlertContent ( ) }
103
- { this . renderToastContent ( ) }
123
+ return (
124
+ < div className = "slds-notify-container" >
125
+ < div className = { this . getClassName ( ) } role = "alert" >
126
+ < span className = "slds-assistive-text" > { this . props . theme } </ span >
127
+ { this . renderClose ( ) }
128
+ { this . renderAlertContent ( ) }
129
+ { this . renderToastContent ( ) }
130
+ </ div >
104
131
</ div >
105
- </ div >
106
- ) ;
132
+ ) ;
107
133
} else {
108
134
return null ;
109
135
}
110
136
}
111
137
}
112
- SLDSNotification . propTypes = {
113
- content : React . PropTypes . node ,
114
- icon : React . PropTypes . string ,
115
- variant : React . PropTypes . oneOf ( [ "alert" , "toast" ] ) ,
116
- theme : React . PropTypes . oneOf ( [ "success" , "warning" , "error" , "offline" ] ) ,
117
- texture : React . PropTypes . bool ,
118
- dismissible : React . PropTypes . bool ,
119
- onDismiss : React . PropTypes . func ,
120
- } ;
121
138
122
- SLDSNotification . defaultProps = {
123
- dismissible : true
124
- } ;
139
+ SLDSNotification . displayName = displayName ;
140
+ SLDSNotification . propTypes = propTypes ;
141
+ SLDSNotification . defaultProps = defaultProps ;
125
142
126
143
module . exports = SLDSNotification ;
127
144
0 commit comments