UNPKG

@bootstrap-styled/ra-ui

Version:
156 lines (124 loc) 5.81 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _reactRedux = require("react-redux"); var _Snackbar = _interopRequireDefault(require("@material-ui/core/Snackbar")); var _Button = _interopRequireDefault(require("@material-ui/core/Button")); var _compose = _interopRequireDefault(require("recompose/compose")); var _raCore = require("ra-core"); var Notification = function (_React$Component) { (0, _inherits2.default)(Notification, _React$Component); function Notification() { var _getPrototypeOf2; var _this; (0, _classCallCheck2.default)(this, Notification); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(Notification)).call.apply(_getPrototypeOf2, [this].concat(args))); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", { open: false }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "componentWillMount", function () { _this.setOpenState(_this.props); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "componentWillReceiveProps", function (nextProps) { _this.setOpenState(nextProps); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setOpenState", function (_ref) { var notification = _ref.notification; _this.setState({ open: !!notification }); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleRequestClose", function () { _this.setState({ open: false }); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleExited", function () { var _this$props = _this.props, notification = _this$props.notification, hideNotification = _this$props.hideNotification, complete = _this$props.complete; if (notification && notification.undoable) { complete(); } hideNotification(); }); return _this; } (0, _createClass2.default)(Notification, [{ key: "render", value: function render() { var _this$props2 = this.props, undo = _this$props2.undo, complete = _this$props2.complete, className = _this$props2.className, type = _this$props2.type, translate = _this$props2.translate, notification = _this$props2.notification, autoHideDuration = _this$props2.autoHideDuration, hideNotification = _this$props2.hideNotification, rest = (0, _objectWithoutProperties2.default)(_this$props2, ["undo", "complete", "className", "type", "translate", "notification", "autoHideDuration", "hideNotification"]); return _react.default.createElement(_Snackbar.default, (0, _extends2.default)({ open: this.state.open, message: notification && notification.message && translate(notification.message, notification.messageArgs), autoHideDuration: notification && notification.autoHideDuration || autoHideDuration, onExited: this.handleExited, onClose: this.handleRequestClose, action: notification && notification.undoable ? _react.default.createElement(_Button.default, { color: "primary", size: "small", onClick: undo }, translate('ra.action.undo')) : null }, rest)); } }]); return Notification; }(_react.default.Component); Notification.propTypes = { complete: _propTypes.default.func, className: _propTypes.default.string, notification: _propTypes.default.shape({ message: _propTypes.default.string, type: _propTypes.default.string, autoHideDuration: _propTypes.default.number, messageArgs: _propTypes.default.object }), type: _propTypes.default.string, hideNotification: _propTypes.default.func.isRequired, autoHideDuration: _propTypes.default.number, translate: _propTypes.default.func.isRequired, undo: _propTypes.default.func }; Notification.defaultProps = { type: 'info', autoHideDuration: 4000 }; var mapStateToProps = function mapStateToProps(state) { return { notification: (0, _raCore.getNotification)(state) }; }; var _default = (0, _compose.default)(_raCore.translate, (0, _reactRedux.connect)(mapStateToProps, { complete: _raCore.complete, hideNotification: _raCore.hideNotification, undo: _raCore.undo }))(Notification); exports.default = _default; module.exports = exports.default;