@@ -14,12 +14,38 @@ const classNames = require("classnames");
1414import SLDSButton from "../SLDSButton" ;
1515import { Icon } from "../SLDSIcons" ;
1616
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+
1734class SLDSNotification extends React . Component {
1835 constructor ( props ) {
1936 super ( props ) ;
2037 this . state = { isOpen : true } ;
2138 }
2239
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+
2349 renderIcon ( ) {
2450 if ( this . props . icon ) {
2551 let classes = "" ;
@@ -57,7 +83,7 @@ class SLDSNotification extends React.Component {
5783
5884 onDismiss ( ) {
5985 if ( this . props . onDismiss ) this . props . onDismiss ( ) ;
60- this . setState ( { isOpen :false } ) ;
86+ this . setState ( { isOpen : false } ) ;
6187 }
6288
6389 renderAlertContent ( ) {
@@ -94,34 +120,25 @@ class SLDSNotification extends React.Component {
94120
95121 render ( ) {
96122 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 >
104131 </ div >
105- </ div >
106- ) ;
132+ ) ;
107133 } else {
108134 return null ;
109135 }
110136 }
111137}
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- } ;
121138
122- SLDSNotification . defaultProps = {
123- dismissible : true
124- } ;
139+ SLDSNotification . displayName = displayName ;
140+ SLDSNotification . propTypes = propTypes ;
141+ SLDSNotification . defaultProps = defaultProps ;
125142
126143module . exports = SLDSNotification ;
127144
0 commit comments