Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions dist/react-stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ var ReactStars = function (_Component) {
halfStar: {
at: Math.floor(props.value),
hidden: props.half && props.value % 1 < 0.5
}
},
edit: props.edit
};

_this.state.config = {
Expand All @@ -71,10 +72,8 @@ var ReactStars = function (_Component) {
color1: props.color1,
// color of an active star
color2: props.color2,
half: props.half,
edit: props.edit
half: props.half
};

return _this;
}

Expand All @@ -88,13 +87,15 @@ var ReactStars = function (_Component) {
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(props) {
console.log(props);
this.setState({
stars: this.getStars(props.value),
value: props.value,
halfStar: {
at: Math.floor(props.value),
hidden: this.state.config.half && props.value % 1 < 0.5
}
},
edit: props.edit
});
}
}, {
Expand Down Expand Up @@ -132,9 +133,10 @@ var ReactStars = function (_Component) {
value: function mouseOver(event) {
var _state = this.state,
config = _state.config,
halfStar = _state.halfStar;
halfStar = _state.halfStar,
edit = _state.edit;

if (!config.edit) return;
if (!edit) return;
var index = Number(event.target.getAttribute('data-index'));
if (config.half) {
var isAtHalf = this.moreThanHalf(event, config.size);
Expand Down Expand Up @@ -163,9 +165,10 @@ var ReactStars = function (_Component) {
var _state2 = this.state,
value = _state2.value,
halfStar = _state2.halfStar,
config = _state2.config;
config = _state2.config,
edit = _state2.edit;

if (!config.edit) return;
if (!edit) return;
if (config.half) {
halfStar.hidden = !this.isDecimal(value);
halfStar.at = Math.floor(this.state.value);
Expand All @@ -179,9 +182,10 @@ var ReactStars = function (_Component) {
value: function clicked(event) {
var _state3 = this.state,
config = _state3.config,
halfStar = _state3.halfStar;
halfStar = _state3.halfStar,
edit = _state3.edit;

if (!config.edit) return;
if (!edit) return;
var index = Number(event.target.getAttribute('data-index'));
var value = void 0;
if (config.half) {
Expand Down Expand Up @@ -219,13 +223,13 @@ var ReactStars = function (_Component) {
halfStar = _state5.halfStar,
stars = _state5.stars,
uniqueness = _state5.uniqueness,
config = _state5.config;
config = _state5.config,
edit = _state5.edit;
var color1 = config.color1,
color2 = config.color2,
size = config.size,
char = config.char,
half = config.half,
edit = config.edit;
half = config.half;

return stars.map(function (star, i) {
var starClass = '';
Expand Down
25 changes: 13 additions & 12 deletions src/react-stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class ReactStars extends Component {
halfStar: {
at: Math.floor(props.value),
hidden: props.half && props.value % 1 < 0.5
}
},
edit: props.edit
}

this.state.config = {
Expand All @@ -57,9 +58,7 @@ class ReactStars extends Component {
// color of an active star
color2: props.color2,
half: props.half,
edit: props.edit,
}

}

componentDidMount() {
Expand All @@ -69,13 +68,15 @@ class ReactStars extends Component {
}

componentWillReceiveProps(props) {
console.log(props);
this.setState({
stars: this.getStars(props.value),
value: props.value,
halfStar: {
at: Math.floor(props.value),
hidden: this.state.config.half && props.value % 1 < 0.5
}
},
edit: props.edit,
})
}

Expand Down Expand Up @@ -107,8 +108,8 @@ class ReactStars extends Component {
}

mouseOver(event) {
let { config, halfStar } = this.state
if (!config.edit) return;
let { config, halfStar, edit } = this.state
if (!edit) return;
let index = Number(event.target.getAttribute('data-index'))
if (config.half) {
const isAtHalf = this.moreThanHalf(event, config.size)
Expand All @@ -131,8 +132,8 @@ class ReactStars extends Component {
}

mouseLeave() {
const { value, halfStar, config } = this.state
if (!config.edit) return
const { value, halfStar, config, edit } = this.state
if (!edit) return
if (config.half) {
halfStar.hidden = !this.isDecimal(value)
halfStar.at = Math.floor(this.state.value)
Expand All @@ -143,8 +144,8 @@ class ReactStars extends Component {
}

clicked(event) {
const { config, halfStar } = this.state
if (!config.edit) return
const { config, halfStar, edit } = this.state
if (!edit) return
let index = Number(event.target.getAttribute('data-index'))
let value
if (config.half) {
Expand Down Expand Up @@ -173,8 +174,8 @@ class ReactStars extends Component {
}

renderStars() {
const { halfStar, stars, uniqueness, config } = this.state
const { color1, color2, size, char, half, edit } = config
const { halfStar, stars, uniqueness, config, edit } = this.state
const { color1, color2, size, char, half } = config
return stars.map((star, i) => {
let starClass = ''
if (half && !halfStar.hidden && halfStar.at === i) {
Expand Down