Skip to content

Commit

Permalink
Merge pull request #16 from nm2501/master
Browse files Browse the repository at this point in the history
Added editProps property to define additional props in edit mode
  • Loading branch information
kaivi authored Oct 31, 2016
2 parents 417c1fe + eeb308d commit 2586901
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 25 deletions.
3 changes: 2 additions & 1 deletion lib/RIEBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var RIEBase = function (_React$Component) {
function RIEBase(props) {
_classCallCheck(this, RIEBase);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RIEBase).call(this, props));
var _this = _possibleConstructorReturn(this, (RIEBase.__proto__ || Object.getPrototypeOf(RIEBase)).call(this, props));

_this.doValidations = function (value) {
if (_this.props.validate) {
Expand Down Expand Up @@ -91,6 +91,7 @@ RIEBase.propTypes = {
value: _react2.default.PropTypes.any.isRequired,
change: _react2.default.PropTypes.func.isRequired,
propName: _react2.default.PropTypes.string.isRequired,
editProps: _react2.default.PropTypes.object,
isDisabled: _react2.default.PropTypes.bool,
validate: _react2.default.PropTypes.func,
shouldBlockWhileLoading: _react2.default.PropTypes.bool,
Expand Down
9 changes: 6 additions & 3 deletions lib/RIENumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand All @@ -26,7 +28,7 @@ var RIENumber = function (_RIEStatefulBase) {
function RIENumber(props) {
_classCallCheck(this, RIENumber);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RIENumber).call(this, props));
var _this = _possibleConstructorReturn(this, (RIENumber.__proto__ || Object.getPrototypeOf(RIENumber)).call(this, props));

_this.validate = function (value) {
return !isNaN(value) && isFinite(value) && value.length > 0;
Expand All @@ -52,14 +54,15 @@ var RIENumber = function (_RIEStatefulBase) {
};

_this.renderEditingComponent = function () {
return _react2.default.createElement('input', { disabled: _this.props.shouldBlockWhileLoading && _this.state.loading,
return _react2.default.createElement('input', _extends({ disabled: _this.props.shouldBlockWhileLoading && _this.state.loading,
type: 'number',
className: _this.makeClassString(),
defaultValue: _this.props.value,
onInput: _this.textChanged,
onBlur: _this.finishEditing,
ref: 'input',
onKeyDown: _this.keyDown });
onKeyDown: _this.keyDown
}, _this.props.editProps));
};

return _this;
Expand Down
11 changes: 7 additions & 4 deletions lib/RIESelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand All @@ -28,7 +30,7 @@ var RIESelect = function (_RIEStatefulBase) {
_inherits(RIESelect, _RIEStatefulBase);

function RIESelect() {
var _Object$getPrototypeO;
var _ref;

var _temp, _this, _ret;

Expand All @@ -38,7 +40,7 @@ var RIESelect = function (_RIEStatefulBase) {
args[_key] = arguments[_key];
}

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(RIESelect)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.finishEditing = function () {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = RIESelect.__proto__ || Object.getPrototypeOf(RIESelect)).call.apply(_ref, [this].concat(args))), _this), _this.finishEditing = function () {
// get the object from options that matches user selected value
var newValue = _this.props.options.find(function (option) {
return option.id === _reactDom2.default.findDOMNode(this.refs.input).value;
Expand All @@ -59,13 +61,14 @@ var RIESelect = function (_RIEStatefulBase) {

return _react2.default.createElement(
'select',
{ disabled: _this.props.shouldBlockWhileLoading && _this.state.loading,
_extends({ disabled: _this.props.shouldBlockWhileLoading && _this.state.loading,
value: _this.props.value.id,
className: _this.makeClassString(),
onChange: _this.finishEditing,
onBlur: _this.cancelEditing,
ref: 'input',
onKeyDown: _this.keyDown },
onKeyDown: _this.keyDown
}, _this.props.editProps),
optionNodes
);
}, _this.renderNormalComponent = function () {
Expand Down
9 changes: 6 additions & 3 deletions lib/RIEStatefulBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand All @@ -30,7 +32,7 @@ var RIEStatefulBase = function (_RIEBase) {
function RIEStatefulBase(props) {
_classCallCheck(this, RIEStatefulBase);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RIEStatefulBase).call(this, props));
var _this = _possibleConstructorReturn(this, (RIEStatefulBase.__proto__ || Object.getPrototypeOf(RIEStatefulBase)).call(this, props));

_this.startEditing = function () {
_this.setState({ editing: true });
Expand Down Expand Up @@ -73,14 +75,15 @@ var RIEStatefulBase = function (_RIEBase) {
};

_this.renderEditingComponent = function () {
return _react2.default.createElement('input', {
return _react2.default.createElement('input', _extends({
disabled: _this.state.loading,
className: _this.makeClassString(),
defaultValue: _this.props.value,
onInput: _this.textChanged,
onBlur: _this.finishEditing,
ref: 'input',
onKeyDown: _this.keyDown });
onKeyDown: _this.keyDown
}, _this.props.editProps));
};

_this.renderNormalComponent = function () {
Expand Down
6 changes: 3 additions & 3 deletions lib/RIETags.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var RIETag = function (_React$Component) {
function RIETag(props) {
_classCallCheck(this, RIETag);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RIETag).call(this, props));
var _this = _possibleConstructorReturn(this, (RIETag.__proto__ || Object.getPrototypeOf(RIETag)).call(this, props));

_this.remove = function () {
_this.props.removeHandler(_this.props.text);
Expand All @@ -46,7 +46,7 @@ var RIETag = function (_React$Component) {
_react2.default.createElement(
'div',
{ onClick: _this.remove, className: _this.props.className || "remove" },
' × '
' \xD7 '
)
);
};
Expand All @@ -69,7 +69,7 @@ var RIETags = function (_RIEStatefulBase) {
function RIETags(props) {
_classCallCheck(this, RIETags);

var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(RIETags).call(this, props));
var _this2 = _possibleConstructorReturn(this, (RIETags.__proto__ || Object.getPrototypeOf(RIETags)).call(this, props));

_this2.addTag = function (tag) {
if ([].concat(_toConsumableArray(_this2.props.value)).length < (_this2.props.maxTags || 65535)) {
Expand Down
11 changes: 7 additions & 4 deletions lib/RIETextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand All @@ -28,7 +30,7 @@ var RIETextArea = function (_RIEStatefulBase) {
_inherits(RIETextArea, _RIEStatefulBase);

function RIETextArea() {
var _Object$getPrototypeO;
var _ref;

var _temp, _this, _ret;

Expand All @@ -38,12 +40,12 @@ var RIETextArea = function (_RIEStatefulBase) {
args[_key] = arguments[_key];
}

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(RIETextArea)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.keyDown = function (event) {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = RIETextArea.__proto__ || Object.getPrototypeOf(RIETextArea)).call.apply(_ref, [this].concat(args))), _this), _this.keyDown = function (event) {
if (event.keyCode === 27) {
_this.cancelEditing();
} // Escape
}, _this.renderEditingComponent = function () {
return _react2.default.createElement('textarea', {
return _react2.default.createElement('textarea', _extends({
rows: _this.props.rows,
cols: _this.props.cols,
disabled: _this.state.loading,
Expand All @@ -52,7 +54,8 @@ var RIETextArea = function (_RIEStatefulBase) {
onInput: _this.textChanged,
onBlur: _this.finishEditing,
ref: 'input',
onKeyDown: _this.keyDown });
onKeyDown: _this.keyDown
}, _this.props.editProps));
}, _this.renderNormalComponent = function () {
var value = _this.state.newValue || _this.props.value;
var spans_and_brs = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/RIEToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var RIEToggle = function (_RIEBase) {
_inherits(RIEToggle, _RIEBase);

function RIEToggle() {
var _Object$getPrototypeO;
var _ref;

var _temp, _this, _ret;

Expand All @@ -34,7 +34,7 @@ var RIEToggle = function (_RIEBase) {
args[_key] = arguments[_key];
}

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(RIEToggle)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.elementClick = function (e) {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = RIEToggle.__proto__ || Object.getPrototypeOf(RIEToggle)).call.apply(_ref, [this].concat(args))), _this), _this.elementClick = function (e) {
_this.setState({ value: !_this.props.value });
_this.commit(!_this.props.value);
}, _this.render = function () {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var RIEInput = function (_RIEStatefulBase) {
function RIEInput() {
_classCallCheck(this, RIEInput);

return _possibleConstructorReturn(this, Object.getPrototypeOf(RIEInput).apply(this, arguments));
return _possibleConstructorReturn(this, (RIEInput.__proto__ || Object.getPrototypeOf(RIEInput)).apply(this, arguments));
}

return RIEInput;
Expand Down
1 change: 1 addition & 0 deletions src/RIEBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class RIEBase extends React.Component {
value: React.PropTypes.any.isRequired,
change: React.PropTypes.func.isRequired,
propName: React.PropTypes.string.isRequired,
editProps: React.PropTypes.object,
isDisabled: React.PropTypes.bool,
validate: React.PropTypes.func,
shouldBlockWhileLoading: React.PropTypes.bool,
Expand Down
3 changes: 2 additions & 1 deletion src/RIENumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class RIENumber extends RIEStatefulBase {
onInput={this.textChanged}
onBlur={this.finishEditing}
ref="input"
onKeyDown={this.keyDown} />;
onKeyDown={this.keyDown}
{...this.props.editProps} />;
};
}
3 changes: 2 additions & 1 deletion src/RIESelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default class RIESelect extends RIEStatefulBase {
onChange={this.finishEditing}
onBlur={this.cancelEditing}
ref="input"
onKeyDown={this.keyDown}>{optionNodes}</select>
onKeyDown={this.keyDown}
{...this.props.editProps}>{optionNodes}</select>
};

renderNormalComponent = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/RIEStatefulBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default class RIEStatefulBase extends RIEBase {
onInput={this.textChanged}
onBlur={this.finishEditing}
ref="input"
onKeyDown={this.keyDown} />;
onKeyDown={this.keyDown}
{...this.props.editProps} />;
};

renderNormalComponent = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/RIETextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class RIETextArea extends RIEStatefulBase {
onInput={this.textChanged}
onBlur={this.finishEditing}
ref="input"
onKeyDown={this.keyDown} />;
onKeyDown={this.keyDown}
{...this.props.editProps} />;
};

renderNormalComponent = () => {
Expand Down

0 comments on commit 2586901

Please sign in to comment.