This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
paper-password-input.html
112 lines (98 loc) · 2.25 KB
/
paper-password-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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-styles/default-theme.html">
<!--
A Material Design input field to enter passwords
@demo demo/index.html
-->
<dom-module id="paper-password-input">
<template>
<style>
.visibility-icon {
color: var(--disabled-text-color);
/** Bottom align visibility button with input box */
height: 32px;
width: 32px;
padding: 0 4px;
margin-top: -6px;
}
</style>
<paper-input
id="input"
type="[[_getType(visible)]]"
value="{{value}}"
label="[[label]]"
name="[[name]]"
maxlength="[[maxlength]]"
disabled="[[disabled]]"
readonly="[[readonly]]"
required="[[required]]"
autofocus="[[autofocus]]"
auto-validate="[[autoValidate]]"
allowed-pattern="[[allowedPattern]]"
invalid="{{invalid}}"
validator="[[validator]]"
error-message="[[errorMessage]]"
char-counter="[[charCounter]]">
<paper-icon-button
slot="suffix"
icon="[[_getIcon(visible)]]"
on-tap="_toggleVisible"
class="visibility-icon"
tabindex="-1"
alt="[[alt]]"
></paper-icon-button>
</paper-input>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'paper-password-input',
properties: {
/**
* True if the content of the password field is visible
*/
visible: {
type: Boolean,
value: false
},
value: {
type: String,
notify: true
},
invalid: {
type: Boolean,
notify: true
},
label: String,
name: String,
disabled: Boolean,
required: Boolean,
readonly: Boolean,
autofocus: Boolean,
autoValidate: Boolean,
validator: String,
errorMessage: String,
charCounter: Boolean,
maxlength: Number,
allowedPattern: String,
alt: String,
},
validate: function() {
return this.$.input.validate();
},
_getIcon: function(visible) {
return visible ? 'icons:visibility' : 'icons:visibility-off';
},
_getType: function(visible) {
return visible ? '' : 'password';
},
_toggleVisible: function() {
this.visible = !this.visible;
},
});
})();
</script>