@activecollab/components
Version:
ActiveCollab Components
37 lines • 1.65 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["text", "type", "onClose", "dismissible", "dropShadow", "timeout"];
import React, { forwardRef, useEffect, useCallback } from "react";
import { StyledToastMessage, StyledToastMessageText, StyledCloseSmallIcon } from "./Styles";
export const ToastMessage = /*#__PURE__*/forwardRef((_ref, ref) => {
let text = _ref.text,
type = _ref.type,
onClose = _ref.onClose,
_ref$dismissible = _ref.dismissible,
dismissible = _ref$dismissible === void 0 ? false : _ref$dismissible,
_ref$dropShadow = _ref.dropShadow,
dropShadow = _ref$dropShadow === void 0 ? false : _ref$dropShadow,
_ref$timeout = _ref.timeout,
timeout = _ref$timeout === void 0 ? 0 : _ref$timeout,
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
const handleOnClose = useCallback(() => {
if (typeof onClose === "function") {
onClose();
}
}, [onClose]);
useEffect(() => {
if (timeout > 0) {
const timer = setTimeout(handleOnClose, timeout);
return () => clearTimeout(timer);
}
}, [dismissible, timeout, handleOnClose]);
return /*#__PURE__*/React.createElement(StyledToastMessage, _extends({
ref: ref,
$type: type,
$dropShadow: dropShadow
}, rest), /*#__PURE__*/React.createElement(StyledToastMessageText, null, text), dismissible ? /*#__PURE__*/React.createElement(StyledCloseSmallIcon, {
onClick: handleOnClose
}) : null);
});
ToastMessage.displayName = "ToastMessage";
//# sourceMappingURL=ToastMessage.js.map