-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAlert.jsx
60 lines (55 loc) · 1.66 KB
/
Alert.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
52
53
54
55
56
57
58
59
60
import { useState } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Button from '../Button';
import Icon from '../Icon';
import styles from './Alert.module.css';
const Alert = ({
icon = null,
skin = 'neutral',
children,
onClose = undefined,
className,
...rest
}) => {
const [show, setShow] = useState(true);
const contentClass = classNames(styles.content, className);
const alertClass = classNames(styles['alert-icon'], styles[`icon-${skin}`]);
const closeButtonClass = classNames(
styles['close-button'],
styles[`icon-${skin}`],
);
const wrapperClass = classNames(styles.wrapper, styles[`wrapper-${skin}`]);
const handleClose = () => {
setShow(false);
onClose();
};
return (
show && (
<div className={wrapperClass} {...rest} role="alert">
<div className={contentClass}>
{icon && <Icon name={icon} className={alertClass} />}
{children && <span>{children}</span>}
{onClose && (
<Button.Icon
onClick={handleClose}
icon="close"
className={closeButtonClass}
/>
)}
</div>
</div>
)
);
};
Alert.propTypes = {
/** At least one children is required for Alert component properly works */
children: PropTypes.node.isRequired,
/** Icon name. The full catalogue can be found
* [here](/?path=/docs/foundation-icons--page) */
icon: PropTypes.string,
/** You must pass a callback that is called when close button is clicked */
onClose: PropTypes.func,
skin: PropTypes.oneOf(['primary', 'success', 'error', 'neutral', 'warning']),
};
export default Alert;