├── .gitignore ├── demo_indicator.png ├── package.json ├── README.md └── star-rating.vue /.gitignore: -------------------------------------------------------------------------------- 1 | *.idea 2 | -------------------------------------------------------------------------------- /demo_indicator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JonathanDn/vue-stars-rating/HEAD/demo_indicator.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-dynamic-star-rating", 3 | "version": "1.0.8", 4 | "description": "A highly dynamic vue stars rating component, similar to google play stars rating", 5 | "main": "star-rating.vue", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "peerDependencies": { 10 | "vue": "^2.5.17" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/JonathanDn/vue-stars-rating.git" 15 | }, 16 | "keywords": [ 17 | "vue", "vue.js", "frontend", "web", "stars", "rating", "google play", "star-rating", "stars-rating", "dynamic", "customize" 18 | ], 19 | "author": "Jonathan Doron ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/JonathanDn/vue-stars-rating/issues" 23 | }, 24 | "homepage": "https://github.com/JonathanDn/vue-stars-rating#readme" 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-dynamic-star-rating 2 | ## A Highly Customizable, easy-to-use elegant stars rating component (similar to Google Play) 3 | 4 | ![MIT License](https://badgen.net/badge/license/MIT/blue "MIT License") 5 | [![view on npm](http://img.shields.io/npm/v/vue-dynamic-star-rating.svg?colorB=red)](https://www.npmjs.org/package/vue-dynamic-star-rating) 6 | 7 | For a walkthrough blogpost about how I implemented this component you can head to my *[medium post](https://medium.com/@yonatandoron/star-rating-make-svg-great-again-d4ce4731347e)* 8 | 9 | ###### Demo 10 | 11 | ![4.8 star rating](https://github.com/JonathanDn/vue-stars-rating/blob/master/demo_indicator.png "4.8 star rating") 12 | 13 | [![Edit Vue Template](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/morqm41968) 14 | 15 | # Usage 16 | Install via NPM ```npm i vue-dynamic-star-rating``` 17 | 18 | Then require in your project: 19 | ```js 20 | var StarRating = require('vue-dynamic-star-rating'); 21 | ``` 22 | or ES6 syntax: 23 | ```js 24 | import StarRating from 'vue-dynamic-star-rating' 25 | ``` 26 | Then you can register the component globally: 27 | ```js 28 | Vue.component('star-rating', StarRating); 29 | ``` 30 | Or in your Vue component: 31 | ```js 32 | components: { 33 | StarRating 34 | } 35 | ``` 36 | You can then use the following selector anywhere in your project: 37 | * To get up and running quick the package now supports rendering just the selector with default values 38 | ```html 39 | 40 | ``` 41 | 42 | # Docs 43 | The component `` support various property. You can use either : 44 | - `rating` to define the default rating value 45 | - `star-style` to define the style that applies to the rating. If not provided, the default values are used. 46 | - `is-indicator-active` to determine if an indicator should be enabled. 47 | 48 | ## Basics 49 | 50 | | Property | Type | Description | Default 51 | | --- | --- | --- | --- | 52 | | **rating** | Number | A number between 0.0-5.0 that will determine the fullness of the 5-stars rating polygons | 1 | 53 | | **isIndicatorActive** | Boolean | A property that deteremines weather a rating indicator would show to the right | true | 54 | | **starStyle** | Object | See the following "Customized Styling" section below | ``` { "fullStarColor" : "#ed8a19", "emptyStarColor" : "#737373", "starWidth" : 20, "starHeight" : 20 }``` 55 | 56 | ## Customized Styling 57 | 58 | | Property | Type | Description | Default | 59 | | --- | --- | --- | --- | 60 | | **fullStarColor** | string | Set the full or partially-full star color | ```#ed8a19``` | 61 | | **emptyStarColor** | string | Set the empty or partially-empty star color | ```#737373``` | 62 | | **starWidth** | number | Set the star width | 20 | 63 | | **starHeight** | number | Set the star height | 20 | 64 | 65 | ## Implementation Example 66 | Define your **config** options object in the component importing StarRating e.g 67 | ```js 68 | data: function() { 69 | return { 70 | rating: 4.7, 71 | starStyle: { 72 | fullStarColor: '#ed8a19', 73 | emptyStarColor: '#737373', 74 | starWidth: 30, 75 | starHeight: 30 76 | } 77 | } 78 | } 79 | ``` 80 | And bind it to the selector like so 81 | ```html 82 | 83 | 84 | ``` 85 | 86 | Feedback would be much appreciated, questions, suggestions, issues are more than welcome. 87 | 88 | --- 89 | 👨‍💻 Follow me on [Twitter](https://twitter.com/jodoron). 90 | -------------------------------------------------------------------------------- /star-rating.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 173 | 174 | 186 | --------------------------------------------------------------------------------