This repository was archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlrnsys-dialog.html
More file actions
266 lines (262 loc) · 8.16 KB
/
Copy pathlrnsys-dialog.html
File metadata and controls
266 lines (262 loc) · 8.16 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="../paper-avatar/paper-avatar.html">
<link rel="import" href="../lrn-icons/lrn-icons.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../neon-animation/web-animations.html">
<link rel="import" href="../neon-animation/neon-animations.html">
<link rel="import" href="../simple-colors/simple-colors.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="lrnsys-dialog-modal.html">
<link rel="import" href="lrnsys-button-inner.html">
<!--
`lrnsys-dialog`
@demo demo/index.html
-->
<dom-module id="lrnsys-dialog">
<template>
<style is="custom-style" include="simple-colors">
:host {
display: inline-block;
--lrnsys-dialog-color: var(--simple-colors-foreground1,#000);
--lrnsys-dialog-background-color: var(--simple-colors-background1);
--lrnsys-dialog-toolbar-background-color: var(--simple-colors-background3);
--lrnsys-dialog-secondary-background-color: rgba(255,255,255, 0.7);
}
:host[dark] {
--lrnsys-dialog-toolbar-background-color: var(--simple-colors-background1);
--lrnsys-dialog-background-color: var(--simple-colors-background3);
--lrnsys-dialog-secondary-background-color: rgba(0, 0, 0, 0.7);
}
</style>
<paper-button class$="[[class]]" id="dialogtrigger" on-tap="toggleDialog" raised="[[raised]]" disabled$="[[disabled]]" title="[[alt]]" aria-label$="[[alt]]">
<lrnsys-button-inner avatar$="[[avatar]]" icon$="[[icon]]" text$="[[text]]">
<slot name="button"></slot>
</lrnsys-button-inner>
</paper-button>
<paper-tooltip for="dialogtrigger" animation-delay="0" hidden$="[[!alt]]">[[alt]]</paper-tooltip>
<lrnsys-dialog-modal id="modal" dynamic-images="[[dynamicImages]]" body-append="[[bodyAppend]]" header="[[header]]" modal="[[modal]]" heading-class="[[headingClass]]" opened$="[[opened]]">
<slot name="toolbar-primary" slot="primary"></slot>
<slot name="toolbar-secondary" slot="secondary"></slot>
<slot name="header" slot="header"></slot>
<slot></slot>
</lrnsys-dialog-modal>
</template>
<script>
Polymer({
is: 'lrnsys-dialog',
listeners: {
'mousedown': 'tapEventOn',
'mouseover': 'tapEventOn',
'mouseout': 'tapEventOff',
'dialogtrigger.focused-changed': 'focusToggle',
},
behaviors: [ simpleColorsBehaviors ],
properties: {
/**
* Icon to present for clicking.
*/
icon: {
type: String
},
/**
* If the button should be visually lifted off the UI.
*/
raised: {
type: Boolean,
},
/**
* Icon to present for clicking.
*/
avatar: {
type: String
},
/**
* Text to present for clicking.
*/
text: {
type: String
},
/**
* Alt / hover text for this link
*/
alt: {
type: String,
reflectToAttribute: true,
},
/**
* Header for the dialog
*/
header: {
type: String
},
/**
* Disabled state.
*/
disabled: {
type: Boolean,
value: false,
},
/**
* Modal state for pop over.
*/
modal: {
type: Boolean,
value: false,
},
/**
* Is dialog opened?
*/
opened: {
type: Boolean,
value: false,
reflectToAttribute: true,
notify: true,
},
/**
* Classes to add / subtract based on the item being hovered
*/
hoverClass: {
type: String,
},
/**
* Default heading classes.
*/
headingClass: {
type: String,
value: 'white-text black',
},
/**
* Support for body-appending which is a hack for stacking context
* correction but breaks scoped styles / shadowDOM
*/
bodyAppend: {
type: Boolean,
value: true,
},
/**
* Support for dynamic loading of iron-image elements that are in the content slot.
*/
dynamicImages: {
type: Boolean,
value: false
},
/**
* Tracks if focus state is applied
*/
focusState: {
type: Boolean,
value: false,
},
/**
* Ability to disable the auto focus mode
* this is useful if something else is picking up this capability.
*/
disableAutoFocus: {
type: Boolean,
value: false,
},
},
/**
* Handle a focus/tap event and add the hoverclasses
* to the classList array for paper-button.
*/
tapEventOn: function (e) {
const root = this;
if (typeof root.hoverClass !== typeof undefined) {
var classes = root.hoverClass.split(' ');
classes.forEach(function (item, index) {
if (item != '') {
root.$.dialogtrigger.classList.add(item);
}
});
}
},
/**
* Handle a mouse out event and remove the hoverclasses
* from the classList array for paper-button.
*/
tapEventOff: function (e) {
const root = this;
if (typeof root.hoverClass !== typeof undefined) {
var classes = root.hoverClass.split(' ');
classes.forEach(function (item, index) {
if (item != '') {
root.$.dialogtrigger.classList.remove(item);
}
});
}
},
/**
* Toggle the drawer to open / close.
*/
toggleDialog: function () {
this.$.modal.toggleDialog();
},
/**
* Handle toggle for mouse class and manage classList array for paper-button.
*/
focusToggle: function (e) {
const root = this;
root.fire('focus-changed', { focus: root.focusState });
// see if it has hover classes
if (typeof root.hoverClass !== typeof undefined) {
// break class into array
var classes = root.hoverClass.split(' ');
// run through each and add or remove classes
classes.forEach(function (item, index) {
if (item != '') {
if (root.focusState) {
root.$.dialogtrigger.classList.add(item);
}
else {
root.$.dialogtrigger.classList.remove(item);
}
}
});
}
root.focusState = !root.focusState;
},
/**
* Ready lifecycle
*/
ready: function() {
this.__modal = this.$.modal;
},
/**
* Attached lifecycle
*/
attached: function() {
document.body.addEventListener('lrnsys-dialog-modal-changed', this._changeOpen.bind(this));
if (!this.disableAutoFocus) {
document.body.addEventListener('lrnsys-dialog-modal-closed', this._accessibleFocus.bind(this));
}
},
/**
* Set ourselves as having focus after the modal closes.
*/
_accessibleFocus: function(e) {
// this is OUR modal, we found her, oh modal, We've missed
// you so much. thank you for coming home. We're so, so, so
// sorry that we appended you to the body. We'll never do it
// again (until the next time you open).
if (e.detail === this.__modal) {
// focus on our dialog triggering button
this.$.dialogtrigger.focus();
}
},
/**
* Attached lifecyce
*/
_changeOpen: function(e) {
e.stopPropagation();
if (e.detail === this.$.modal) {
this.opened = e.type === 'iron-overlay-opened';
this.fire('lrnsys-dialog-changed', this);
}
},
});
</script>
</dom-module>