-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.jsx
41 lines (33 loc) · 1.18 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useState, useEffect } from 'react';
import WarningCircleIcon from '@/icons/Common/warning_circle';
const Toast = ({ message, type, timeout, dataTestId, size, clearData, bgColor, position }) => {
const [visible, setVisible] = useState(true);
const colors = {
success: bgColor || 'bg-green-500',
error: bgColor || 'bg-red-500',
};
const textColor = type === 'success' ? 'text-white' : 'text-white';
const containerStyles = `flex ${
size === 'sm' ? 'items-center py-1 px-2' : 'p-4'
} w-auto text-sm ${colors[type]} ${textColor} rounded-md shadow-lg`;
useEffect(() => {
const timer = setTimeout(() => {
setVisible(false);
clearData && clearData();
}, timeout || 5000);
return () => clearTimeout(timer);
}, [timeout]);
return visible ? (
<div
className={`absolute ${
!position ? 'top-5' : 'bottom-5'
} left-0 right-0 z-50 flex justify-center items-center mx-4`}
data-testid={dataTestId}>
<div className={containerStyles}>
{type === 'error' && <WarningCircleIcon fillColor='#FFF' />}
<p className='ml-2 capitalize'>{message}</p>
</div>
</div>
) : null;
};
export default Toast;