Comparing version 0.6.2 to 0.6.3
@@ -0,1 +1,8 @@ | ||
## 0.6.3 (26 июня 2018) | ||
## Новые возможности | ||
* Добавлено свойство `noMargins` компоненту "Сообщение" (`Alert`) | ||
* Добавлен параметр `approve` всплывающим подтверждениям (`showConfirm`) | ||
## 0.6.2 (26 июня 2018) | ||
@@ -2,0 +9,0 @@ |
@@ -27,2 +27,3 @@ 'use strict'; | ||
button = _ref.button, | ||
noMargins = _ref.noMargins, | ||
children = _ref.children; | ||
@@ -33,2 +34,3 @@ return _react2.default.createElement( | ||
className: (0, _classnames2.default)('n3__alert', 'n3__alert_color_' + color, { | ||
'n3__alert_no-margins': noMargins, | ||
'n3__alert_has-button': button | ||
@@ -55,2 +57,3 @@ }) | ||
button: _propTypes2.default.node, | ||
noMargins: _propTypes2.default.bool, | ||
@@ -63,2 +66,3 @@ children: _propTypes2.default.node | ||
button: null, | ||
noMargins: false, | ||
children: null | ||
@@ -65,0 +69,0 @@ }; |
@@ -330,2 +330,8 @@ 'use strict'; | ||
}); | ||
Object.defineProperty(exports, 'ConfirmError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _showConfirm.ConfirmError; | ||
} | ||
}); | ||
@@ -332,0 +338,0 @@ var _sidebar = require('./sidebar'); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.Confirm = undefined; | ||
exports.Confirm = exports.ConfirmError = undefined; | ||
@@ -21,2 +21,6 @@ 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 _es6Error = require('es6-error'); | ||
var _es6Error2 = _interopRequireDefault(_es6Error); | ||
var _clay = require('../clay'); | ||
@@ -38,2 +42,6 @@ | ||
var _alert = require('../alert'); | ||
var _alert2 = _interopRequireDefault(_alert); | ||
var _showModal = require('./show-modal'); | ||
@@ -45,2 +53,4 @@ | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -52,2 +62,21 @@ | ||
var ConfirmError = exports.ConfirmError = function (_ExtendableError) { | ||
_inherits(ConfirmError, _ExtendableError); | ||
function ConfirmError(_ref) { | ||
var title = _ref.title, | ||
message = _ref.message; | ||
_classCallCheck(this, ConfirmError); | ||
var _this = _possibleConstructorReturn(this, (ConfirmError.__proto__ || Object.getPrototypeOf(ConfirmError)).call(this, 'Confirm error')); | ||
_this.title = title; | ||
_this.message = message; | ||
return _this; | ||
} | ||
return ConfirmError; | ||
}(_es6Error2.default); | ||
var Confirm = exports.Confirm = function (_Component) { | ||
@@ -57,5 +86,6 @@ _inherits(Confirm, _Component); | ||
function Confirm() { | ||
var _ref; | ||
var _ref2, | ||
_this3 = this; | ||
var _temp, _this, _ret; | ||
var _temp, _this2, _ret; | ||
@@ -68,7 +98,89 @@ _classCallCheck(this, Confirm); | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Confirm.__proto__ || Object.getPrototypeOf(Confirm)).call.apply(_ref, [this].concat(args))), _this), _this.handleCancel = function () { | ||
_this.props.resolveModal(false); | ||
}, _this.handleApprove = function () { | ||
_this.props.resolveModal(true); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
return _ret = (_temp = (_this2 = _possibleConstructorReturn(this, (_ref2 = Confirm.__proto__ || Object.getPrototypeOf(Confirm)).call.apply(_ref2, [this].concat(args))), _this2), _this2.state = { | ||
approving: false, | ||
error: null | ||
}, _this2.handleCancel = function () { | ||
if (_this2.state.approving) { | ||
return; | ||
} | ||
_this2.props.resolveModal(false); | ||
}, _this2.handleApprove = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
var approve, error; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!_this2.state.approving) { | ||
_context.next = 2; | ||
break; | ||
} | ||
return _context.abrupt('return'); | ||
case 2: | ||
approve = _this2.props.approve; | ||
_context.next = 5; | ||
return _this2.setState({ | ||
approving: true, | ||
error: null | ||
}); | ||
case 5: | ||
if (!approve) { | ||
_context.next = 23; | ||
break; | ||
} | ||
error = void 0; | ||
_context.prev = 7; | ||
_context.next = 10; | ||
return approve(); | ||
case 10: | ||
_context.next = 19; | ||
break; | ||
case 12: | ||
_context.prev = 12; | ||
_context.t0 = _context['catch'](7); | ||
if (!(_context.t0 instanceof ConfirmError)) { | ||
_context.next = 18; | ||
break; | ||
} | ||
error = _context.t0; | ||
_context.next = 19; | ||
break; | ||
case 18: | ||
throw _context.t0; | ||
case 19: | ||
if (!error) { | ||
_context.next = 23; | ||
break; | ||
} | ||
_context.next = 22; | ||
return _this2.setState({ | ||
approving: false, | ||
error: error | ||
}); | ||
case 22: | ||
return _context.abrupt('return'); | ||
case 23: | ||
_this2.props.resolveModal(true); | ||
case 24: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this3, [[7, 12]]); | ||
})), _temp), _possibleConstructorReturn(_this2, _ret); | ||
} | ||
@@ -84,2 +196,5 @@ | ||
approveButtonText = _props.approveButtonText; | ||
var _state = this.state, | ||
approving = _state.approving, | ||
error = _state.error; | ||
@@ -105,2 +220,15 @@ | ||
content | ||
), | ||
error && _react2.default.createElement( | ||
_clay2.default, | ||
{ margin: [6, 0, 0] }, | ||
_react2.default.createElement( | ||
_alert2.default, | ||
{ | ||
color: 'danger', | ||
title: error.title, | ||
noMargins: true | ||
}, | ||
error.message | ||
) | ||
) | ||
@@ -123,2 +251,3 @@ ), | ||
}, | ||
disabled: approving, | ||
onClick: this.handleCancel | ||
@@ -134,2 +263,3 @@ }, | ||
}, | ||
disabled: approving, | ||
onClick: this.handleApprove, | ||
@@ -153,2 +283,3 @@ color: 'primary' | ||
content: _propTypes2.default.node, | ||
approve: _propTypes2.default.func, | ||
cancalButtonText: _propTypes2.default.string, | ||
@@ -162,16 +293,19 @@ approveButtonText: _propTypes2.default.string, | ||
content: null, | ||
approve: null, | ||
cancalButtonText: 'Отмена', | ||
approveButtonText: 'Ок' | ||
}; | ||
function showConfirm(_ref2) { | ||
var title = _ref2.title, | ||
content = _ref2.content, | ||
cancalButtonText = _ref2.cancalButtonText, | ||
approveButtonText = _ref2.approveButtonText; | ||
function showConfirm(_ref4) { | ||
var title = _ref4.title, | ||
content = _ref4.content, | ||
approve = _ref4.approve, | ||
cancalButtonText = _ref4.cancalButtonText, | ||
approveButtonText = _ref4.approveButtonText; | ||
return (0, _showModal2.default)(function (_ref3) { | ||
var resolveModal = _ref3.resolveModal; | ||
return (0, _showModal2.default)(function (_ref5) { | ||
var resolveModal = _ref5.resolveModal; | ||
return _react2.default.createElement(Confirm, { | ||
title: title, | ||
content: content, | ||
approve: approve, | ||
cancalButtonText: cancalButtonText, | ||
@@ -178,0 +312,0 @@ approveButtonText: approveButtonText, |
{ | ||
"name": "@n3/kit", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "React components for n3 interfaces", | ||
@@ -71,2 +71,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"es6-error": "^4.1.1", | ||
"escape-html": "^1.0.3", | ||
@@ -73,0 +74,0 @@ "humane-js": "^3.2.2", |
468287
13428
22
+ Addedes6-error@^4.1.1
+ Addedes6-error@4.1.1(transitive)