Added create toast function

This commit is contained in:
Daniel Cojocea committed 2024-07-11 18:05:41 -04:00
1 parent e9cb0aa339
commit 92d4caa801
4 files changed
+55 -4

No files matched your search

+17 -1
View File
@@ -40,6 +40,8 @@ import { getMonitorsByUserId } from "../../Features/Monitors/monitorsSlice";
import ImageField from "../../Components/TextFields/Image"; import ImageField from "../../Components/TextFields/Image";
import ProgressUpload from "../../Components/ProgressBars"; import ProgressUpload from "../../Components/ProgressBars";
import Alert from "../../Components/Alert"; import Alert from "../../Components/Alert";
import { createToast } from "../../Utils/toastUtils";
import { ToastContainer } from "react-toastify";
const cols = [ const cols = [
{ {
@@ -463,7 +465,7 @@ const Demo = () => {
variant="info" variant="info"
title="We've just released a new feature" title="We've just released a new feature"
body="Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquid pariatur, ipsum dolor." body="Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquid pariatur, ipsum dolor."
toast={true} isToast={true}
/> />
</Box> </Box>
<Box width="500px" mt="5px"> <Box width="500px" mt="5px">
@@ -474,8 +476,22 @@ const Demo = () => {
hasIcon={false} hasIcon={false}
/> />
</Box> </Box>
<Box width="500px" mt="5px">
<Button
level="primary"
label="Toast"
onClick={() =>
createToast({
variant: "info",
body: "Your password is incorrect.",
hasIcon: false,
})
}
/>
</Box>
</Stack> </Stack>
<Divider sx={{ margin: `${theme.spacing(2)}` }} /> <Divider sx={{ margin: `${theme.spacing(2)}` }} />
<ToastContainer />
</div> </div>
); );
}; };
+3 -3
View File
@@ -109,9 +109,9 @@ const theme = createTheme({
border: "#f04438", border: "#f04438",
}, },
warning: { warning: {
color: "#f79009", color: "#DC6803",
bg: "#fffaef", bg: "#fffcf5",
border: "#fecf60" border: "#fec84b"
}, },
}, },
}); });
+26
View File
@@ -0,0 +1,26 @@
import { toast } from "react-toastify";
import Alert from "../Components/Alert";
export const createToast = ({ variant, title, body, hasIcon, config = {} }) => {
const toastConfig = {
position: "top-right",
autoClose: 3000,
hideProgressBar: true,
closeButton: false,
...config,
};
toast(
({ closeToast }) => (
<Alert
variant={variant}
title={title}
body={body}
isToast={true}
hasIcon={hasIcon}
onClick={closeToast}
/>
),
toastConfig
);
};
+9
View File
@@ -124,6 +124,15 @@ button:focus-visible {
outline: 4px auto -webkit-focus-ring-color; outline: 4px auto -webkit-focus-ring-color;
} }
.Toastify [class^="Toastify__toast"] {
padding: 0;
margin: 0;
}
.Toastify__toast{
min-height: 0;
border-radius: 4px;
}
@media (prefers-color-scheme: light) { @media (prefers-color-scheme: light) {
:root { :root {
color: #213547; color: #213547;