2017-10-13 02:53:33 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { toast } from 'react-toastify';
|
|
|
|
import Icon from '../icon/component';
|
2021-11-11 04:31:00 +08:00
|
|
|
import Styled from './styles';
|
2017-10-13 02:53:33 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
icon: PropTypes.string,
|
2017-10-13 03:03:48 +08:00
|
|
|
message: PropTypes.node.isRequired,
|
2017-10-13 02:53:33 +08:00
|
|
|
type: PropTypes.oneOf(Object.values(toast.TYPE)).isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
icon: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultIcons = {
|
|
|
|
[toast.TYPE.INFO]: 'help',
|
|
|
|
[toast.TYPE.SUCCESS]: 'checkmark',
|
|
|
|
[toast.TYPE.WARNING]: 'warning',
|
|
|
|
[toast.TYPE.ERROR]: 'close',
|
|
|
|
[toast.TYPE.DEFAULT]: 'about',
|
|
|
|
};
|
|
|
|
|
2018-06-13 01:21:31 +08:00
|
|
|
const Toast = ({
|
|
|
|
icon,
|
|
|
|
type,
|
|
|
|
message,
|
|
|
|
content,
|
|
|
|
small,
|
2019-04-04 23:29:46 +08:00
|
|
|
}) => (
|
2022-02-09 23:52:42 +08:00
|
|
|
<Styled.ToastContainer small={small} data-test="toastContainer">
|
2021-11-11 04:31:00 +08:00
|
|
|
<Styled.Toast type={type}>
|
|
|
|
<Styled.ToastIcon small={small}>
|
2019-04-04 23:29:46 +08:00
|
|
|
<Icon iconName={icon || defaultIcons[type]} />
|
2021-11-11 04:31:00 +08:00
|
|
|
</Styled.ToastIcon>
|
|
|
|
<Styled.ToastMessage data-test="toastSmallMsg">
|
2019-04-04 23:29:46 +08:00
|
|
|
<span>{message}</span>
|
2021-11-11 04:31:00 +08:00
|
|
|
</Styled.ToastMessage>
|
|
|
|
</Styled.Toast>
|
2019-05-01 05:41:15 +08:00
|
|
|
{content
|
|
|
|
? (
|
2021-11-11 04:31:00 +08:00
|
|
|
<Styled.BackgroundColorInherit>
|
|
|
|
<Styled.Separator />
|
|
|
|
<Styled.BackgroundColorInherit>
|
2019-05-01 05:41:15 +08:00
|
|
|
{content}
|
2021-11-11 04:31:00 +08:00
|
|
|
</Styled.BackgroundColorInherit>
|
|
|
|
</Styled.BackgroundColorInherit>
|
|
|
|
) : null}
|
|
|
|
</Styled.ToastContainer>
|
2019-04-04 23:29:46 +08:00
|
|
|
);
|
2017-10-13 02:53:33 +08:00
|
|
|
|
|
|
|
export default Toast;
|
|
|
|
|
|
|
|
Toast.propTypes = propTypes;
|
|
|
|
Toast.defaultProps = defaultProps;
|