Refactor SnackbarIndicator

This commit is contained in:
Leonardo Murça 2022-07-01 17:38:24 -03:00
parent 3387d94ea4
commit c735142276
2 changed files with 16 additions and 2 deletions

View file

@ -1,8 +1,11 @@
import { useState, useEffect, forwardRef } from 'react';
import { Snackbar, Alert } from '@mui/material';
import styles from './styles';
function SnackbarIndicator({ isOpen, severity, message }) {
const [open, setOpen] = useState(false);
const { snackbarContainer, customAlert } = styles;
useEffect(() => {
setOpen(isOpen);
@ -16,12 +19,12 @@ function SnackbarIndicator({ isOpen, severity, message }) {
return (
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
anchorOrigin={snackbarContainer}
open={open}
autoHideDuration={5000}
onClose={onClose}
>
<CustomAlert onClose={onClose} severity={severity} sx={{ width: '100%' }}>
<CustomAlert onClose={onClose} severity={severity} sx={customAlert}>
{message}
</CustomAlert>
</Snackbar>

View file

@ -0,0 +1,11 @@
const snackbarContainer = {
vertical: 'bottom',
horizontal: 'center',
};
const customAlert = {
width: '100%',
};
const styles = { snackbarContainer, customAlert };
export default styles;