Skip to content

Commit

Permalink
Public elements refactor (#80)
Browse files Browse the repository at this point in the history
* Remove vaadin-login since it doesn't provide password managers support and its
name makes it look like main component
* Create internal vaadin-login-form-wrapper for handling native form
* Create new element `vaadin-login-form` which can be used inline and has 
password managers support as long as it's not inside a shadow root
  • Loading branch information
alexberazouski committed Jan 29, 2019
1 parent 95eca47 commit 6cd2413
Show file tree
Hide file tree
Showing 38 changed files with 545 additions and 408 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
|
[API documentation ↗](https://vaadin.com/components/vaadin-login/html-api)

[Vaadin Login](https://vaadin.com/components/vaadin-login) consists of two components:

[<vaadin-login>](https://vaadin.com/components/vaadin-login) is a Web Component providing a painless login experience, part of the [Vaadin components](https://vaadin.com/components).
<vaadin-login-overlay> is a Web Component providing a painless login experience, part of the [Vaadin components](https://vaadin.com/components). Component shows the <vaadin-login-form> inside of an overlay.

```html
<vaadin-login></vaadin-login>
<vaadin-login-overlay opened></vaadin-login-overlay>
```

`<vaadin-login-overlay>` is a `<vaadin-login>` wrapper which opens the login form in an overlay and allows the form being accessible for password managers.
[<img src="https://raw.githubusercontent.com/vaadin/vaadin-login/master/screenshot.png" width="700" alt="Screenshot of vaadin-login-overlay">](https://vaadin.com/components/vaadin-login)

&lt;vaadin-login-form&gt; is a Web Component providing a form to require users to log in into an application.

```html
<vaadin-login-overlay></vaadin-login-overlay>
<vaadin-login-form></vaadin-login-form>
```

[<img src="https://raw.githubusercontent.com/vaadin/vaadin-login/master/screenshot.png" width="700" alt="Screenshot of vaadin-login-overlay">](https://vaadin.com/components/vaadin-login)


## Installation

The Vaadin components are distributed as Bower and npm packages.
Expand All @@ -51,7 +51,7 @@ bower i vaadin/vaadin-login --save
Once installed, import it in your application:

```html
<link rel="import" href="bower_components/vaadin-login/vaadin-login.html">
<link rel="import" href="bower_components/vaadin-login/vaadin-login-overlay.html">
```
### Polymer 3 and ES Modules compatible version

Expand All @@ -65,7 +65,7 @@ npm i @vaadin/vaadin-login --save
Once installed, import it in your application:

```js
import '@vaadin/vaadin-login/vaadin-login.js';
import '@vaadin/vaadin-login/vaadin-login-overlay.js';
```

## Getting started
Expand All @@ -78,18 +78,18 @@ To use the Material theme, import the correspondent file from the `theme/materia

- The component with the Lumo theme:

`theme/lumo/vaadin-login.html`
`theme/lumo/vaadin-login-overlay.html`
`theme/lumo/vaadin-login-form.html`

- The component with the Material theme:

`theme/material/vaadin-login.html`
`theme/material/vaadin-login-overlay.html`
`theme/material/vaadin-login-form.html`

- Aliases for lumo themed components:

`vaadin-login.html`
`vaadin-login-overlay.html`
`vaadin-login-form.html`


## Running demos and tests in browser
Expand Down
6 changes: 4 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
],
"description": "vaadin-login",
"main": [
"vaadin-login.html",
"theme/material/vaadin-login.html"
"vaadin-login-overlay.html",
"vaadin-login-form.html",
"theme/material/vaadin-login-overlay.html",
"theme/material/vaadin-login-form.html"
],
"keywords": [
"Vaadin",
Expand Down
14 changes: 9 additions & 5 deletions demo/advanced-demos.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ <h3>Title with custom HTML</h3>
<vaadin-demo-snippet id="login-overlay">
<template preserve-content>
<style>
iron-icon {
top: -2px;
.logo {
top: -4px;
height: 29px;
width: 29px;
}

.customTitle {
color: var(--lumo-primary-contrast-color);
}
</style>
<vaadin-login-overlay><h1 slot="title"><iron-icon icon="vaadin:vaadin-h"></iron-icon> My App</h1></vaadin-login-overlay>
<vaadin-login-overlay><h1 slot="title" class="customTitle"><iron-icon icon="vaadin:vaadin-h" class="logo"></iron-icon> My App</h1></vaadin-login-overlay>
<vaadin-button>Log in</vaadin-button>
<vaadin-dialog id="feedbackDialog">
<template>Login is being processed...</template>
Expand Down Expand Up @@ -101,7 +105,7 @@ <h3>Login form without overlay</h3>
}
</style>
<main>
<vaadin-login></vaadin-login>
<vaadin-login-form></vaadin-login-form>
</main>
<vaadin-dialog id="feedbackDialog">
<template>Login is being processed...</template>
Expand All @@ -111,7 +115,7 @@ <h3>Login form without overlay</h3>
</vaadin-dialog>
<script>
window.addDemoReadyListener('#element-basic-demos-sample-example', function(document) {
var login = document.querySelector('vaadin-login');
var login = document.querySelector('vaadin-login-form');
var feedbackDialog = document.querySelector('#feedbackDialog');
var supportDialog = document.querySelector('#supportDialog');

Expand Down
105 changes: 105 additions & 0 deletions demo/index-standalone.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<title>Vaadin Login Inline Example</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>

<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../vaadin-dialog/vaadin-dialog.html">
<link rel="import" href="../../vaadin-button/vaadin-button.html">
<link rel="import" href="../vaadin-login-overlay.html">

<style>
.sidebar {
grid-area: sidebar;
}

.content {
grid-area: content;
}

.header {
grid-area: header;
}

.footer {
grid-area: footer;
}

.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, 33%);
grid-template-areas:
"....... header header"
"sidebar content content"
"footer footer footer";
background-color: #fff;
color: #444;
}

.box {
background-color: #444;
color: #fff;
border-radius: 5px;
padding: 10px;
font-size: 150%;
}

.header,
.footer {
background-color: #999;
}
</style>
</head>

<body>
<div class="wrapper">
<div class="box header">Header</div>
<div class="box sidebar">Sidebar
<vaadin-login-form></vaadin-login-form>
</div>
<div class="box content">Content
</div>
<div class="box footer">Footer</div>
</div>
<vaadin-dialog id="feedbackDialog">
<template>Login is being processed...</template>
</vaadin-dialog>
<vaadin-dialog id="supportDialog">
<template>Try with admin/admin.</template>
</vaadin-dialog>
<script>
window.addEventListener('WebComponentsReady', function(e) {
var login = document.querySelector('vaadin-login-form');
var feedbackDialog = document.querySelector('#feedbackDialog');
var supportDialog = document.querySelector('#supportDialog');

login.addEventListener('login', function(e) {
feedbackDialog.opened = true;
var detail = e.detail,
username = detail.username,
password = detail.password;

setTimeout(function() {
feedbackDialog.opened = false;
if (username === 'admin' && password === 'admin') {
login.remove();
} else {
login.error = true;
}
}, 1000);
});

login.addEventListener('forgot-password', function() {
supportDialog.opened = true;
});
});

</script>
</body>

</html>
13 changes: 8 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
<script src="./element-demo.js"></script>
<link rel="import" href="../../vaadin-dialog/vaadin-dialog.html">
<link rel="import" href="../../vaadin-button/vaadin-button.html">
<link rel="import" href="../vaadin-login.html">
<link rel="import" href="../vaadin-login-overlay.html">

<custom-style>
<style include="vaadin-component-demo-shared-styles"></style>
</custom-style>
<style>
iron-icon {
top: -2px;
height: 29px;
width: 29px;
.logo {
top: -4px;
height: 30px;
width: 30px;
}

.customTitle {
color: var(--lumo-primary-contrast-color);
}

vaadin-component-demo {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<link rel="import" href="../iron-component-page/iron-component-page.html">
</head>
<body>
<iron-component-page src="vaadin-login.html"></iron-component-page>
<iron-component-page src="vaadin-login-overlay.html"></iron-component-page>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vaadin/vaadin-login",
"version": "1.0.0-alpha8",
"description": "vaadin-login",
"main": "vaadin-login.html",
"main": "vaadin-login-overlay.html",
"repository": "vaadin/vaadin-login",
"keywords": [
"Vaadin",
Expand Down
57 changes: 9 additions & 48 deletions src/vaadin-login.html → src/vaadin-login-form-wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

<link rel="import" href="vaadin-login-mixin.html">

<link rel="import" href="../../vaadin-text-field/src/vaadin-text-field.html">
<link rel="import" href="../../vaadin-text-field/src/vaadin-password-field.html">
<link rel="import" href="../../vaadin-button/src/vaadin-button.html">

<dom-module id="vaadin-login">
<dom-module id="vaadin-login-form-wrapper">
<template>
<style>
:host {
Expand All @@ -38,10 +36,6 @@
margin: 0;
}

#loginForm * {
width: 100%;
}

[part="error-message"] {
position: relative;
}
Expand All @@ -54,20 +48,6 @@ <h5 part="error-message-title">[[i18n.errorMessage.title]]</h5>
</div>

<slot name="form">
<form id="loginForm" method="POST" action$="[[action]]">
<vaadin-text-field name="username" label="[[i18n.form.username]]"
id="username" required on-keydown="_handleInputKeydown"
autocapitalize="none" autocorrect="off" spellcheck="false">
<input type="text" slot="input">
</vaadin-text-field>

<vaadin-password-field name="password" label="[[i18n.form.password]]" id="password" required on-keydown="_handleInputKeydown"
spellcheck="false">
<input type="password" slot="input">
</vaadin-password-field>

<vaadin-button id="submit" theme="primary contained vaadin-login-submit" on-click="submit" disabled$="[[disabled]]">[[i18n.form.submit]]</vaadin-button>
</form>
</slot>

<vaadin-button id="forgotPasswordButton" theme="tertiary small forgot-password" on-click="_forgotPassword" hidden$="[[noForgotPassword]]">[[i18n.form.forgotPassword]]</vaadin-button>
Expand All @@ -82,18 +62,13 @@ <h5 part="error-message-title">[[i18n.errorMessage.title]]</h5>
(function() {

/**
* `<vaadin-login>` is a Web Component providing an easy way to require users
* to log in into an application.
* `<vaadin-login-form-wrapper>` is a helper component providing a wrapper for the login form.
*
* ```
* <vaadin-login></vaadin-login>
* ```
*
* Use `<vaadin-login-overlay>` Web Component which allows the form to work with password managers.
* See the usage in `<vaadin-login-form>`.
*
* ### Styling
*
* The following Shadow DOM parts of the `<vaadin-login>` are available for styling:
* The following Shadow DOM parts of the `<vaadin-login-form-wrapper>` are available for styling:
*
* Part name | Description
* ---------------|---------------------------------------------------------|
Expand All @@ -113,7 +88,7 @@ <h5 part="error-message-title">[[i18n.errorMessage.title]]</h5>
*
* Slot name | Description
* ----------|---------------------------------------------------|
* `form` | Html form placeholder. See the usage in `<vaadin-login-overlay>`.
* `form` | Html form placeholder. See the usage in `<vaadin-login-form>`.
*
* See examples of setting the content into slots in the live demos.
* @memberof Vaadin
Expand All @@ -122,37 +97,23 @@ <h5 part="error-message-title">[[i18n.errorMessage.title]]</h5>
* @mixes Vaadin.Login.LoginMixin
* @demo demo/index.html
*/
class LoginElement extends Vaadin.Login.LoginMixin(Vaadin.ElementMixin(Vaadin.ThemableMixin(Polymer.Element))) {
class LoginFormWrapperElement extends Vaadin.Login.LoginMixin(Vaadin.ElementMixin(Vaadin.ThemableMixin(Polymer.Element))) {
static get is() {
return 'vaadin-login';
}
static get version() {
return '1.0.0-alpha8';
return 'vaadin-login-form-wrapper';
}

_forgotPassword() {
this.dispatchEvent(new CustomEvent('forgot-password'));
}

static get observers() {
return [
'_errorChanged(error)'
];
}

_errorChanged() {
if (this.error && !this._preventAutoEnable) {
this.disabled = false;
}
}
}

customElements.define(LoginElement.is, LoginElement);
customElements.define(LoginFormWrapperElement.is, LoginFormWrapperElement);

/**
* @namespace Vaadin
*/
window.Vaadin.LoginElement = LoginElement;
window.Vaadin.LoginFormWrapperElement = LoginFormWrapperElement;
})();
</script>
</dom-module>

0 comments on commit 6cd2413

Please sign in to comment.