-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating.vue
102 lines (96 loc) · 2.6 KB
/
rating.vue
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template id="template-star-rating">
<div class="star-rating">
<label
class="star-rating__star"
v-for="rating in ratings"
v-bind:class="{'is-selected': ((value >= rating) && value != null), 'is-disabled': disabled}"
v-on:mouseover="star_over(rating)"
v-on:mouseout="star_out"
v-on:click="set(rating)">
<input
class="star-rating star-rating__checkbox"
type="radio"
v-bind:name="name"
v-bind:value="rating"
v-bind:required="required"
v-bind:id="$index+1"
v-bind:disabled="disabled"
v-model="value">
❤
</label>
</div>
</template>
<style>
.star-rating__checkbox {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
}
.star-rating__star {
display: inline-block;
padding: 3px;
vertical-align: middle;
line-height: 1;
font-size: 1.5em;
color: #ABABAB;
-webkit-transition: color;
transition: color;
}
.star-rating__star:hover {
cursor: pointer;
}
.star-rating__star.is-selected {
color: #df470b;
}
.star-rating__star.is-disabled:hover {
cursor: default;
}
</style>
<script>
Vue.component('star-rating', {
template: '#template-star-rating',
data: function() {
return {
temp_value: null,
ratings: [1, 2, 3, 4, 5]
};
},
props: {
'name': String,
'value': null,
'id': String,
'disabled': String,
'required': Boolean
},
methods: {
star_over: function(index) {
if (this.disabled=="true") {
return;
}
this.temp_value = this.value;
this.value = index;
},
star_out: function() {
if (this.disabled=="true") {
return;
}
this.value = this.temp_value;
},
set: function(value) {
if (this.disabled=="true") {
return;
}
this.temp_value = value;
this.value = value;
}
}
});
new Vue({
el: '#app'
});
</script>