-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore-element.html
More file actions
176 lines (167 loc) · 5.72 KB
/
score-element.html
File metadata and controls
176 lines (167 loc) · 5.72 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-button-group/paper-button-group.html">
<link rel="import" href="../paper-button/paper-button.html">
<!--
A web component that lets the user select a numeric value from a defined range.
Every selectable value will be displayed as paper-button.
### Example:
<score-element selected="{{select1}}"></score-element>
<score-element start="0.5" end="2.0" step="0.1" decimals="1" selected="{{select2}}"></score-element>
<score-element class="green" start="0.5" end="2.0" step="0.1" decimals="1" selected="{{select4}}"
ltr></score-element>
### Styling:
--button-score-color: Defines the background color of the button
--text-score-color: Defines the text color of the button
--hover-score-color: Defines the background color of the button in hover state
--hover-text-score-color: Defines the text color of the button in hover state
--selected-score-color: Defines the background color of the button in selected state
--selected--text-score-color: Defines the text color of the button in hover state
@element score-element
@demo demo/index.html
-->
<dom-module id="score-element">
<template>
<style>
paper-button-group {
@apply(--layout-horizontal);
@apply(--layout-center-center);
@apply(--layout-wrap);
}
paper-button {
margin: 0.2em;
min-width: 3em;
background: var(--button-score-color);
color: var(--text-score-color);
--paper-button-checked-color: var(--checked-score-color);
--paper-button-checked-ink-color: var(--checked-score-color);
--paper-button-unchecked-color: var(--unchecked-score-color);
--paper-button-unchecked-ink-color: var(--unchecked-score-color);
}
@media (max-width: 800px) {
paper-button {
min-width: 1em;
margin-left: 0em;
margin-right: 0em;
margin-top: 0em;
margin-bottom: 0.5em;
font-size: 1em;
padding: 0.5em;
}
}
paper-button:hover {
background: var(--hover-score-color);
color: var(--hover-text-score-color);
}
paper-button {
transition: background-color 0.3s;
}
paper-button[active] {
background-color: var(--selected-score-color);
color: var(--selected--text-score-color);
}
</style>
<paper-button-group selected="{{selected}}" attr-for-selected="name" class="layout flex wrap">
<template is="dom-repeat" items="[[_valueArray]]">
<paper-button raised name="[[item]]" on-tap="onButton">[[item]]</paper-button>
</template>
</paper-button-group>
</template>
</dom-module>
<script>
Polymer({
is: 'score-element',
properties: {
/**
* The start value of the score range.
*
* @attribute start
* @type Number
* @default 0
*/
start: {
type: Number,
value: 0
},
/**
* True if the highest score value should be displayed on the left side.
*
* @attribute ltr
* @type Boolean
* @default false
*/
ltr: {
type: Boolean,
value: false
},
/**
* The end value of the score range.
*
* @attribute end
* @type Number
* @default 10
*/
end: {
type: Number,
value: 10
},
/**
* The step size for the score range.
*
* @attribute step
* @type Number
* @default 1
*/
step: {
type: Number,
value: 1
},
/**
* The number of decimal positions to display.
*
* @attribute decimals
* @type Number
* @default 0
*/
decimals: {
type: Number,
value: 0
},
/**
* The currently selected score.
*
* @attribute selected
* @type Number
* @notify true
*/
selected: {
type: Number,
notify: true
},
/**
* The currently calculated value array.
*
* @attribute _valueArray
* @type Array
*/
_valueArray: {
type: Array,
computed: '_calculateArray(start, end, step, decimals)'
}
},
_calculateArray: function (start, end, step, decimals) {
var newArray = [];
var min = Number(start);
var max = Number(end);
var multiplier = Math.pow(10, decimals);
var stepValue = Number(step);
for (var i = min; Math.floor(i * multiplier) <= Math.floor(max * multiplier); i = i + stepValue) {
newArray.push(i.toFixed(decimals));
}
if (this.ltr) {
return newArray.reverse();
} else {
return newArray;
}
}
});
</script>