npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-star-rating

v0.6.1

Published

Adds a star-rating widget to your Ember application.

Downloads

113

Readme

ember-cli-star-rating

Build Status

An Ember CLI addon for using stars to manage ratings in your glorious Ember application.

Compatibility


  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above

Installation

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!

Usage

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();
    }
  }
});

Using other icons

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"}}

Contributing

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.

Running Tests

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.