@shakthillc/components
Version:
React generic components for shakthi products
165 lines (136 loc) • 5.82 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 _AlertBoxModule = require("./AlertBox.module.css");
var _AlertBoxModule2 = _interopRequireDefault(_AlertBoxModule);
var _Icon = require("@material-ui/core/Icon");
var _Icon2 = _interopRequireDefault(_Icon);
var _propTypes = require("prop-types");
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 AlertBox = function (_Component) {
_inherits(AlertBox, _Component);
function AlertBox(props) {
_classCallCheck(this, AlertBox);
var _this = _possibleConstructorReturn(this, (AlertBox.__proto__ || Object.getPrototypeOf(AlertBox)).call(this, props));
_this.state = { show: false };
_this.toggleAlert = _this.toggleAlert.bind(_this);
return _this;
}
_createClass(AlertBox, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps, PrevState) {
var _this2 = this;
var _props = this.props,
show = _props.show,
onClose = _props.onClose;
if (prevProps.show != show) {
if (!this.props.show) {
onClose && onClose();
} else {
this.setState({ show: true }, function () {
_this2.alertTimer = setTimeout(function () {
if (_this2.state.show && show) {
onClose && onClose();
_this2.setState({ show: false });
}
}, 5000);
});
}
}
}
}, {
key: "toggleAlert",
value: function toggleAlert() {
var _this3 = this;
var onClose = this.props.onClose;
onClose && onClose();
this.setState({ show: false }, function () {
clearTimeout(_this3.alertTimer);
});
}
}, {
key: "render",
value: function render() {
var _props2 = this.props,
mainText = _props2.mainText,
subText = _props2.subText,
_props2$type = _props2.type,
type = _props2$type === undefined ? 2 : _props2$type,
_props2$icon = _props2.icon,
icon = _props2$icon === undefined ? "check_circle" : _props2$icon,
_props2$type2 = _props2.type,
type = _props2$type2 === undefined ? "default" : _props2$type2;
var theme = {
danger: "#cc3b3b",
warning: "#eeb200",
success: "#007c89",
default: "black"
};
var themeIcon = {
danger: "highlight_off",
warning: "error_outline",
success: "check_circle",
default: icon
};
var show = this.state.show;
return _react2.default.createElement(
"div",
{
className: show === true ? _AlertBoxModule2.default["alert-box"] + " " + _AlertBoxModule2.default["alert-box--show"] : _AlertBoxModule2.default["alert-box"]
},
_react2.default.createElement(
"span",
{ className: _AlertBoxModule2.default["alert-box__status-icon"] },
_react2.default.createElement(
_Icon2.default,
{ style: { color: theme[type] } },
themeIcon[type]
)
),
_react2.default.createElement(
"p",
{ className: _AlertBoxModule2.default["alert-box__main-info"] },
mainText
),
_react2.default.createElement(
"span",
{
onClick: this.toggleAlert.bind(this),
className: _AlertBoxModule2.default["alert-box__close-icon"]
},
_react2.default.createElement(
_Icon2.default,
null,
"close"
)
),
_react2.default.createElement(
"p",
{ className: _AlertBoxModule2.default["alert-box__sub-info"] },
subText
),
show === true && _react2.default.createElement("div", {
style: { width: "100%", backgroundColor: theme[type] },
className: _AlertBoxModule2.default["alter-box__loader"]
})
);
}
}]);
return AlertBox;
}(_react.Component);
exports.default = AlertBox;
AlertBox.defaultProps = {
show: true
};
AlertBox.propTypes = {
mainText: _propTypes.PropTypes.string,
subText: _propTypes.PropTypes.string,
show: _propTypes.PropTypes.bool
};