@material-ui/core#SnackbarOrigin TypeScript Examples
The following examples show how to use
@material-ui/core#SnackbarOrigin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnackBar.tsx From postgres-nest-react-typescript-boilerplate with GNU General Public License v3.0 | 6 votes |
Toast: FC<{ position: SnackbarOrigin; duration: number }> = ({
position: { vertical, horizontal },
duration
}) => {
const snackBarState = useSelector((state: IStore) => state.ui.snackbar);
const dispatch = useDispatch();
const [isOpen, setIsOpen] = useState<boolean>(false);
const [msg, setMsg] = useState<string>(snackBarState.msg);
const [type, setType] = useState<AlertType>(snackBarState.type);
const onCloseHandler = () => {
dispatch(clearSnackBar());
};
useEffect(() => {
if (!snackBarState.msg) {
setIsOpen(false);
} else {
setIsOpen(true);
setType(snackBarState.type);
setMsg(snackBarState.msg);
}
}, [snackBarState]);
return (
<Snackbar
onClose={onCloseHandler}
open={isOpen}
autoHideDuration={duration}
anchorOrigin={{ vertical, horizontal }}
>
<MuiAlert elevation={6} variant="filled" severity={type}>
{msg}
</MuiAlert>
</Snackbar>
);
}
Example #2
Source File: snack.tsx From bitpay-browser-extension with MIT License | 5 votes |
anchorOrigin: SnackbarOrigin = { vertical: 'top', horizontal: 'center' }