Refactor SnackbarIndicator
This commit is contained in:
parent
3387d94ea4
commit
c735142276
2 changed files with 16 additions and 2 deletions
|
@ -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>
|
11
src/components/SnackbarIndicator/styles.js
Normal file
11
src/components/SnackbarIndicator/styles.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const snackbarContainer = {
|
||||
vertical: 'bottom',
|
||||
horizontal: 'center',
|
||||
};
|
||||
|
||||
const customAlert = {
|
||||
width: '100%',
|
||||
};
|
||||
|
||||
const styles = { snackbarContainer, customAlert };
|
||||
export default styles;
|
Loading…
Reference in a new issue