Advertisement
SanderCokart

AppSnackbar.js

Mar 3rd, 2020
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Snackbar} from '@material-ui/core';
  2. import Button from '@material-ui/core/Button';
  3. import SnackbarContent from '@material-ui/core/SnackbarContent';
  4. import React, {Fragment, useContext} from 'react';
  5. import {TodoContext} from '../contexts/TodoContext';
  6.  
  7. function checkLevel(level) {
  8.     switch (level) {
  9.         case 'success':
  10.             return 'green';
  11.         case 'error':
  12.             return 'red';
  13.         default:
  14.             return 'white';
  15.     }
  16. }
  17.  
  18. function AppSnackbar() {
  19.     const context = useContext(TodoContext);
  20.     return (
  21.         <Snackbar autoHideDuration={6000} open={context.message.text !== undefined}>
  22.             {context.message.text && (
  23.                 <SnackbarContent style={{backgroundColor: checkLevel(context.message.level), whiteSpace: 'pre'}}
  24.                                  message={context.message.text}
  25.                                  action={[
  26.                                      <Button
  27.                                          onClick={() => context.setMessage({})}
  28.                                          key='dismiss'
  29.                                          color='inherit'
  30.                                      >
  31.                                          dismiss
  32.                                      </Button>,
  33.                                  ]}/>
  34.             )}
  35.         </Snackbar>
  36.     );
  37. }
  38.  
  39. export default AppSnackbar;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement