-
Notifications
You must be signed in to change notification settings - Fork 340
/
Copy pathtoaster.tsx
52 lines (46 loc) · 1.17 KB
/
toaster.tsx
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
42
43
44
45
46
47
48
49
50
51
52
import * as React from 'react';
import { setup } from 'goober';
import CSS from 'csstype';
import { useToaster } from '../core/use-toaster';
import { ToastBar } from './toast-bar';
import { ToastPosition, DefaultToastOptions } from '../core/types';
setup(React.createElement);
interface ToasterProps {
position?: ToastPosition;
reverseOrder?: boolean;
containerStyle?: CSS.Properties;
toastOptions?: DefaultToastOptions;
}
export const Toaster: React.FC<ToasterProps> = ({
reverseOrder,
position = 'top-center',
containerStyle,
toastOptions,
}) => {
const { toasts, handlers } = useToaster(toastOptions);
return (
<div
style={{
position: 'fixed',
zIndex: 9999,
...containerStyle,
}}
onMouseEnter={handlers.startPause}
onMouseLeave={handlers.endPause}
>
{toasts.map((t) => {
return (
<ToastBar
key={t.id}
onHeight={(height) => handlers.updateHeight(t.id, height)}
toast={t}
offset={handlers.calculateOffset(t.id, {
reverseOrder,
})}
position={position}
/>
);
})}
</div>
);
};