rc-checkbox
Advanced tools
Comparing version 1.4.4 to 1.5.0
@@ -41,43 +41,8 @@ 'use strict'; | ||
_this.handleFocus = function (e) { | ||
_this.setState({ focus: true }); | ||
_this.props.onFocus(e); | ||
}; | ||
_initialiseProps.call(_this); | ||
_this.handleBlur = function (e) { | ||
_this.setState({ focus: false }); | ||
_this.props.onBlur(e); | ||
}; | ||
var checked = 'checked' in props ? props.checked : props.defaultChecked; | ||
_this.handleChange = function (e) { | ||
if (_this.props.disabled) { | ||
return; | ||
} | ||
if (!('checked' in _this.props)) { | ||
_this.setState({ | ||
checked: e.target.checked | ||
}); | ||
} | ||
_this.props.onChange({ | ||
target: _extends({}, _this.props, { | ||
checked: e.target.checked | ||
}), | ||
stopPropagation: function stopPropagation() { | ||
e.stopPropagation(); | ||
}, | ||
preventDefault: function preventDefault() { | ||
e.preventDefault(); | ||
} | ||
}); | ||
}; | ||
var checked = false; | ||
if ('checked' in props) { | ||
checked = props.checked; | ||
} else { | ||
checked = props.defaultChecked; | ||
} | ||
_this.state = { | ||
checked: checked, | ||
focus: false | ||
checked: checked | ||
}; | ||
@@ -106,35 +71,35 @@ return _this; | ||
var props = _extends({}, this.props); | ||
// Remove React warning. | ||
// Warning: Input elements must be either controlled or uncontrolled | ||
// (specify either the value prop, or the defaultValue prop, but not both). | ||
delete props.defaultChecked; | ||
var _props = this.props, | ||
prefixCls = _props.prefixCls, | ||
className = _props.className, | ||
style = _props.style, | ||
name = _props.name, | ||
type = _props.type, | ||
disabled = _props.disabled, | ||
readOnly = _props.readOnly, | ||
tabIndex = _props.tabIndex, | ||
onClick = _props.onClick, | ||
onFocus = _props.onFocus, | ||
onBlur = _props.onBlur; | ||
var checked = this.state.checked; | ||
var state = this.state; | ||
var prefixCls = props.prefixCls; | ||
var checked = state.checked; | ||
if (typeof checked === 'boolean') { | ||
checked = checked ? 1 : 0; | ||
} | ||
var className = (0, _classnames2["default"])((_classNames = {}, _defineProperty(_classNames, props.className, !!props.className), _defineProperty(_classNames, prefixCls, 1), _defineProperty(_classNames, prefixCls + '-checked', checked), _defineProperty(_classNames, prefixCls + '-checked-' + checked, !!checked), _defineProperty(_classNames, prefixCls + '-focused', state.focus), _defineProperty(_classNames, prefixCls + '-disabled', props.disabled), _classNames)); | ||
var classString = (0, _classnames2["default"])(prefixCls, className, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-checked', checked), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _classNames)); | ||
return _react2["default"].createElement( | ||
'span', | ||
{ | ||
className: className, | ||
style: props.style | ||
}, | ||
_react2["default"].createElement('span', { className: prefixCls + '-inner' }), | ||
{ className: classString, style: style }, | ||
_react2["default"].createElement('input', { | ||
name: props.name, | ||
type: props.type, | ||
readOnly: props.readOnly, | ||
disabled: props.disabled, | ||
tabIndex: props.tabIndex, | ||
name: name, | ||
type: type, | ||
readOnly: readOnly, | ||
disabled: disabled, | ||
tabIndex: tabIndex, | ||
className: prefixCls + '-input', | ||
checked: !!checked, | ||
onClick: this.props.onClick, | ||
onFocus: this.handleFocus, | ||
onBlur: this.handleBlur, | ||
onClick: onClick, | ||
onFocus: onFocus, | ||
onBlur: onBlur, | ||
onChange: this.handleChange | ||
}) | ||
}), | ||
_react2["default"].createElement('span', { className: prefixCls + '-inner' }) | ||
); | ||
@@ -147,20 +112,22 @@ }; | ||
Checkbox.propTypes = { | ||
name: _react2["default"].PropTypes.string, | ||
prefixCls: _react2["default"].PropTypes.string, | ||
style: _react2["default"].PropTypes.object, | ||
type: _react2["default"].PropTypes.string, | ||
className: _react2["default"].PropTypes.string, | ||
defaultChecked: _react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.number, _react2["default"].PropTypes.bool]), | ||
disabled: _react2["default"].PropTypes.bool, | ||
checked: _react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.number, _react2["default"].PropTypes.bool]), | ||
onFocus: _react2["default"].PropTypes.func, | ||
onBlur: _react2["default"].PropTypes.func, | ||
onChange: _react2["default"].PropTypes.func, | ||
onClick: _react2["default"].PropTypes.func | ||
prefixCls: _react.PropTypes.string, | ||
className: _react.PropTypes.string, | ||
style: _react.PropTypes.object, | ||
name: _react.PropTypes.string, | ||
type: _react.PropTypes.string, | ||
defaultChecked: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.bool]), | ||
checked: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.bool]), | ||
disabled: _react.PropTypes.bool, | ||
onFocus: _react.PropTypes.func, | ||
onBlur: _react.PropTypes.func, | ||
onChange: _react.PropTypes.func, | ||
onClick: _react.PropTypes.func, | ||
tabIndex: _react.PropTypes.string, | ||
readOnly: _react.PropTypes.bool | ||
}; | ||
Checkbox.defaultProps = { | ||
prefixCls: 'rc-checkbox', | ||
className: '', | ||
style: {}, | ||
type: 'checkbox', | ||
className: '', | ||
defaultChecked: false, | ||
@@ -171,3 +138,32 @@ onFocus: function onFocus() {}, | ||
}; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.handleChange = function (e) { | ||
var props = _this2.props; | ||
if (props.disabled) { | ||
return; | ||
} | ||
if (!('checked' in props)) { | ||
_this2.setState({ | ||
checked: e.target.checked | ||
}); | ||
} | ||
props.onChange({ | ||
target: _extends({}, props, { | ||
checked: e.target.checked | ||
}), | ||
stopPropagation: function stopPropagation() { | ||
e.stopPropagation(); | ||
}, | ||
preventDefault: function preventDefault() { | ||
e.preventDefault(); | ||
} | ||
}); | ||
}; | ||
}; | ||
exports["default"] = Checkbox; | ||
module.exports = exports['default']; |
{ | ||
"name": "rc-checkbox", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"description": "checkbox ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15615
296