bbm-component-library-test
Version:
React based component library for all BBM web applications
119 lines (93 loc) • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _propTypes = require("prop-types");
var _Icon = require("../Icon");
var _Icon2 = _interopRequireDefault(_Icon);
var _styles = require("./styles.js");
var _settings = require("../Common/styles/settings");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 Toastr = function (_Component) {
_inherits(Toastr, _Component);
function Toastr(props) {
_classCallCheck(this, Toastr);
var _this = _possibleConstructorReturn(this, (Toastr.__proto__ || Object.getPrototypeOf(Toastr)).call(this, props));
_this.state = {
mounted: false
};
_this.toggle = _this.toggle.bind(_this);
return _this;
}
_createClass(Toastr, [{
key: "toggle",
value: function toggle() {
var _this2 = this;
setTimeout(function () {
_this2.setState({ mounted: true });
}, 500);
}
}, {
key: "componentWillMount",
value: function componentWillMount() {
this.historyListenner = this.props.history.listen(this.props.closeToastr);
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
this.toggle();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.historyListenner();
}
}, {
key: "render",
value: function render() {
var _props = this.props,
toastrSettings = _props.toastrSettings,
closeToastr = _props.closeToastr;
var mounted = this.state.mounted;
return _react2.default.createElement(
_styles.Wrapper,
{
"data-test": "Toastr",
opened: mounted && toastrSettings,
onClick: closeToastr
},
_react2.default.createElement(
_styles.Text,
null,
toastrSettings && toastrSettings.text
),
_react2.default.createElement(
_styles.IconWrapper,
{ "data-test": "ToastrClose" },
_react2.default.createElement(_Icon2.default, { type: "ToastrClose", color: _settings.white })
)
);
}
}]);
return Toastr;
}(_react.Component);
Toastr.defaultProps = {
toastrSettings: false
};
Toastr.propTypes = {
toastrSettings: (0, _propTypes.oneOfType)([_propTypes.bool, (0, _propTypes.shape)({
text: _propTypes.string
}).isRequired]),
history: (0, _propTypes.shape)({
location: _propTypes.object,
listen: _propTypes.func
}).isRequired,
closeToastr: _propTypes.func.isRequired
};
exports.default = Toastr;