import React from 'react'; import { ReactElement, useContext, useEffect } from 'react'; import Icon from '../icon/Icon'; import styles from './Snackbar.module.scss'; import { ThemeContext } from '../theme-context/ThemeContext'; export type ISnackBarOptions = { message: string; isShow: boolean; variant: 'error' | 'success' | 'info'; timmer?: number; iconName?: string; iconColor?: string; renderComponent?: ReactElement; }; export type ISnackBar = { snackBarOptions: ISnackBarOptions; setSnackBarOptions: React.Dispatch>; }; const Snackbar = (props: ISnackBar) => { const { theme } = useContext(ThemeContext); const { iconName, message, isShow, variant, timmer, iconColor, renderComponent, } = props.snackBarOptions; let timeOutId: number | NodeJS.Timeout; useEffect(() => { timeOutId = setTimeout( () => { props.setSnackBarOptions({ ...props.snackBarOptions, isShow: false, }); }, timmer ? timmer : 5000 ); return () => { clearTimeout(timeOutId as NodeJS.Timeout); }; }, [isShow]); return ( <> {isShow && (

{message}

{renderComponent && renderComponent}
)} ); }; export default Snackbar;