import { Box } from "@mui/material"; import MuiSnackbarContent from "@mui/material/SnackbarContent"; import { CustomContentProps } from "notistack"; import * as React from "react"; import { forwardRef, useEffect, useState } from "react"; import CircularProgress from "../CircularProgress.tsx"; declare module "notistack" { interface VariantOverrides { loading: { getProgress?: () => number; }; } } interface LoadingSnackbarProps extends CustomContentProps { getProgress?: () => number; } const LoadingSnackbar = forwardRef((props, ref) => { const [progress, setProgress] = useState(0); const { // You have access to notistack props and options 👇🏼 message, action, id, getProgress, // as well as your own custom props 👇🏼 ...other } = props; useEffect(() => { var intervalId: NodeJS.Timeout; if (getProgress) { intervalId = setInterval(() => { setProgress(getProgress()); }, 1000); } return () => { clearInterval(intervalId); }; }, [getProgress]); let componentOrFunctionAction: React.ReactNode = undefined; if (typeof action === "function") { componentOrFunctionAction = action(id); } else { componentOrFunctionAction = action; } return ( {message} {componentOrFunctionAction && ( {componentOrFunctionAction} )} } /> ); }); export default LoadingSnackbar;