import { forwardRef, FC, SyntheticEvent } from 'react'; import { CustomSnackBarType } from './Types'; import MuiAlert from '@material-ui/lab/Alert'; import { Snackbar, makeStyles, Theme, createStyles } from '@material-ui/core'; import Slide from '@material-ui/core/Slide'; import { TransitionProps } from '@material-ui/core/transitions/transition'; // if we need to use slide component // snackbar content must use forwardRef to wrapper it const Alert = forwardRef((props: { [x: string]: any }, ref) => { return ; }); function SlideTransition(props: TransitionProps) { return ; } const useStyles = makeStyles((theme: Theme) => createStyles({ root: { maxWidth: '50vh', wordBreak: 'break-all' }, topRight: { [theme.breakpoints.up('md')]: { top: '72px', right: theme.spacing(4), }, top: '72px', right: theme.spacing(4), }, }) ); const CustomSnackBar: FC = props => { const { vertical, horizontal, open, autoHideDuration = 2500, type, message, onClose, } = props; const classes = useStyles(); const handleClose = (e: SyntheticEvent, reason: string) => { // only click x to close or auto hide. if (reason === 'clickaway') { return; } onClose && onClose(); }; return (
{message}
); }; export default CustomSnackBar;