Skip to content

Commit

Permalink
Merge pull request #30 from AAISS/fix/toast
Browse files Browse the repository at this point in the history
refactor: toast colors and style
  • Loading branch information
KimiaMontazeri authored Nov 28, 2023
2 parents fa8627c + 9da223a commit 6356b11
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
76 changes: 43 additions & 33 deletions frontend/src/components/toast/Toast.jsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
import {useCallback} from "react";
import {Alert, Snackbar} from "@mui/material";
import { useCallback } from 'react';
import { Close } from '@mui/icons-material';
import { IconButton, Snackbar, SnackbarContent } from '@mui/material';
import Slide from '@mui/material/Slide';

export default function Toast({
duration = 6000,
vertical = "top", //'top', 'bottom'
horizontal = "right", //'left', 'center', 'right'
message = "fill me",
alertType = "success",//'error', 'warning', 'info', 'success',
open,
setOpen,
}) {
const CloseButton = ({ onClick }) => (
<IconButton onClick={onClick}>
<Close />
</IconButton>
);

const alertTypeColorMapping = {
error: 'var(--error-color)',
warning: 'var(--warn-color)',
info: 'var(--info-color)',
success: 'var(--success-color)',
};

const onClose = useCallback(() => {
setOpen(false)
}, [])
export default function Toast({
duration = 6000,
vertical = 'top', //'top', 'bottom'
horizontal = 'right', //'left', 'center', 'right'
message = 'fill me',
alertType = 'success', //'error', 'warning', 'info', 'success',
open,
setOpen,
}) {
const onClose = useCallback(() => {
setOpen(false);
}, []);

return (
<Snackbar
autoHideDuration={duration}
open={open}
onClose={onClose}
anchorOrigin={{vertical, horizontal}}
TransitionComponent={(props) => <Slide {...props} direction={"right"}/>}
>
<Alert
sx={{
width: "100%",
}}
onClose={onClose}
severity={alertType}>
{message}
</Alert>
</Snackbar>
)
}
return (
<Snackbar
autoHideDuration={duration}
open={open}
onClose={onClose}
anchorOrigin={{ vertical, horizontal }}
TransitionComponent={(props) => <Slide {...props} direction={'right'} />}
action={<CloseButton />}
>
<SnackbarContent
message={message}
action={<CloseButton onClick={() => setOpen(false)} />}
sx={{ bgcolor: alertTypeColorMapping[alertType], color: 'var(--light-text-color)' }}
/>
</Snackbar>
);
}
2 changes: 2 additions & 0 deletions frontend/src/css/Theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/*warn color*/
--warn-color: #ec6803;
--error-color: #ff3333;
--success-color: #197f3c;
--info-color: #19517f;

/*background*/
--background-color: #0a0f26;
Expand Down

0 comments on commit 6356b11

Please sign in to comment.