Comparing version 2.1.0 to 2.1.1
162
lib/Rate.js
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactDom = require('react-dom'); | ||
@@ -12,5 +16,5 @@ | ||
var _react = require('react'); | ||
var _propTypes = require('prop-types'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
@@ -29,43 +33,33 @@ var _classnames = require('classnames'); | ||
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 _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); } | ||
function noop() {} | ||
var Rate = _react2["default"].createClass({ | ||
displayName: 'Rate', | ||
var Rate = function (_React$Component) { | ||
_inherits(Rate, _React$Component); | ||
propTypes: { | ||
disabled: _react.PropTypes.bool, | ||
value: _react.PropTypes.number, | ||
defaultValue: _react.PropTypes.number, | ||
count: _react.PropTypes.number, | ||
allowHalf: _react.PropTypes.bool, | ||
style: _react.PropTypes.object, | ||
prefixCls: _react.PropTypes.string, | ||
onChange: _react.PropTypes.func, | ||
onHoverChange: _react.PropTypes.func, | ||
className: _react.PropTypes.string, | ||
character: _react.PropTypes.node | ||
}, | ||
function Rate(props) { | ||
_classCallCheck(this, Rate); | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
defaultValue: 0, | ||
count: 5, | ||
allowHalf: false, | ||
style: {}, | ||
prefixCls: 'rc-rate', | ||
onChange: noop, | ||
character: '★', | ||
onHoverChange: noop | ||
}; | ||
}, | ||
getInitialState: function getInitialState() { | ||
var value = this.props.value; | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
_initialiseProps.call(_this); | ||
var value = props.value; | ||
if (value === undefined) { | ||
value = this.props.defaultValue; | ||
value = props.defaultValue; | ||
} | ||
return { | ||
_this.state = { | ||
value: value | ||
}; | ||
}, | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
return _this; | ||
} | ||
Rate.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if ('value' in nextProps) { | ||
@@ -80,30 +74,9 @@ var value = nextProps.value; | ||
} | ||
}, | ||
onHover: function onHover(event, index) { | ||
var hoverValue = this.getStarValue(index, event.pageX); | ||
this.setState({ | ||
hoverValue: hoverValue | ||
}); | ||
this.props.onHoverChange(hoverValue); | ||
}, | ||
onMouseLeave: function onMouseLeave() { | ||
this.setState({ | ||
hoverValue: undefined | ||
}); | ||
this.props.onHoverChange(undefined); | ||
}, | ||
onClick: function onClick(event, index) { | ||
var value = this.getStarValue(index, event.pageX); | ||
if (!('value' in this.props)) { | ||
this.setState({ | ||
value: value | ||
}); | ||
} | ||
this.onMouseLeave(); | ||
this.props.onChange(value); | ||
}, | ||
getStarDOM: function getStarDOM(index) { | ||
}; | ||
Rate.prototype.getStarDOM = function getStarDOM(index) { | ||
return _reactDom2["default"].findDOMNode(this.refs['star_' + index]); | ||
}, | ||
getStarValue: function getStarValue(index, x) { | ||
}; | ||
Rate.prototype.getStarValue = function getStarValue(index, x) { | ||
var value = index + 1; | ||
@@ -118,4 +91,5 @@ if (this.props.allowHalf) { | ||
return value; | ||
}, | ||
render: function render() { | ||
}; | ||
Rate.prototype.render = function render() { | ||
var _props = this.props, | ||
@@ -158,6 +132,62 @@ count = _props.count, | ||
); | ||
} | ||
}); | ||
}; | ||
return Rate; | ||
}(_react2["default"].Component); | ||
Rate.propTypes = { | ||
disabled: _propTypes2["default"].bool, | ||
value: _propTypes2["default"].number, | ||
defaultValue: _propTypes2["default"].number, | ||
count: _propTypes2["default"].number, | ||
allowHalf: _propTypes2["default"].bool, | ||
style: _propTypes2["default"].object, | ||
prefixCls: _propTypes2["default"].string, | ||
onChange: _propTypes2["default"].func, | ||
onHoverChange: _propTypes2["default"].func, | ||
className: _propTypes2["default"].string, | ||
character: _propTypes2["default"].node | ||
}; | ||
Rate.defaultProps = { | ||
defaultValue: 0, | ||
count: 5, | ||
allowHalf: false, | ||
style: {}, | ||
prefixCls: 'rc-rate', | ||
onChange: noop, | ||
character: '★', | ||
onHoverChange: noop | ||
}; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.onHover = function (event, index) { | ||
var hoverValue = _this2.getStarValue(index, event.pageX); | ||
_this2.setState({ | ||
hoverValue: hoverValue | ||
}); | ||
_this2.props.onHoverChange(hoverValue); | ||
}; | ||
this.onMouseLeave = function () { | ||
_this2.setState({ | ||
hoverValue: undefined | ||
}); | ||
_this2.props.onHoverChange(undefined); | ||
}; | ||
this.onClick = function (event, index) { | ||
var value = _this2.getStarValue(index, event.pageX); | ||
if (!('value' in _this2.props)) { | ||
_this2.setState({ | ||
value: value | ||
}); | ||
} | ||
_this2.onMouseLeave(); | ||
_this2.props.onChange(value); | ||
}; | ||
}; | ||
exports["default"] = Rate; | ||
module.exports = exports['default']; |
@@ -11,29 +11,48 @@ 'use strict'; | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var Star = _react2["default"].createClass({ | ||
displayName: 'Star', | ||
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; } | ||
propTypes: { | ||
value: _react.PropTypes.number, | ||
index: _react.PropTypes.number, | ||
prefixCls: _react.PropTypes.string, | ||
allowHalf: _react.PropTypes.bool, | ||
disabled: _react.PropTypes.bool, | ||
onHover: _react.PropTypes.func, | ||
onClick: _react.PropTypes.func, | ||
character: _react.PropTypes.node | ||
}, | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
onHover: function onHover(e) { | ||
this.props.onHover(e, this.props.index); | ||
}, | ||
onClick: function onClick(e) { | ||
this.props.onClick(e, this.props.index); | ||
}, | ||
getClassName: function getClassName() { | ||
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 Star = function (_React$Component) { | ||
_inherits(Star, _React$Component); | ||
function Star() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, Star); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.onHover = function (e) { | ||
var _this$props = _this.props, | ||
onHover = _this$props.onHover, | ||
index = _this$props.index; | ||
onHover(e, index); | ||
}, _this.onClick = function (e) { | ||
var _this$props2 = _this.props, | ||
onClick = _this$props2.onClick, | ||
index = _this$props2.index; | ||
onClick(e, index); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
Star.prototype.getClassName = function getClassName() { | ||
var _props = this.props, | ||
prefixCls = _props.prefixCls, | ||
index = _props.index, | ||
value = _props.value, | ||
prefixCls = _props.prefixCls, | ||
allowHalf = _props.allowHalf; | ||
@@ -46,4 +65,5 @@ | ||
return starValue <= value ? prefixCls + ' ' + prefixCls + '-full' : prefixCls + ' ' + prefixCls + '-zero'; | ||
}, | ||
render: function render() { | ||
}; | ||
Star.prototype.render = function render() { | ||
var onHover = this.onHover, | ||
@@ -74,6 +94,18 @@ onClick = this.onClick; | ||
); | ||
} | ||
}); | ||
}; | ||
return Star; | ||
}(_react2["default"].Component); | ||
Star.propTypes = { | ||
value: _propTypes2["default"].number, | ||
index: _propTypes2["default"].number, | ||
prefixCls: _propTypes2["default"].string, | ||
allowHalf: _propTypes2["default"].bool, | ||
disabled: _propTypes2["default"].bool, | ||
onHover: _propTypes2["default"].func, | ||
onClick: _propTypes2["default"].func, | ||
character: _propTypes2["default"].node | ||
}; | ||
exports["default"] = Star; | ||
module.exports = exports['default']; |
{ | ||
"name": "rc-rate", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "React Star Rate Component", | ||
@@ -44,5 +44,4 @@ "keywords": [ | ||
"rc-tools": "5.x", | ||
"react": "0.14.x", | ||
"react-addons-test-utils": "0.14.x", | ||
"react-dom": "0.14.x" | ||
"react": "^15.0.0", | ||
"react-dom": "^15.0.0" | ||
}, | ||
@@ -53,4 +52,5 @@ "pre-commit": [ | ||
"dependencies": { | ||
"classnames": "^2.2.5" | ||
"classnames": "^2.2.5", | ||
"prop-types": "^15.5.8" | ||
} | ||
} |
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
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
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
18988
5
372
2
1
+ Addedprop-types@^15.5.8
+ 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)