Created
October 18, 2016 02:01
-
-
Save brendanoh/72ad7a19dd0510d4fba4d99f05d709a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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