-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathMessageBar.jsx
51 lines (50 loc) · 1.75 KB
/
MessageBar.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
42
43
44
45
46
47
48
49
50
51
import CloseIcon from '../../styles/icons/cross.svg';
import PropTypes from 'prop-types';
import Content from './Notification.mdx';
import { version, localStorageIsEnabled } from './NotificationBar';
import { useTransition, animated, config } from '@react-spring/web';
import { useEffect, useState } from 'react';
MessageBar.propTypes = {
onClose: PropTypes.func,
};
export default function MessageBar(props) {
const [list, setList] = useState([]);
const listTransitions = useTransition(list, {
config: config.gentle,
from: { opacity: 0, transform: 'translate3d(-50%, 0px, 0px)' },
enter: { opacity: 1, transform: 'translate3d(0px, 0px, 0px)' },
keys: list.map((item, index) => index),
});
useEffect(() => {
setList(['']);
}, []);
const close = () => {
localStorage.setItem('notification-dismissed', version);
props.onClose();
};
return (
<>
{listTransitions((styles) => (
<animated.div
className="flex items-center rounded-sm z-50 fixed left-[1px] right-[1px] bottom-[1px] bg-white border-2 border-solid border-gray-700 max-w-full pl-20 py-20 shadow-2xl md:left-20 md:right-auto md:bottom-20 md:max-w-[300px] dark:bg-gray-500 print:hidden"
style={styles}
>
<Content />
{localStorageIsEnabled ? (
<div
role="button"
className="px-20 self-stretch inline-flex items-center cursor-pointer"
onClick={close}
>
<CloseIcon
aria-label="Dismiss"
className="fill-current text-gray-300 dark:text-white transform duration-200 hover:text-gray-700"
width={25}
/>
</div>
) : null}
</animated.div>
))}
</>
);
}