-
Notifications
You must be signed in to change notification settings - Fork 1
/
cosmoz-form-dialog.js
62 lines (52 loc) · 1.22 KB
/
cosmoz-form-dialog.js
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
import '@polymer/iron-form';
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';
import { dialogOpener } from './cosmoz-dialog-mixin';
/**
* `<cosmoz-form-dialog>`
* @demo demo/form-dialog.html Dialog Demo
* @appliesMixin dialogOpener
*/
class CosmozFormDialog extends dialogOpener(PolymerElement) {
static get is() {
return 'cosmoz-form-dialog';
}
constructor() {
super();
this._form = null;
this._spawnSteps.push(this._createForm);
}
static get template() {
return html`
<template>
<div hidden>
<slot></slot>
</div>
</template>
`;
}
get form() {
return this._form;
}
_detachDialog() {
if (this._form != null && this._form.parentNode) {
this._form.parentNode.removeChild(this._form);
}
}
_attachDialog() {
if (!this._form.parentNode) {
document.body.appendChild(this._form);
}
}
_createForm() {
if (!this._paperDialog) {
return;
}
const ironForm = document.createElement('iron-form'),
form = document.createElement('form');
ironForm.appendChild(form);
form.appendChild(this._paperDialog);
this._form = ironForm;
}
}
customElements.define(CosmozFormDialog.is, CosmozFormDialog);