bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/common/toast/component.jsx

52 lines
1.3 KiB
React
Raw Normal View History

2017-10-13 02:53:33 +08:00
import React from 'react';
import PropTypes from 'prop-types';
import { toast } from 'react-toastify';
2022-02-15 22:51:51 +08:00
import Icon from '/imports/ui/components/common/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 defaultIcons = {
[toast.TYPE.INFO]: 'help',
[toast.TYPE.SUCCESS]: 'checkmark',
[toast.TYPE.WARNING]: 'warning',
[toast.TYPE.ERROR]: 'close',
[toast.TYPE.DEFAULT]: 'about',
};
const Toast = ({
2024-06-11 21:05:08 +08:00
icon = null,
type,
message,
content,
small,
2019-04-04 23:29:46 +08:00
}) => (
<Styled.ToastContainer small={small} data-test="toastContainer">
2021-11-11 04:31:00 +08:00
<Styled.Toast type={type}>
2022-02-26 04:29:26 +08:00
<Styled.ToastIcon className="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>
{content
? (
2021-11-11 04:31:00 +08:00
<Styled.BackgroundColorInherit>
<Styled.Separator />
<Styled.BackgroundColorInherit>
{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;