@easyguide/checkbox
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -7,2 +7,4 @@ 'use strict'; | ||
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'); | ||
@@ -14,2 +16,6 @@ | ||
var _lodash = require('lodash.isequal'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _elements = require('./elements'); | ||
@@ -28,32 +34,31 @@ | ||
function Checkbox(props) { | ||
function Checkbox() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, Checkbox); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.checkSelectedValue = function (value) { | ||
return _this.state.value.some(function (v) { | ||
return v === value; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { | ||
list: _this.props.items | ||
}, _this.handleChange = function (item) { | ||
var newList = _this.state.list.map(function (listItem) { | ||
if (item.value === listItem.value) { | ||
return _extends({}, listItem, { isActive: !item.isActive }); | ||
} | ||
return _extends({}, listItem); | ||
}); | ||
}; | ||
_this.toggleValue = function (item) { | ||
var value = _this.state.value, | ||
onChange = _this.props.onChange; | ||
_this.setState({ list: newList }, _this.props.onChange(newList)); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
// eslint-disable-next-line babel/no-unused-expressions | ||
Checkbox.prototype.componentDidUpdate = function componentDidUpdate() { | ||
if (!(0, _lodash2.default)(this.props.items, this.state.list)) { | ||
this.setState({ list: this.props.items }); | ||
} | ||
}; | ||
_this.checkSelectedValue(item.value) ? value.splice(value.indexOf(item.value), 1) : value.push(item.value); | ||
_this.setState({ value }, function () { | ||
onChange(value); | ||
}); | ||
}; | ||
_this.state = { | ||
value: props.value | ||
}; | ||
return _this; | ||
} | ||
Checkbox.prototype.render = function render() { | ||
@@ -64,4 +69,4 @@ var _this2 = this; | ||
label = _props.label, | ||
items = _props.items, | ||
className = _props.className; | ||
className = _props.className, | ||
disabled = _props.disabled; | ||
@@ -80,3 +85,3 @@ | ||
null, | ||
items.map(function (item) { | ||
this.state.list.map(function (item) { | ||
return _react2.default.createElement( | ||
@@ -87,5 +92,5 @@ _elements.Tag, | ||
onClick: function onClick() { | ||
return _this2.toggleValue(item); | ||
return !disabled && _this2.handleChange(item); | ||
}, | ||
selected: _this2.checkSelectedValue(item.value) | ||
selected: item.isActive | ||
}, | ||
@@ -92,0 +97,0 @@ item.label |
{ | ||
"name": "@easyguide/checkbox", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Components checkbox ui", | ||
@@ -79,3 +79,7 @@ "author": "iamtchelo", | ||
"dist" | ||
] | ||
], | ||
"dependencies": { | ||
"lodash.isequal": "^4.5.0" | ||
}, | ||
"gitHead": "e78af0dcfc16ab0e501789fad376b88cc0cd0c57" | ||
} |
12054
7
151
4
+ Addedlodash.isequal@^4.5.0
+ Addedlodash.isequal@4.5.0(transitive)