UNPKG

pouncejs

Version:

A collection of UI components from Panther labs

41 lines (34 loc) 1.33 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; import React from 'react'; import ControlledAlert from '../utils/ControlledAlert'; import Collapse from '../Collapse'; /** An Alert component is simply a container for text that should capture the user's attention */ var Alert = function Alert(_ref) { var onClose = _ref.onClose, _ref$disableAnimation = _ref.disableAnimation, disableAnimation = _ref$disableAnimation === void 0 ? false : _ref$disableAnimation, rest = _objectWithoutPropertiesLoose(_ref, ["onClose", "disableAnimation"]); var _React$useState = React.useState(true), open = _React$useState[0], setOpen = _React$useState[1]; var handleClose = React.useCallback(function () { setOpen(false); if (onClose) { onClose(); } }, [setOpen, onClose]); if (disableAnimation) { return /*#__PURE__*/React.createElement(ControlledAlert, _extends({}, rest, { open: open, onClose: handleClose })); } return /*#__PURE__*/React.createElement(Collapse, { open: open }, /*#__PURE__*/React.createElement(ControlledAlert, _extends({}, rest, { open: true, onClose: handleClose }))); }; export default /*#__PURE__*/React.memo(Alert);