forked from David-Mulder/paper-color-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb-component-input.html
94 lines (76 loc) · 1.95 KB
/
rgb-component-input.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
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-input/iron-input.html">
<link rel="import" href="../paper-input/paper-input-container.html">
<link rel="import" href="../paper-input/paper-input-error.html">
<link rel="import" href="../paper-input/paper-input-behavior.html">
<link rel="import" href="rgb-component-validator.html">
<dom-module id="rgb-component-input">
<template>
<style>
:host {
display: inline-block;
}
:host([hidden]) {
display: none !important;
}
input[is="iron-input"] {
font: inherit;
outline: none;
box-shadow: none;
border: none;
width: auto;
text-align: center;
}
</style>
<rgb-component-validator></rgb-component-validator>
<paper-input-container auto-validate always-float-label>
<label for="input">[[ color ]]</label>
<input is="iron-input"
id="input"
type="number"
bind-value="{{ value }}"
minlength="1"
maxlength="3"
aria-label="[[ color ]] value from 0 to 255"
allowed-pattern="[0-9]"
validator="rgb-component-validator"
invalid="{{ invalid }}"
prevent-invalid-input
/>
<paper-input-error>0 - 255</paper-input-error>
</paper-input-container>
</template>
</dom-module>
<script>
Polymer({
is: 'rgb-component-input',
behaviors: [
Polymer.PaperInputBehavior
],
properties: {
color: {
type: String
},
invalid: {
type: Boolean,
value: false,
notify: true
},
value: {
type: Number
}
},
listeners: {
'value-changed': '_onValueChanged'
},
_onValueChanged: function (e, obj) {
value = parseInt(obj.value);
if (value > 255) {
value = 255;
} else if (value < 0) {
value = 0;
}
this.set('value', value);
}
});
</script>