-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxenon-modal.html
141 lines (107 loc) · 2.84 KB
/
xenon-modal.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-overlay-behavior/iron-overlay-behavior.html">
<!--
`xenon-modal`
Modal polymer element
@demo demo/index.html
-->
<dom-module id="xenon-modal">
<template>
<style>
:host {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
}
.modal__icon {
position: absolute;;
top: var(--close-icon-top, 0);
right: var(--close-icon-bottom, 0);
cursor: pointer;
}
.modal__content {
position: relative;
background-color: var(--content-bgcolor, white);
padding: var(--content-padding, 1rem);
}
</style>
<div class="modal">
<div class="modal__content">
<iron-icon class="modal__icon" on-tap="close" icon="[[closeIcon]]"></iron-icon>
<content></content>
</div>
</div>
</template>
<script>
Polymer({
is: 'xenon-modal',
properties: {
withBackdrop: {
type: Boolean,
value: true
},
closeIcon: {
type: String,
value: 'close'
},
opened: {
type: Boolean,
value: false
}
},
behaviors: [
Polymer.IronOverlayBehavior
],
listeners: {
'iron-overlay-closed': '_onClose'
},
// ------- Public methods -------
showElement: function(elName, properties) {
this._el = document.createElement(elName);
// If element properties are defined, we set them
if (properties) {
this._setElementProperties(properties);
}
// Set xenon-modal as property to instanced element
this._el.set('modal', this);
// If a previous element is displayed, we remove it
if (this.get('opened')) {
this.removeElement();
}
Polymer.dom(this).appendChild(this._el);
this.open();
this.set('opened', true);
},
getElement: function() {
return this._el;
},
isOpened: function() {
return this.get('opened');
},
getElementProperty: function(property) {
return this._el.get(property);
},
// ------- Private methods -------
_setElementProperties: function(properties) {
var self = this;
Object.keys(properties).forEach(function(key) {
self._el.set(key, properties[key]);
});
},
_onClose: function(evt) {
this._removeElement();
this._el = null;
this.set('opened', false);
},
_removeElement() {
Polymer.dom(this).removeChild(this._el);
}
});
</script>
</dom-module>