mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
53354224fc
Upgrades biome to 1.6.1, and updates husky pre-commit hook. Most changes here are making type imports explicit.
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { Portal } from '@mui/material';
|
|
import { useContext, useEffect, useMemo } from 'react';
|
|
import {
|
|
fadeInBottomEnter,
|
|
fadeInBottomLeave,
|
|
fadeInBottomStartWithoutFixed,
|
|
} from 'themes/themeStyles';
|
|
import UIContext from 'contexts/UIContext';
|
|
import AnimateOnMount from '../AnimateOnMount/AnimateOnMount';
|
|
import Toast from './Toast/Toast';
|
|
import type { IToast } from 'interfaces/toast';
|
|
|
|
const ToastRenderer = () => {
|
|
const { toastData, setToast } = useContext(UIContext);
|
|
|
|
const hide = () => {
|
|
setToast((prev: IToast) => ({ ...prev, show: false }));
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!toastData.autoHideDuration) return;
|
|
const timeout = setTimeout(() => {
|
|
hide();
|
|
}, toastData.autoHideDuration);
|
|
|
|
return () => {
|
|
clearTimeout(timeout);
|
|
};
|
|
/* eslint-disable-next-line */
|
|
}, [toastData?.show]);
|
|
|
|
const animations = useMemo(
|
|
() => ({
|
|
start: {
|
|
...fadeInBottomStartWithoutFixed,
|
|
right: 0,
|
|
left: 0,
|
|
margin: '0 auto',
|
|
maxWidth: '450px',
|
|
},
|
|
enter: fadeInBottomEnter,
|
|
leave: fadeInBottomLeave,
|
|
}),
|
|
[],
|
|
);
|
|
|
|
return (
|
|
<Portal>
|
|
<AnimateOnMount
|
|
mounted={Boolean(toastData?.show)}
|
|
start={animations.start}
|
|
enter={animations.enter}
|
|
leave={animations.leave}
|
|
>
|
|
<Toast {...toastData} />
|
|
</AnimateOnMount>
|
|
</Portal>
|
|
);
|
|
};
|
|
|
|
export default ToastRenderer;
|