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