-
Notifications
You must be signed in to change notification settings - Fork 7
/
vaadin-login-overlay.html
193 lines (166 loc) · 5.63 KB
/
vaadin-login-overlay.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!--
@license
Vaadin Login
Copyright (C) 2018 Vaadin Ltd
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
-->
<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../vaadin-themable-mixin/vaadin-themable-mixin.html">
<link rel="import" href="../../vaadin-element-mixin/vaadin-element-mixin.html">
<link rel="import" href="vaadin-login.html">
<link rel="import" href="vaadin-login-mixin.html">
<link rel="import" href="vaadin-login-overlay-wrapper.html">
<dom-module id="vaadin-login-overlay">
<template>
<vaadin-login-overlay-wrapper
id="wrapper"
opened="{{opened}}"
focus-trap
with-backdrop
title="[[title]]"
description="[[description]]">
<vaadin-login
theme="with-overlay"
id="login"
action="{{action}}"
disabled="{{disabled}}"
error="{{error}}"
no-forgot-password="{{noForgotPassword}}"
i18n="{{i18n}}"
on-login="_handleEvent"
on-forgot-password="_handleEvent">
<vaadin-text-field slot="username" label="[[i18n.form.username]]" name="username" id="username" required>
<input type="text" slot="input">
</vaadin-text-field>
<vaadin-password-field slot="password" label="[[i18n.form.password]]" name="password" id="password" required>
<input type="password" slot="input">
</vaadin-password-field>
</vaadin-login>
</vaadin-login-overlay-wrapper>
</template>
<script>
(function() {
/**
* `<vaadin-login-overlay>` is a Web Component.
*
* ```
* <vaadin-login-overlay></vaadin-login-overlay>
* ```
*
* @memberof Vaadin
* @mixes Vaadin.ElementMixin
* @mixes Vaadin.ThemableMixin
* @mixes Vaadin.Login.LoginMixin
* @demo demo/index.html
*/
class LoginOverlayElement extends Vaadin.Login.LoginMixin(Vaadin.ElementMixin(Vaadin.ThemableMixin(Polymer.Element))) {
static get is() {
return 'vaadin-login-overlay';
}
static get properties() {
return {
/**
* Defines the application description
*/
description: {
type: String,
value: 'Application description',
notify: true
},
opened: {
type: Boolean,
value: false,
observer: '_onOpenedChange'
},
/**
* Defines the application title
*/
title: {
type: String,
value: 'App name'
}
};
}
static get observers() {
return [
'__i18nChanged(i18n.header.*)'
];
}
ready() {
super.ready();
this._preventClosingLogin = this._preventClosingLogin.bind(this);
}
connectedCallback() {
super.connectedCallback();
this.$.wrapper.addEventListener('vaadin-overlay-outside-click', this._preventClosingLogin);
this.$.wrapper.addEventListener('vaadin-overlay-escape-press', this._preventClosingLogin);
}
disconnectedCallback() {
super.disconnectedCallback();
this.$.wrapper.removeEventListener('vaadin-overlay-outside-click', this._preventClosingLogin);
this.$.wrapper.removeEventListener('vaadin-overlay-escape-press', this._preventClosingLogin);
this.$.wrapper.opened = false;
}
__i18nChanged(i18n) {
const header = i18n.base;
if (!header) {
return;
}
this.title = header.title;
this.description = header.description;
}
_preventClosingLogin(e) {
e.preventDefault();
}
_handleEvent(e) {
e.stopPropagation();
const {
detail,
composed,
cancelable,
bubbles
} = e;
this.dispatchEvent(new CustomEvent(e.type, {bubbles, cancelable, composed, detail}));
}
_onOpenedChange() {
if (!this.opened) {
this.$.login.$.username.value = '';
this.$.login.$.password.value = '';
this.disabled = false;
if (this._undoTeleport) {
this._undoTeleport();
}
} else {
this._undoTeleport = this._teleport(this._getElementsToTeleport());
// Overlay sets pointerEvents on body to `none`, which breaks LastPass popup
// Reverting it back to the previous state
// https://github.com/vaadin/vaadin-overlay/blob/041cde4481b6262eac68d3a699f700216d897373/src/vaadin-overlay.html#L660
document.body.style.pointerEvents = this.$.wrapper._previousDocumentPointerEvents;
}
}
_teleport(elements) {
const teleported = Array.from(elements).map(e => {
return this.$.wrapper.appendChild(e);
});
// Function to undo the teleport
return () => {
while (teleported.length > 0) {
this.appendChild(teleported.shift());
}
};
}
_getElementsToTeleport() {
if (!this._elementsToTeleport) {
this._elementsToTeleport = this.querySelectorAll('[slot=title]');
}
return this._elementsToTeleport;
}
}
customElements.define(LoginOverlayElement.is, LoginOverlayElement);
/**
* @namespace Vaadin
*/
window.Vaadin.LoginOverlayElement = LoginOverlayElement;
})();
</script>
</dom-module>