Comparing version 1.4.3 to 1.4.4
'use strict'; | ||
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; }; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var React = require('react'); | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
var classNames = require('classnames'); | ||
@@ -14,26 +35,10 @@ | ||
var Switch = React.createClass({ | ||
displayName: 'Switch', | ||
var Switch = function (_Component) { | ||
_inherits(Switch, _Component); | ||
propTypes: { | ||
className: React.PropTypes.string, | ||
prefixCls: React.PropTypes.string, | ||
disabled: React.PropTypes.bool, | ||
checkedChildren: React.PropTypes.any, | ||
unCheckedChildren: React.PropTypes.any, | ||
onChange: React.PropTypes.func, | ||
onMouseUp: React.PropTypes.func | ||
}, | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
prefixCls: 'rc-switch', | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
className: '', | ||
defaultChecked: false, | ||
onChange: noop | ||
}; | ||
}, | ||
getInitialState: function getInitialState() { | ||
var props = this.props; | ||
function Switch(props) { | ||
_classCallCheck(this, Switch); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
var checked = false; | ||
@@ -45,7 +50,7 @@ if ('checked' in props) { | ||
} | ||
return { | ||
checked: checked | ||
}; | ||
}, | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
_this.state = { checked: checked }; | ||
return _this; | ||
} | ||
Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if ('checked' in nextProps) { | ||
@@ -56,4 +61,5 @@ this.setState({ | ||
} | ||
}, | ||
setChecked: function setChecked(checked) { | ||
}; | ||
Switch.prototype.setChecked = function setChecked(checked) { | ||
if (!('checked' in this.props)) { | ||
@@ -65,8 +71,10 @@ this.setState({ | ||
this.props.onChange(checked); | ||
}, | ||
toggle: function toggle() { | ||
}; | ||
Switch.prototype.toggle = function toggle() { | ||
var checked = !this.state.checked; | ||
this.setChecked(checked); | ||
}, | ||
handleKeyDown: function handleKeyDown(e) { | ||
}; | ||
Switch.prototype.handleKeyDown = function handleKeyDown(e) { | ||
if (e.keyCode === 37) { | ||
@@ -78,5 +86,8 @@ this.setChecked(false); | ||
} | ||
}, | ||
}; | ||
// Handle auto focus when click switch in Chrome | ||
handleMouseUp: function handleMouseUp(e) { | ||
Switch.prototype.handleMouseUp = function handleMouseUp(e) { | ||
if (this.refs.node) { | ||
@@ -88,27 +99,28 @@ this.refs.node.blur(); | ||
} | ||
}, | ||
render: function render() { | ||
}; | ||
Switch.prototype.render = function render() { | ||
var _classNames; | ||
var _props = this.props; | ||
var className = _props.className; | ||
var prefixCls = _props.prefixCls; | ||
var disabled = _props.disabled; | ||
var checkedChildren = _props.checkedChildren; | ||
var unCheckedChildren = _props.unCheckedChildren; | ||
var _props = this.props, | ||
className = _props.className, | ||
prefixCls = _props.prefixCls, | ||
disabled = _props.disabled, | ||
checkedChildren = _props.checkedChildren, | ||
unCheckedChildren = _props.unCheckedChildren, | ||
restProps = _objectWithoutProperties(_props, ['className', 'prefixCls', 'disabled', 'checkedChildren', 'unCheckedChildren']); | ||
var restProps = _objectWithoutProperties(_props, ['className', 'prefixCls', 'disabled', 'checkedChildren', 'unCheckedChildren']); | ||
var checked = this.state.checked; | ||
var switchClassName = classNames((_classNames = {}, _defineProperty(_classNames, className, !!className), _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, prefixCls + '-checked', checked), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _classNames)); | ||
return React.createElement( | ||
return _react2["default"].createElement( | ||
'span', | ||
_extends({}, restProps, { | ||
className: switchClassName, | ||
tabIndex: '0', | ||
tabIndex: disabled ? -1 : 0, | ||
ref: 'node', | ||
onKeyDown: this.handleKeyDown, | ||
onClick: disabled ? noop : this.toggle, | ||
onMouseUp: this.handleMouseUp }), | ||
React.createElement( | ||
onKeyDown: this.handleKeyDown.bind(this), | ||
onClick: disabled ? noop : this.toggle.bind(this), | ||
onMouseUp: this.handleMouseUp.bind(this) | ||
}), | ||
_react2["default"].createElement( | ||
'span', | ||
@@ -119,5 +131,29 @@ { className: prefixCls + '-inner' }, | ||
); | ||
} | ||
}); | ||
}; | ||
module.exports = Switch; | ||
return Switch; | ||
}(_react.Component); | ||
Switch.propTypes = { | ||
className: _propTypes2["default"].string, | ||
prefixCls: _propTypes2["default"].string, | ||
disabled: _propTypes2["default"].bool, | ||
checkedChildren: _propTypes2["default"].any, | ||
unCheckedChildren: _propTypes2["default"].any, | ||
onChange: _propTypes2["default"].func, | ||
onMouseUp: _propTypes2["default"].func, | ||
checked: _propTypes2["default"].bool, | ||
defaultChecked: _propTypes2["default"].bool | ||
}; | ||
Switch.defaultProps = { | ||
prefixCls: 'rc-switch', | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
className: '', | ||
defaultChecked: false, | ||
onChange: noop | ||
}; | ||
exports["default"] = Switch; | ||
module.exports = exports['default']; |
{ | ||
"name": "rc-switch", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "switch ui component for react", | ||
@@ -27,9 +27,11 @@ "keywords": [ | ||
"gh-pages": "rc-tools run gh-pages", | ||
"start": "rc-server", | ||
"start": "rc-tools run server", | ||
"pub": "rc-tools run pub", | ||
"lint": "rc-tools run lint", | ||
"lint:fix": "rc-tools run lint --fix", | ||
"karma": "rc-tools run karma", | ||
"saucelabs": "rc-tools run saucelabs", | ||
"browser-test": "rc-tools run browser-test", | ||
"browser-test-cover": "rc-tools run browser-test-cover" | ||
"test": "rc-tools run test", | ||
"chrome-test": "rc-tools run chrome-test", | ||
"coverage": "rc-tools run coverage" | ||
}, | ||
@@ -39,7 +41,6 @@ "devDependencies": { | ||
"pre-commit": "1.x", | ||
"rc-server": "3.x", | ||
"rc-tools": "4.x", | ||
"react": "^0.14.0", | ||
"react-addons-test-utils": "~0.14.0", | ||
"react-dom": "~0.14.0" | ||
"rc-tools": "5.x", | ||
"react": "15.x", | ||
"react-addons-test-utils": "15.x", | ||
"react-dom": "~15.x" | ||
}, | ||
@@ -50,4 +51,5 @@ "pre-commit": [ | ||
"dependencies": { | ||
"classnames": "^2.2.1" | ||
"classnames": "^2.2.1", | ||
"prop-types": "^15.5.6" | ||
} | ||
} |
# rc-switch | ||
--- | ||
switch ui component for react | ||
switch ui component for react. | ||
@@ -26,4 +26,2 @@ [![NPM version][npm-image]][npm-url] | ||
## Screenshots | ||
## Feature | ||
@@ -33,3 +31,2 @@ | ||
## install | ||
@@ -42,5 +39,6 @@ | ||
```js | ||
var Switch = require('rc-switch'); | ||
var React = require('react'); | ||
React.render(<Switch />, container); | ||
import ReactDOM from 'react-dom'; | ||
import Switch from 'rc-switch'; | ||
ReactDOM.render(<Switch />, container); | ||
``` | ||
@@ -101,18 +99,6 @@ | ||
## Example | ||
Online demo: http://react-component.github.io/switch/examples/ | ||
http://localhost:8001/examples/ | ||
online example: http://react-component.github.io/switch/examples/ | ||
## Test Case | ||
http://localhost:8001/tests/runner.html?coverage | ||
## Coverage | ||
http://localhost:8001/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8001/tests/runner.html?coverage | ||
## License | ||
rc-switch is released under the MIT license. |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14073
6
263
0
2
101
+ Addedprop-types@^15.5.6
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact-is@16.13.1(transitive)