import React, { Fragment, PureComponent } from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import CloseIcon from '@material-ui/icons/Close'; import { Typography, Button, Grid, Snackbar, Slide, Fade, IconButton } from '@material-ui/core'; const styles = theme => ({ row: { display: 'flex', justifyContent: 'flex-start', }, close: { width: theme.spacing(4) }, divider: { display: 'block', margin: `${theme.spacing(3)}px 0`, }, button: { margin: theme.spacing(1) } }); function TransitionLeft(props) { return ; } function TransitionUp(props) { return ; } function TransitionRight(props) { return ; } function TransitionDown(props) { return ; } class TransitionNotif extends PureComponent { state = { open: false, open2: false, open3: false, transition: null, messageInfo: {}, }; queue = []; handleClickQueue = message => () => { this.queue.push({ message, key: new Date().getTime(), }); if (this.state.open3) { // immediately begin dismissing current message // to start showing new one this.setState({ open3: false }); } else { this.processQueue(); } }; processQueue = () => { if (this.queue.length > 0) { this.setState({ messageInfo: this.queue.shift(), open3: true, }); } }; handleCloseQueue = (event, reason) => { if (reason === 'clickaway') { return; } this.setState({ open3: false }); }; handleExited = () => { this.processQueue(); }; handleClick = transition => () => { this.setState({ open: true, transition }); }; handleClose = () => { this.setState({ open: false }); }; handleClick2 = () => { this.setState({ open2: true }); }; handleClose2 = () => { this.setState({ open2: false }); }; render() { const { classes } = this.props; const { message, key } = this.state.messageInfo; return ( Transition
I love snacks} />
Change Transition
I love snacks} />
Consecutive Snackbars
{message}} action={[ , ]} />
); } } TransitionNotif.propTypes = { classes: PropTypes.object.isRequired, }; export default withStyles(styles)(TransitionNotif);