Home

Awesome

vue-dynamic-star-rating

A Highly Customizable, easy-to-use elegant stars rating component (similar to Google Play)

MIT License view on npm

For a walkthrough blogpost about how I implemented this component you can head to my medium post

Demo

4.8 star rating

Edit Vue Template

Usage

Install via NPM npm i vue-dynamic-star-rating

Then require in your project:

var StarRating = require('vue-dynamic-star-rating');

or ES6 syntax:

import StarRating from 'vue-dynamic-star-rating'

Then you can register the component globally:

Vue.component('star-rating', StarRating);

Or in your Vue component:

components: {
  StarRating
}

You can then use the following selector anywhere in your project:

<star-rating></star-rating>

Docs

The component <star-rating></star-rating> support various property. You can use either :

Basics

PropertyTypeDescriptionDefault
ratingNumberA number between 0.0-5.0 that will determine the fullness of the 5-stars rating polygons1
isIndicatorActiveBooleanA property that deteremines weather a rating indicator would show to the righttrue
starStyleObjectSee the following "Customized Styling" section below { "fullStarColor" : "#ed8a19", "emptyStarColor" : "#737373", "starWidth" : 20, "starHeight" : 20 }

Customized Styling

PropertyTypeDescriptionDefault
fullStarColorstringSet the full or partially-full star color#ed8a19
emptyStarColorstringSet the empty or partially-empty star color#737373
starWidthnumberSet the star width20
starHeightnumberSet the star height20

Implementation Example

Define your config options object in the component importing StarRating e.g

data: function() {
    return {
        rating: 4.7,
        starStyle: {
            fullStarColor: '#ed8a19',
            emptyStarColor: '#737373',
            starWidth: 30,
            starHeight: 30
        }
    }
}

And bind it to the selector like so

<star-rating :rating="rating" :star-style="starStyle"></star-rating>

Feedback would be much appreciated, questions, suggestions, issues are more than welcome.


👨‍💻 Follow me on Twitter.