react-checkbox-group
Advanced tools
Comparing version
{ | ||
"name": "react-checkbox-group", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Sensible checkbox groups manipulation for DOM.", | ||
@@ -40,6 +40,4 @@ "main": "react-checkbox-group.js", | ||
"react": "^15.0.1", | ||
"react-addons-test-utils": "^15.0.1", | ||
"react-dom": "^15.0.1", | ||
"prop-types": "^15.5.8" | ||
"react-dom": "^15.0.1" | ||
} | ||
} |
@@ -16,6 +16,2 @@ 'use strict'; | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -43,3 +39,3 @@ | ||
value: function componentWillMount() { | ||
if (!(this.context && this.context.checkboxGroup)) { | ||
if (!(this.props && this.props.checkboxGroup)) { | ||
throw new Error('The `Checkbox` component must be used as a child of `CheckboxGroup`.'); | ||
@@ -51,6 +47,8 @@ } | ||
value: function render() { | ||
var _context$checkboxGrou = this.context.checkboxGroup, | ||
name = _context$checkboxGrou.name, | ||
checkedValues = _context$checkboxGrou.checkedValues, | ||
onChange = _context$checkboxGrou.onChange; | ||
var _props = this.props, | ||
_props$checkboxGroup = _props.checkboxGroup, | ||
name = _props$checkboxGroup.name, | ||
checkedValues = _props$checkboxGroup.checkedValues, | ||
onChange = _props$checkboxGroup.onChange, | ||
rest = _objectWithoutProperties(_props, ['checkboxGroup']); | ||
@@ -65,3 +63,3 @@ var optional = {}; | ||
return _react2.default.createElement('input', _extends({}, this.props, { | ||
return _react2.default.createElement('input', _extends({}, rest, { | ||
type: 'checkbox', | ||
@@ -77,6 +75,2 @@ name: name, | ||
Checkbox.contextTypes = { | ||
checkboxGroup: _propTypes2.default.object.isRequired | ||
}; | ||
var CheckboxGroup = exports.CheckboxGroup = function (_Component2) { | ||
@@ -92,3 +86,2 @@ _inherits(CheckboxGroup, _Component2); | ||
_this2._onCheckboxChange = _this2._onCheckboxChange.bind(_this2); | ||
_this2.getChildContext = _this2.getChildContext.bind(_this2); | ||
_this2.getValue = _this2.getValue.bind(_this2); | ||
@@ -102,12 +95,2 @@ _this2.state = { | ||
_createClass(CheckboxGroup, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
var checkboxGroup = { | ||
name: this.props.name, | ||
checkedValues: this.state.value, | ||
onChange: this._onCheckboxChange | ||
}; | ||
return { checkboxGroup: checkboxGroup }; | ||
} | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
@@ -124,14 +107,22 @@ value: function componentWillReceiveProps(newProps) { | ||
value: function render() { | ||
var _props = this.props, | ||
Component = _props.Component, | ||
name = _props.name, | ||
value = _props.value, | ||
onChange = _props.onChange, | ||
children = _props.children, | ||
rest = _objectWithoutProperties(_props, ['Component', 'name', 'value', 'onChange', 'children']); | ||
var checkboxGroup = { | ||
name: this.props.name, | ||
checkedValues: this.state.value, | ||
onChange: this._onCheckboxChange | ||
}; | ||
var _props2 = this.props, | ||
Component = _props2.Component, | ||
name = _props2.name, | ||
value = _props2.value, | ||
onChange = _props2.onChange, | ||
children = _props2.children, | ||
rest = _objectWithoutProperties(_props2, ['Component', 'name', 'value', 'onChange', 'children']); | ||
return _react2.default.createElement( | ||
Component, | ||
rest, | ||
children | ||
_react2.default.Children.map(children, function (child) { | ||
return _react2.default.cloneElement(child, { checkboxGroup: checkboxGroup }); | ||
}) | ||
); | ||
@@ -176,15 +167,4 @@ } | ||
CheckboxGroup.childContextTypes = { | ||
checkboxGroup: _propTypes2.default.object.isRequired | ||
}; | ||
CheckboxGroup.propTypes = { | ||
name: _propTypes2.default.string, | ||
defaultValue: _propTypes2.default.array, | ||
value: _propTypes2.default.array, | ||
onChange: _propTypes2.default.func, | ||
children: _propTypes2.default.node.isRequired, | ||
Component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func, _propTypes2.default.object]) | ||
}; | ||
CheckboxGroup.defaultProps = { | ||
Component: "div" | ||
}; |
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -7,8 +6,4 @@ export class Checkbox extends Component { | ||
static contextTypes = { | ||
checkboxGroup: PropTypes.object.isRequired | ||
} | ||
componentWillMount() { | ||
if (!(this.context && this.context.checkboxGroup)) { | ||
if (!(this.props && this.props.checkboxGroup)) { | ||
throw new Error('The `Checkbox` component must be used as a child of `CheckboxGroup`.'); | ||
@@ -19,3 +14,3 @@ } | ||
render() { | ||
const {name, checkedValues, onChange} = this.context.checkboxGroup; | ||
const {checkboxGroup: {name, checkedValues, onChange}, ...rest} = this.props; | ||
const optional = {}; | ||
@@ -31,3 +26,3 @@ if (checkedValues) { | ||
<input | ||
{...this.props} | ||
{...rest} | ||
type="checkbox" | ||
@@ -45,19 +40,2 @@ name={name} | ||
static childContextTypes = { | ||
checkboxGroup: PropTypes.object.isRequired | ||
} | ||
static propTypes = { | ||
name: PropTypes.string, | ||
defaultValue: PropTypes.array, | ||
value: PropTypes.array, | ||
onChange: PropTypes.func, | ||
children: PropTypes.node.isRequired, | ||
Component: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.func, | ||
PropTypes.object | ||
]) | ||
} | ||
static defaultProps = { | ||
@@ -71,3 +49,2 @@ Component: "div" | ||
this._onCheckboxChange = this._onCheckboxChange.bind(this); | ||
this.getChildContext = this.getChildContext.bind(this); | ||
this.getValue = this.getValue.bind(this); | ||
@@ -79,11 +56,2 @@ this.state = { | ||
getChildContext() { | ||
const checkboxGroup = { | ||
name: this.props.name, | ||
checkedValues: this.state.value, | ||
onChange: this._onCheckboxChange | ||
}; | ||
return {checkboxGroup}; | ||
} | ||
componentWillReceiveProps(newProps) { | ||
@@ -98,4 +66,10 @@ if (newProps.value) { | ||
render() { | ||
const checkboxGroup = { | ||
name: this.props.name, | ||
checkedValues: this.state.value, | ||
onChange: this._onCheckboxChange | ||
}; | ||
const {Component, name, value, onChange, children, ...rest} = this.props; | ||
return <Component {...rest}>{children}</Component>; | ||
return <Component {...rest}>{React.Children.map(children, child => React.cloneElement(child, {checkboxGroup}))}</Component>; | ||
} | ||
@@ -102,0 +76,0 @@ |
@@ -5,3 +5,3 @@ import React from 'react'; | ||
import {Checkbox, CheckboxGroup} from '../react-checkbox-group.jsx'; | ||
import {Simulate, renderIntoDocument} from 'react-addons-test-utils'; | ||
import {Simulate, renderIntoDocument} from 'react-dom/test-utils'; | ||
@@ -8,0 +8,0 @@ function _findInputWithValue(wrapper, value) { |
10
-16.67%19426
-5.85%390
-9.51%