Added create toast function

This commit is contained in:
Daniel Cojocea
2024-07-11 18:05:41 -04:00
parent e9cb0aa339
commit 92d4caa801
4 changed files with 55 additions and 4 deletions

View File

@@ -40,6 +40,8 @@ import { getMonitorsByUserId } from "../../Features/Monitors/monitorsSlice";
import ImageField from "../../Components/TextFields/Image";
import ProgressUpload from "../../Components/ProgressBars";
import Alert from "../../Components/Alert";
import { createToast } from "../../Utils/toastUtils";
import { ToastContainer } from "react-toastify";
const cols = [
{
@@ -463,7 +465,7 @@ const Demo = () => {
variant="info"
title="We've just released a new feature"
body="Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquid pariatur, ipsum dolor."
toast={true}
isToast={true}
/>
</Box>
<Box width="500px" mt="5px">
@@ -474,8 +476,22 @@ const Demo = () => {
hasIcon={false}
/>
</Box>
<Box width="500px" mt="5px">
<Button
level="primary"
label="Toast"
onClick={() =>
createToast({
variant: "info",
body: "Your password is incorrect.",
hasIcon: false,
})
}
/>
</Box>
</Stack>
<Divider sx={{ margin: `${theme.spacing(2)}` }} />
<ToastContainer />
</div>
);
};

View File

@@ -109,9 +109,9 @@ const theme = createTheme({
border: "#f04438",
},
warning: {
color: "#f79009",
bg: "#fffaef",
border: "#fecf60"
color: "#DC6803",
bg: "#fffcf5",
border: "#fec84b"
},
},
});

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
);
};

View File

@@ -124,6 +124,15 @@ button:focus-visible {
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) {
:root {
color: #213547;