react-rating
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -1,2 +0,2 @@ | ||
/*! react-rating - 0.0.12 | (c) 2015, 2015 dreyescat | MIT | https://github.com/dreyescat/react-rating */ | ||
/*! react-rating - 0.0.13 | (c) 2015, 2015 dreyescat | MIT | https://github.com/dreyescat/react-rating */ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -72,2 +72,19 @@ if(typeof exports === 'object' && typeof module === 'object') | ||
// Returns the index of the rate in the range (start, stop, step). | ||
// Returns undefined index if the rate is outside the range. | ||
// NOTE: A range.step of 0 produces an empty range and consequently returns an | ||
// undefined index. | ||
var indexOf = function indexOf(range, rate) { | ||
// Check the rate is in the proper range [start..stop] according to | ||
// the start, stop and step properties in props. | ||
var step = range.step; | ||
var start = step > 0 ? range.start : range.stop; | ||
var stop = step > 0 ? range.stop : range.start; | ||
if (step && start <= rate && rate <= stop) { | ||
// The index corresponds to the number of steps of size props.step | ||
// that fits between rate and start. | ||
return Math.max(Math.floor((rate - range.start) / step), 0); | ||
} | ||
}; | ||
var Rating = React.createClass({ | ||
@@ -117,3 +134,3 @@ displayName: 'Rating', | ||
this.setState({ | ||
index: this._initialIndex(nextProps) | ||
index: indexOf(nextProps, nextProps.initialRate) | ||
}); | ||
@@ -123,3 +140,3 @@ }, | ||
return { | ||
index: this._initialIndex(this.props), | ||
index: this._rateToIndex(this.props.initialRate), | ||
indexOver: undefined | ||
@@ -153,7 +170,2 @@ }; | ||
}, | ||
_initialIndex: function _initialIndex(props) { | ||
if (this._contains(props.initialRate)) { | ||
return this._rateToIndex(props.initialRate); | ||
} | ||
}, | ||
// Calculate the rate of an index according the the start and step. | ||
@@ -163,12 +175,7 @@ _indexToRate: function _indexToRate(index) { | ||
}, | ||
// Calculate the corresponding index for a rate. | ||
// Calculate the corresponding index for a rate according to the provided | ||
// props or this.props. | ||
_rateToIndex: function _rateToIndex(rate) { | ||
return (rate - this.props.start) / this.props.step; | ||
return indexOf(this.props, rate); | ||
}, | ||
// Check the rate is in the proper range [start..stop]. | ||
_contains: function _contains(rate) { | ||
var start = this.props.step > 0 ? this.props.start : this.props.stop; | ||
var stop = this.props.step > 0 ? this.props.stop : this.props.start; | ||
return start <= rate && rate <= stop; | ||
}, | ||
_roundToFraction: function _roundToFraction(index) { | ||
@@ -175,0 +182,0 @@ // Get the closest top fraction. |
@@ -1,2 +0,2 @@ | ||
/*! react-rating - 0.0.12 | (c) 2015, 2015 dreyescat | MIT | https://github.com/dreyescat/react-rating */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactRating=e(require("react")):t.ReactRating=e(t.React)}(this,function(t){return function(t){function e(n){if(o[n])return o[n].exports;var s=o[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var o={};return e.m=t,e.c=o,e.p="/lib",e(0)}([function(t,e,o){"use strict";t.exports=o(3)},function(e,o){e.exports=t},function(t,e,o){"use strict";var n=o(1),s=n.createClass({displayName:"PercentageSymbol",propTypes:!1,render:function(){var t="string"==typeof this.props.background?n.createElement("div",{className:this.props.background}):n.createElement("div",{style:this.props.background}),e="string"==typeof this.props.icon?n.createElement("div",{className:this.props.icon}):n.createElement("div",{style:this.props.icon}),o={display:"inline-block",position:"absolute",overflow:"hidden",left:0,width:void 0!==this.props.percent?this.props.percent+"%":"auto"},s={display:"inline-block",position:"relative"};return n.createElement("span",{style:s,onMouseDown:this.props.onMouseDown,onMouseOver:this.props.onMouseOver,onMouseLeave:this.props.onMouseLeave,onMouseMove:this.props.onMouseMove},t,n.createElement("div",{style:o},e))}});t.exports=s},function(t,e,o){"use strict";var n=o(1),s=o(5),i=o(2),r=n.createClass({displayName:"Rating",propTypes:!1,getDefaultProps:function(){return{start:0,stop:5,step:1,empty:s.empty,full:s.full,fractions:1,scale:3,onChange:function(t){},onRate:function(t){}}},componentWillReceiveProps:function(t){this.setState({index:this._initialIndex(t)})},getInitialState:function(){return{index:this._initialIndex(this.props),indexOver:void 0}},handleMouseDown:function(t,e){var o=t+this._fractionalIndex(e);this.state.index!==o&&(this.props.onChange(this._indexToRate(o)),this.setState({index:o})),console.log(this._indexToRate(o))},handleMouseLeave:function(t){this.props.onRate(),this.setState({indexOver:void 0})},handleMouseMove:function(t,e){var o=t+this._fractionalIndex(e);this.state.indexOver!==o&&(this.props.onRate(this._indexToRate(o)),this.setState({indexOver:o}))},_initialIndex:function(t){return this._contains(t.initialRate)?this._rateToIndex(t.initialRate):void 0},_indexToRate:function(t){return this.props.start+Math.floor(t)*this.props.step+this.props.step*this._roundToFraction(t%1)},_rateToIndex:function(t){return(t-this.props.start)/this.props.step},_contains:function(t){var e=this.props.step>0?this.props.start:this.props.stop,o=this.props.step>0?this.props.stop:this.props.start;return t>=e&&o>=t},_roundToFraction:function(t){var e=Math.ceil(t%1*this.props.fractions)/this.props.fractions,o=Math.pow(10,this.props.scale);return Math.floor(t)+Math.floor(e*o)/o},_fractionalIndex:function(t){var e=t.clientX-t.currentTarget.getBoundingClientRect().left;return this._roundToFraction(e/t.currentTarget.offsetWidth)},render:function(){for(var t=[],e=[].concat(this.props.empty),o=[].concat(this.props.full),s=void 0!==this.state.indexOver?this.state.indexOver:this.state.index,r=Math.floor(s),a=0;a<this._rateToIndex(this.props.stop);a++){var p=a-r===0?s%1*100:0>a-r?100:0;t.push(n.createElement(i,{key:a,background:e[a%e.length],icon:o[a%o.length],percent:p,onMouseDown:!this.props.readonly&&this.handleMouseDown.bind(this,a),onMouseLeave:!this.props.readonly&&this.handleMouseLeave.bind(this,a),onMouseMove:!this.props.readonly&&this.handleMouseMove.bind(this,a)}))}return n.createElement("span",null,t)}});t.exports=r},function(t,e){"use strict";t.exports=function(){for(var t={},e=0;e<arguments.length;e++){var o=arguments[e];for(var n in o)t[n]=o[n]}return t}},function(t,e,o){"use strict";var n=o(4),s={display:"inline-block",borderRadius:"50%",border:"5px double white",width:30,height:30,cursor:"pointer"};t.exports={empty:n(s,{backgroundColor:"#ccc"}),full:n(s,{backgroundColor:"black"})}}])}); | ||
/*! react-rating - 0.0.13 | (c) 2015, 2015 dreyescat | MIT | https://github.com/dreyescat/react-rating */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactRating=e(require("react")):t.ReactRating=e(t.React)}(this,function(t){return function(t){function e(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var o={};return e.m=t,e.c=o,e.p="/lib",e(0)}([function(t,e,o){"use strict";t.exports=o(3)},function(e,o){e.exports=t},function(t,e,o){"use strict";var n=o(1),r=n.createClass({displayName:"PercentageSymbol",propTypes:!1,render:function(){var t="string"==typeof this.props.background?n.createElement("div",{className:this.props.background}):n.createElement("div",{style:this.props.background}),e="string"==typeof this.props.icon?n.createElement("div",{className:this.props.icon}):n.createElement("div",{style:this.props.icon}),o={display:"inline-block",position:"absolute",overflow:"hidden",left:0,width:void 0!==this.props.percent?this.props.percent+"%":"auto"},r={display:"inline-block",position:"relative"};return n.createElement("span",{style:r,onMouseDown:this.props.onMouseDown,onMouseOver:this.props.onMouseOver,onMouseLeave:this.props.onMouseLeave,onMouseMove:this.props.onMouseMove},t,n.createElement("div",{style:o},e))}});t.exports=r},function(t,e,o){"use strict";var n=o(1),r=o(5),s=o(2),i=function(t,e){var o=t.step,n=o>0?t.start:t.stop,r=o>0?t.stop:t.start;return o&&e>=n&&r>=e?Math.max(Math.floor((e-t.start)/o),0):void 0},a=n.createClass({displayName:"Rating",propTypes:!1,getDefaultProps:function(){return{start:0,stop:5,step:1,empty:r.empty,full:r.full,fractions:1,scale:3,onChange:function(t){},onRate:function(t){}}},componentWillReceiveProps:function(t){this.setState({index:i(t,t.initialRate)})},getInitialState:function(){return{index:this._rateToIndex(this.props.initialRate),indexOver:void 0}},handleMouseDown:function(t,e){var o=t+this._fractionalIndex(e);this.state.index!==o&&(this.props.onChange(this._indexToRate(o)),this.setState({index:o})),console.log(this._indexToRate(o))},handleMouseLeave:function(t){this.props.onRate(),this.setState({indexOver:void 0})},handleMouseMove:function(t,e){var o=t+this._fractionalIndex(e);this.state.indexOver!==o&&(this.props.onRate(this._indexToRate(o)),this.setState({indexOver:o}))},_indexToRate:function(t){return this.props.start+Math.floor(t)*this.props.step+this.props.step*this._roundToFraction(t%1)},_rateToIndex:function(t){return i(this.props,t)},_roundToFraction:function(t){var e=Math.ceil(t%1*this.props.fractions)/this.props.fractions,o=Math.pow(10,this.props.scale);return Math.floor(t)+Math.floor(e*o)/o},_fractionalIndex:function(t){var e=t.clientX-t.currentTarget.getBoundingClientRect().left;return this._roundToFraction(e/t.currentTarget.offsetWidth)},render:function(){for(var t=[],e=[].concat(this.props.empty),o=[].concat(this.props.full),r=void 0!==this.state.indexOver?this.state.indexOver:this.state.index,i=Math.floor(r),a=0;a<this._rateToIndex(this.props.stop);a++){var p=a-i===0?r%1*100:0>a-i?100:0;t.push(n.createElement(s,{key:a,background:e[a%e.length],icon:o[a%o.length],percent:p,onMouseDown:!this.props.readonly&&this.handleMouseDown.bind(this,a),onMouseLeave:!this.props.readonly&&this.handleMouseLeave.bind(this,a),onMouseMove:!this.props.readonly&&this.handleMouseMove.bind(this,a)}))}return n.createElement("span",null,t)}});t.exports=a},function(t,e){"use strict";t.exports=function(){for(var t={},e=0;e<arguments.length;e++){var o=arguments[e];for(var n in o)t[n]=o[n]}return t}},function(t,e,o){"use strict";var n=o(4),r={display:"inline-block",borderRadius:"50%",border:"5px double white",width:30,height:30,cursor:"pointer"};t.exports={empty:n(r,{backgroundColor:"#ccc"}),full:n(r,{backgroundColor:"black"})}}])}); |
{ | ||
"name": "react-rating", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "A rating react component with custom symbols", | ||
@@ -5,0 +5,0 @@ "main": "lib/react-rating.js", |
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
19896
285