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-drawer.html
More file actions
239 lines (235 loc) · 6.89 KB
/
Copy pathlrnsys-drawer.html
File metadata and controls
239 lines (235 loc) · 6.89 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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-layout/app-layout.html">
<link rel="import" href="../paper-avatar/paper-avatar.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../simple-colors/simple-colors.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="lrnsys-button-inner.html">
<link rel="import" href="lrnsys-drawer-modal.html">
<!--
`lrnsys-drawer`
@demo demo/index.html
-->
<dom-module id="lrnsys-drawer">
<template>
<style is="custom-style" include="simple-colors">
:host {
display: block;
--lrnsys-drawer-color: var(--simple-colors-foreground1);
--lrnsys-drawer-background-color: var(--simple-colors-background1);
}
lrnsys-drawer-modal {
--lrnsys-drawer-width: 30%;
}
</style>
<paper-button class$="[[class]]" id="flyouttrigger" on-tap="toggleDrawer" raised="[[raised]]" disabled$="[[disabled]]" title="[[alt]]">
<lrnsys-button-inner avatar="[[avatar]]" icon="[[icon]]" text="[[text]]">
<slot name="button"></slot>
</lrnsys-button-inner>
</paper-button>
<paper-tooltip for="flyouttrigger" animation-delay="0">[[alt]]</paper-tooltip>
<lrnsys-drawer-modal id="modal" body-append="[[bodyAppend]]" opened="[[opened]]" align="[[align]]" header="[[header]]" heading-class="[[headingClass]]">
<slot name="header" slot="header"></slot>
<slot></slot>
</lrnsys-drawer-modal>
</template>
<script>
Polymer({
is: 'lrnsys-drawer',
listeners: {
'mousedown': 'tapEventOn',
'mouseover': 'tapEventOn',
'mouseout': 'tapEventOff',
'flyouttrigger.focused-changed': 'focusToggle',
},
behaviors: [ simpleColorsBehaviors ],
properties: {
/**
* State for if it is currently open.
*/
opened: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
/**
* If the button should be visually lifted off the UI.
*/
raised: {
type: Boolean,
reflectToAttribute: true,
},
/**
* Icon to present for clicking.
*/
icon: {
type: String,
},
/**
* Icon to present for clicking.
*/
avatar: {
type: String,
},
/**
* Text to present for clicking.
*/
text: {
type: String,
},
/**
* Side of the screen to align the flyout (right or left)
*/
align: {
type: String,
value: 'left',
},
/**
* Alt / hover text for this link
*/
alt: {
type: String,
reflectToAttribute: true,
},
/**
* Header for the drawer
*/
header: {
type: String,
},
/**
* Disabled state.
*/
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
/**
* Classes to add / subtract based on the item being hovered
*/
hoverClass: {
type: String,
},
/**
* Heading classes to apply downstream.
*/
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,
},
/**
* Tracks if focus state is applied
*/
focusState: {
type: Boolean,
value: false,
}
},
/**
* Ready lifecycle
*/
ready: function() {
this.__modal = this.$.modal;
},
/**
* Attached lifecycle
*/
attached: function() {
document.body.addEventListener('lrnsys-drawer-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 flyout triggering button
this.$.flyouttrigger.focus();
}
},
/**
* Handle a mouse on 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.$.flyouttrigger.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.$.flyouttrigger.classList.remove(item);
}
});
}
},
/**
* Toggle the drawer to open / close.
*/
toggleDrawer: function() {
this.$.modal.open();
},
/**
* 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.$.flyouttrigger.classList.add(item);
}
else {
root.$.flyouttrigger.classList.remove(item);
}
}
});
}
root.focusState = !root.focusState;
},
/**
* Find out if the text does not have an avatar or an icon to the left,
* and add a class to remove the left margin.
*/
_getTextLabelClass: function() {
if(!this.avatar && !this.icon){
return 'text-label-only';
}
return 'text-label';
},
});
</script>
</dom-module>