| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  | import React, {Fragment} from 'react'; | 
					
						
							| 
									
										
										
										
											2018-02-26 00:11:31 +00:00
										 |  |  | import PropTypes from 'prop-types'; | 
					
						
							|  |  |  | import { withStyles } from 'material-ui/styles'; | 
					
						
							|  |  |  | import Snackbar from 'material-ui/Snackbar'; | 
					
						
							|  |  |  | import IconButton from 'material-ui/IconButton'; | 
					
						
							|  |  |  | import CloseIcon from 'material-ui-icons/Close'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const styles = theme => ({ | 
					
						
							|  |  |  |   close: { | 
					
						
							|  |  |  |     width: theme.spacing.unit * 4, | 
					
						
							|  |  |  |     height: theme.spacing.unit * 4, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SnackbarNotification extends React.Component { | 
					
						
							| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   constructor(props) { | 
					
						
							|  |  |  |     super(props); | 
					
						
							|  |  |  |     this.raiseNotification=this.raiseNotification.bind(this); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static childContextTypes = { | 
					
						
							|  |  |  |     raiseNotification: PropTypes.func.isRequired | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getChildContext = () => { | 
					
						
							|  |  |  |     return {raiseNotification : this.raiseNotification}; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-26 00:11:31 +00:00
										 |  |  |   state = { | 
					
						
							|  |  |  |     open: false, | 
					
						
							|  |  |  |     message: null | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   raiseNotification = (message) => { | 
					
						
							|  |  |  |     this.setState({ open: true, message:message }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   handleClose = (event, reason) => { | 
					
						
							|  |  |  |     if (reason === 'clickaway') { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this.setState({ open: false }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     const { classes } = this.props; | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  |       <Fragment> | 
					
						
							| 
									
										
										
										
											2018-02-26 00:11:31 +00:00
										 |  |  |         <Snackbar | 
					
						
							|  |  |  |           anchorOrigin={{ | 
					
						
							|  |  |  |             vertical: 'bottom', | 
					
						
							|  |  |  |             horizontal: 'left', | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |           open={this.state.open} | 
					
						
							|  |  |  |           autoHideDuration={6000} | 
					
						
							|  |  |  |           onClose={this.handleClose} | 
					
						
							|  |  |  |           SnackbarContentProps={{ | 
					
						
							|  |  |  |             'aria-describedby': 'message-id', | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |           message={<span id="message-id">{this.state.message}</span>} | 
					
						
							|  |  |  |           action={ | 
					
						
							|  |  |  |             <IconButton | 
					
						
							|  |  |  |               aria-label="Close" | 
					
						
							|  |  |  |               color="inherit" | 
					
						
							|  |  |  |               className={classes.close} | 
					
						
							|  |  |  |               onClick={this.handleClose} | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               <CloseIcon /> | 
					
						
							|  |  |  |             </IconButton> | 
					
						
							| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           {this.props.children} | 
					
						
							|  |  |  |         </Fragment> | 
					
						
							| 
									
										
										
										
											2018-02-26 00:11:31 +00:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SnackbarNotification.propTypes = { | 
					
						
							| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  |   classes: PropTypes.object.isRequired | 
					
						
							| 
									
										
										
										
											2018-02-26 00:11:31 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default withStyles(styles)(SnackbarNotification); | 
					
						
							| 
									
										
										
										
											2018-03-03 22:41:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function withNotifier(WrappedComponent) { | 
					
						
							|  |  |  |   return class extends React.Component { | 
					
						
							|  |  |  |     static contextTypes = { | 
					
						
							|  |  |  |       raiseNotification: PropTypes.func.isRequired | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     render() { | 
					
						
							|  |  |  |       return <WrappedComponent raiseNotification={this.context.raiseNotification} {...this.props} />; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |