This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
star-rating.html
66 lines (65 loc) · 1.53 KB
/
star-rating.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/iron-flex-layout/classes/iron-flex-layout.html">
<link rel="import" href="bower_components/paper-styles/color.html">
<dom-module id="star-rating">
<template>
<style>
:host {
display: inline-block;
}
.ratings iron-icon.star {
--iron-icon-height: 16px;
--iron-icon-width: 16px;
color: var(--paper-yellow-700);
}
.rating {
opacity: var(--dark-primary-opacity);
margin-left: 8px;
margin-right: 2px;
}
.total {
opacity: var(--dark-primary-opacity);
}
</style>
<div class="layout horizontal center ratings">
<template is="dom-repeat" items="[[stars]]" as="star">
<iron-icon icon="{{_computeIcon(star.active)}}" class="star"></iron-icon>
</template>
<span class="rating">{{rating}}</span> (<span class="total">{{total}}</span>)
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'star-rating',
properties: {
count: {
type: Number,
value: 5
},
total: {
type: Number,
value: 0
},
rating: {
type: Number,
value: 0
},
stars: {
type: Array,
readOnly: true,
computed: '_computeStars(rating, count)'
}
},
_computeStars: function(rating, count) {
var stars = [];
for (var i = 1; i <= count; ++i) {
stars.push({active: rating >= i});
}
return stars;
},
_computeIcon: function(active) {
return active ? 'icons:star' : 'icons:star-border';
}
});
</script>