@trendmicro/react-notifications
Version:
Trend Micro Components: React Notifications
377 lines (288 loc) • 16.9 kB
JavaScript
/*! react-notifications v1.0.1 | (c) 2018 Trend Micro Inc. | MIT | https://github.com/trendmicro-frontend/react-notifications */
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _class, _temp2;
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(7);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _reactAnchor = __webpack_require__(6);
var _reactAnchor2 = _interopRequireDefault(_reactAnchor);
var _index = __webpack_require__(1);
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Notification = (_temp2 = _class = function (_Component) {
_inherits(Notification, _Component);
function Notification() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Notification);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Notification.__proto__ || Object.getPrototypeOf(Notification)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
show: _this.props.defaultShow === undefined ? true : _this.props.defaultShow
}, _this.dismissTimer = null, _this.dismissAfter = function (timeout) {
if (_this.dismissTimer) {
clearTimeout(_this.dismissTimer);
_this.dismissTimer = null;
}
_this.dismissTimer = setTimeout(function () {
_this.dismiss();
}, timeout);
}, _this.dismiss = function () {
if (typeof _this.props.onDismiss === 'function') {
_this.props.onDismiss();
}
_this.setState({ show: false });
}, _this.visible = function () {
return _this.props.show !== undefined ? _this.props.show : _this.state.show;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Notification, [{
key: 'componentDidMount',
value: function componentDidMount() {
if (this.visible()) {
var autoDismiss = this.props.autoDismiss;
if (typeof autoDismiss === 'number' && autoDismiss > 0) {
this.dismissAfter(autoDismiss);
}
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
if (this.visible()) {
var autoDismiss = this.props.autoDismiss;
if (typeof autoDismiss === 'number' && autoDismiss > 0) {
this.dismissAfter(autoDismiss);
}
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.dismissTimer) {
clearTimeout(this.dismissTimer);
this.dismissTimer = null;
}
}
}, {
key: 'render',
value: function render() {
var _cx, _cx2;
var _props = this.props,
type = _props.type,
dismissible = _props.dismissible,
className = _props.className,
children = _props.children,
props = _objectWithoutProperties(_props, ['type', 'dismissible', 'className', 'children']);
var icon = _react2.default.createElement('i', {
className: (0, _classnames2.default)(_index2.default.icon, (_cx = {}, _defineProperty(_cx, _index2.default.iconError, type === 'error'), _defineProperty(_cx, _index2.default.iconWarning, type === 'warning'), _defineProperty(_cx, _index2.default.iconInfo, type === 'info'), _defineProperty(_cx, _index2.default.iconSuccess, type === 'success'), _cx))
});
var dismiss = _react2.default.createElement(_reactAnchor2.default, {
onClick: this.dismiss,
className: _index2.default.btnDismiss
});
delete props.show;
delete props.defaultShow;
delete props.autoDismiss;
delete props.onDismiss;
var visible = this.visible();
return _react2.default.createElement(
'div',
_extends({}, props, {
className: (0, _classnames2.default)(className, _index2.default.notification, (_cx2 = {}, _defineProperty(_cx2, _index2.default.fade, true), _defineProperty(_cx2, _index2.default.in, visible), _defineProperty(_cx2, _index2.default.dismissed, !visible), _defineProperty(_cx2, _index2.default.error, type === 'error'), _defineProperty(_cx2, _index2.default.warning, type === 'warning'), _defineProperty(_cx2, _index2.default.info, type === 'info'), _defineProperty(_cx2, _index2.default.success, type === 'success'), _cx2))
}),
visible && icon,
dismissible && visible && dismiss,
visible && children
);
}
}]);
return Notification;
}(_react.Component), _class.propTypes = {
// One of: 'error', 'warning', 'info', 'success'
type: _propTypes2.default.oneOf(['', 'error', 'success', 'warning', 'info']),
// Whether or not the component is visible.
show: _propTypes2.default.bool,
// It's only used for initial render when the `show` prop is not specified.
defaultShow: _propTypes2.default.bool,
// Whether or not the notification is dismissible.
dismissible: _propTypes2.default.bool,
// The auto dismiss timeout.
autoDismiss: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.bool]),
// A callback fired when the dismiss icon (x) is clicked.
onDismiss: _propTypes2.default.func
}, _class.defaultProps = {
type: '',
dismissible: true,
autoDismiss: false,
onDismiss: function onDismiss(event) {}
}, _temp2);
exports.default = Notification;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
module.exports = {"notification":"notifications---notification---3T-X4","icon":"notifications---icon---1Gg7l","icon-success":"notifications---icon-success---11u21","iconSuccess":"notifications---icon-success---11u21","icon-error":"notifications---icon-error---34lRH","iconError":"notifications---icon-error---34lRH","icon-warning":"notifications---icon-warning---2OGqJ","iconWarning":"notifications---icon-warning---2OGqJ","icon-info":"notifications---icon-info---14HAC","iconInfo":"notifications---icon-info---14HAC","success":"notifications---success---1mkcr","dismissed":"notifications---dismissed---3dxgE","error":"notifications---error---29KRV","warning":"notifications---warning---30q1K","info":"notifications---info---25oWq","fade":"notifications---fade---1VVrQ","in":"notifications---in---1iDGq","btn-dismiss":"notifications---btn-dismiss---1mgsU","btnDismiss":"notifications---btn-dismiss---1mgsU","toast-notification":"notifications---toast-notification---MGSPR","toastNotification":"notifications---toast-notification---MGSPR"};
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = require("classnames");
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("react");
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _class, _temp;
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _Notification = __webpack_require__(0);
var _Notification2 = _interopRequireDefault(_Notification);
var _index = __webpack_require__(1);
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ToastNotification = (_temp = _class = function (_Component) {
_inherits(ToastNotification, _Component);
function ToastNotification() {
_classCallCheck(this, ToastNotification);
return _possibleConstructorReturn(this, (ToastNotification.__proto__ || Object.getPrototypeOf(ToastNotification)).apply(this, arguments));
}
_createClass(ToastNotification, [{
key: 'render',
value: function render() {
var _props = this.props,
className = _props.className,
props = _objectWithoutProperties(_props, ['className']);
return _react2.default.createElement(_Notification2.default, _extends({}, props, {
className: (0, _classnames2.default)(className, _index2.default.toastNotification)
}));
}
}]);
return ToastNotification;
}(_react.Component), _class.propTypes = _extends({}, _Notification2.default.propTypes), _class.defaultProps = _extends({}, _Notification2.default.defaultProps), _temp);
exports.default = ToastNotification;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ToastNotification = exports.Notification = undefined;
var _Notification2 = __webpack_require__(0);
var _Notification3 = _interopRequireDefault(_Notification2);
var _ToastNotification2 = __webpack_require__(4);
var _ToastNotification3 = _interopRequireDefault(_ToastNotification2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Notification = _Notification3.default;
exports.ToastNotification = _ToastNotification3.default;
/***/ }),
/* 6 */
/***/ (function(module, exports) {
module.exports = require("@trendmicro/react-anchor");
/***/ }),
/* 7 */
/***/ (function(module, exports) {
module.exports = require("prop-types");
/***/ })
/******/ ]);
//# sourceMappingURL=index.js.map