Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ember-cli-star-rating
Advanced tools
An Ember CLI addon for using stars to manage ratings in your glorious Ember application.
As this is an Ember addon, you just need to do:
ember install ember-cli-star-rating
Reload your app and you're ready to reach for the stars!
The addon makes a star-rating
component accessible in your consuming Ember app. You should pass it the item the rating should be set on, the rating property itself and the action that should be fired when one of the stars is clicked by the user.
{{star-rating item=song rating=song.rating on-click=(action "updateRating")}}
Optionally, you can pass the maximum rating (the number of stars to be drawn, which is 5 by default):
{{star-rating item=song rating=song.rating on-click=(action "updateRating") maxRating=10}}
If you use the component in the non-block form (like above), the appropriate glyphicon classes ('glyphicon-star' and ''glyphicon-star-empty') will be added to each star's tag, so you'll need to have the glyphicons fonts pulled in to display them correctly.
In the block form, the component yields back the stars (where star.full
is a boolean) and the set
action that will be called when any of the stars is clicked:
{{#star-rating item=song rating=song.rating on-click=(action "updateRating") as |stars set|}}
{{#each stars as |star|}}
<a {{action set star.rating}}>
{{if star.full}}*{{else}}_{{/if}}
</a>
{{/each}}
{{/star-rating}}
The action you pass (updateRating
in the above example) will be called with a params hash that has an item
and a rating
key. item
is the item that was clicked and rating
is the new rating value. You can then handle the action as you wish:
import Ember from 'ember';
export default Ember.Controller.extend({
(...)
actions: {
updateRating(params) {
let { item: song, rating } = params;
song.set('rating', rating);
return song.save();
}
}
});
You can use other glyphicons or font-awesome icons by specifying fullClassNames
and emptyClassNames
like this:
{{star-rating item=song rating=song.rating on-click="updateRating" fullClassNames='fa fa-star' emptyClassNames='fa fa-star-o'}}
If you want to do this globally you can create your own component by creating a app/components/star-rating-fa.js
file with the following content:
import StarRatingComponent from 'ember-cli-star-rating/components/star-rating';
export default StarRatingComponent.extend({
fullClassNames: 'fa fa-star',
emptyClassNames: 'fa fa-star-o'
});
Then use it like this:
{{star-rating-fa item=song rating=song.rating on-click="updateRating"}}
I'm happy to consider changes and accept feature requests. If you submit a PR, please include tests in tests/integration/components/star-rating-test.js
.
Ember CLI now makes it joyfully simple to write integration tests. You can check out the current tests or this blog post to see how.
You can run your tests by typing ember test
in the addon or launching ember serve
and then going to http://localhost:4200
to see the tests run.
FAQs
Adds a star-rating widget to your Ember application.
The npm package ember-cli-star-rating receives a total of 31 weekly downloads. As such, ember-cli-star-rating popularity was classified as not popular.
We found that ember-cli-star-rating demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.