aboutsummaryrefslogtreecommitdiff
path: root/front/odiparpack/app/containers/UiElements/demos/Notification/SimpleNotif.js
blob: 0b068b509f79296d9784c76c9cc255acc2e9ca35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import CloseIcon from '@material-ui/icons/Close';
import { Typography, Button, Snackbar, IconButton, Grid } from '@material-ui/core';

const styles = theme => ({
  close: {
    width: theme.spacing(4)
  },
  divider: {
    margin: `${theme.spacing(3)}px 0`,
  },
  button: {
    margin: theme.spacing(1)
  }
});

class SimpleNotif extends React.Component {
  state = {
    open: false,
    open2: false,
    vertical: 'bottom',
    horizontal: 'left',
  };

  handleClick = () => {
    this.setState({ open: true });
  };

  handleClose = (event, reason) => {
    if (reason === 'clickaway') {
      return;
    }

    this.setState({ open: false });
  };

  handleClick2 = state => () => {
    this.setState({ open2: true, ...state });
  };

  handleClose2 = () => {
    this.setState({ open2: false });
  };

  render() {
    const { classes } = this.props;
    const { vertical, horizontal, open2 } = this.state;
    return (
      <Grid
        container
        alignItems="flex-start"
        justify="flex-start"
        direction="row"
        spacing={2}
      >
        <Grid item md={6}>
          <Typography variant="button" className={classes.divider}>Simple Notification</Typography>
          <div>
            <Button variant="contained" onClick={this.handleClick}>Open simple snackbar</Button>
            <Snackbar
              anchorOrigin={{
                vertical: 'bottom',
                horizontal: 'left',
              }}
              open={this.state.open}
              autoHideDuration={6000}
              onClose={this.handleClose}
              ContentProps={{
                'aria-describedby': 'message-id',
              }}
              message={<span id="message-id">Note archived</span>}
              action={[
                <Button key="undo" color="secondary" size="small" onClick={this.handleClose}>
                  UNDO
                </Button>,
                <IconButton
                  key="close"
                  aria-label="Close"
                  color="inherit"
                  className={classes.close}
                  onClick={this.handleClose}
                >
                  <CloseIcon />
                </IconButton>,
              ]}
            />
          </div>
        </Grid>
        <Grid item md={6}>
          <Typography variant="button" className={classes.divider}>Positioning</Typography>
          <div>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'top', horizontal: 'center' })}>
              Top-Center
            </Button>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'top', horizontal: 'right' })}>
              Top-Right
            </Button>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'bottom', horizontal: 'right' })}>
              Bottom-Right
            </Button>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'bottom', horizontal: 'center' })}>
              Bottom-Center
            </Button>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'bottom', horizontal: 'left' })}>
              Bottom-Left
            </Button>
            <Button className={classes.button} variant="contained" onClick={this.handleClick2({ vertical: 'top', horizontal: 'left' })}>
              Top-Left
            </Button>
            <Snackbar
              anchorOrigin={{ vertical, horizontal }}
              open={open2}
              onClose={this.handleClose2}
              ContentProps={{
                'aria-describedby': 'message-id',
              }}
              message={<span id="message-id">I love snacks</span>}
            />
          </div>
        </Grid>
      </Grid>
    );
  }
}

SimpleNotif.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SimpleNotif);