DocSpace-client/packages/components/toast/index.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

import React from "react";
import { cssTransition } from "react-toastify";
import PropTypes from "prop-types";
import StyledToastContainer from "./styled-toast";
const Slide = cssTransition({
enter: "SlideIn",
exit: "SlideOut",
});
const Toast = (props) => {
const onToastClick = () => {
let documentElement = document.getElementsByClassName("Toastify__toast");
if (documentElement.length > 1)
for (var i = 0; i < documentElement.length; i++) {
documentElement &&
documentElement[i].style.setProperty("position", "static");
}
};
return (
<StyledToastContainer
2022-01-24 14:32:05 +00:00
theme={props.theme}
2019-12-17 11:08:11 +00:00
className={props.className}
draggable={true}
position="top-right"
hideProgressBar={true}
2019-12-17 11:08:11 +00:00
id={props.id}
newestOnTop={true}
pauseOnFocusLoss={false}
style={props.style}
transition={Slide}
onClick={onToastClick}
/>
);
};
Toast.propTypes = {
autoClosed: PropTypes.bool,
2021-03-11 16:03:17 +00:00
/** Accepts class */
className: PropTypes.string,
2021-03-11 16:03:17 +00:00
/** Accepts id */
id: PropTypes.string,
2021-03-11 16:03:17 +00:00
/** Accepts css style */
2019-12-17 11:08:11 +00:00
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
text: PropTypes.string,
2021-03-11 16:03:17 +00:00
/** Title inside a toast */
2019-12-17 11:08:11 +00:00
title: PropTypes.string,
2021-03-11 16:03:17 +00:00
/** Define color and icon of toast */
type: PropTypes.oneOf(["success", "error", "warning", "info"]).isRequired,
};
Toast.defaultProps = {
2019-12-17 11:08:11 +00:00
autoClosed: true,
text: "Demo text for example",
title: "Demo title",
type: "success",
};
export default Toast;