-
Notifications
You must be signed in to change notification settings - Fork 76
/
index.tsx
49 lines (41 loc) 路 1.14 KB
/
index.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
/* eslint-disable react/jsx-handler-names */
import React, { useContext } from 'react';
import useStyles, { StyleSheet } from '@airbnb/lunar/lib/hooks/useStyles';
import Toast from '@airbnb/lunar/lib/components/Toast';
import { Z_INDEX_TOAST } from '@airbnb/lunar/lib/constants';
import PopToast from './PopToast';
import AppContext from '../AppContext';
export { PopToast };
export const styleSheet: StyleSheet = ({ unit }) => ({
toasts: {
position: 'fixed',
bottom: unit * 1.5,
left: '50%',
transform: 'translate(-50%, 0)',
width: 500,
// Higher than modals
zIndex: Z_INDEX_TOAST,
},
});
export default function Toasts() {
const context = useContext(AppContext);
const [styles, cx] = useStyles(styleSheet);
if (!context || context.toasts.length === 0) {
return null;
}
const toasts = [...context.toasts];
toasts.reverse();
return (
<div className={cx(styles.toasts)}>
{toasts.map(toast => (
<Toast
{...toast.props}
key={toast.id}
id={toast.id}
message={toast.message}
onRemove={context.removeToast}
/>
))}
</div>
);
}