Skip to content

Instantly share code, notes, and snippets.

@brendanoh
Created October 18, 2016 02:01
Show Gist options
  • Save brendanoh/72ad7a19dd0510d4fba4d99f05d709a1 to your computer and use it in GitHub Desktop.
Save brendanoh/72ad7a19dd0510d4fba4d99f05d709a1 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
const computed = Ember.computed;
export default Ember.Component.extend({
value: 0,
min: 1,
max: 5,
starClass: "white-text",
stars: computed('min', 'max', 'value', function() {
const min = this.get('min');
const max = this.get('max');
const val = parseInt(this.get('value'));
let stars = Ember.A();
for (let i = min; i <= max; i = i+2) {
const icon = val >= i+1 ? 'star' : val === i ? 'star-half' : 'star-border';
stars.pushObject({ rating: i, icon: icon });
}
return stars;
}),
actions: {
setRating: function(rating) {
const old = parseInt(this.get('value'));
const newRating = rating === old ? (rating + 1) : (rating + 1) === old ? (rating - 1) : rating;
this.sendAction('action', newRating);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment