This repository was archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha11y-collapse.html
More file actions
317 lines (304 loc) · 11 KB
/
a11y-collapse.html
File metadata and controls
317 lines (304 loc) · 11 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../hax-body-behaviors/hax-body-behaviors.html">
<link rel="import" href="../schema-behaviors/schema-behaviors.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html" />
<link rel="import" href="a11y-collapse-accordion-button.html"/>
<link rel="import" href="a11y-collapse-icon-button.html"/>
<!--
`a11y-collapse`
An accessible expand collapse.
@demo demo/index.html
@microcopy - the mental model for this element
<a11y-collapse
accordion
disabled
icon="" //The expand/collapse icon. Default is "icons:expand-more"
icon-expanded="" //The expand/collapse icon when expanded. Default is the same as when collapsed.
label="" //The expand/collapse label. Default is "expand/collapse"
label-expanded="" //The expand/collapse label when expanded. Default is the same as when collapsed.
tooltip="" //The expand/collapse tooltip. Default is "toggle expand/collapse"
tooltip-expanded="" //The expand/collapse tooltip when expanded. Default is the same as when collapsed.
<p slot="heading">...</p> //Named slot for a heading.
... //Unnamed slot for a collapsible content.
</a11y-collapse>
CSS Variables:
--a11y-collapse-horizontal-padding //sets the horizontal padding (left and right) inside the a11y-collapse
--a11y-collapse-vertical-padding //sets the horizontal padding (top and bottom) inside the a11y-collapse
--a11y-collapse-border //sets the border style. Default is 0px solid black
CSS Mixins:
--a11y-collapse: { ... }; //sets CSS for the a11y-collapse container
--a11y-collapse-disabled: { ... }; //sets CSS for the a11y-collapse container when disabled
--a11y-collapse-expanded: { ... }; //sets CSS for the a11y-collapse container when expanded
--a11y-collapse-heading: { ... }; //sets CSS for the a11y-collapse heading
--a11y-collapse-heading-expanded: { ... }; //sets CSS for the a11y-collapse heading when expanded
--a11y-collapse-heading-focus: { ... }; //sets CSS for the a11y-collapse heading when focused or hovered
--a11y-collapse-heading-text: { ... }; //sets CSS for the a11y-collapse heading text
--a11y-collapse-heading-text-expanded: { ... }; //sets CSS for the a11y-collapse heading text when expanded
--a11y-collapse-heading-text-focus: { ... }; //sets CSS for the a11y-collapse heading text when heading is focused or hovered
--a11y-collapse-icon: { ... }; //sets CSS for the a11y-collapse icon
--a11y-collapse-icon-expanded: { ... }; //sets CSS for the a11y-collapse icon when expanded
--a11y-collapse-icon-focus: { ... }; //sets CSS for the a11y-collapse icon when button is focused or hovered
--a11y-collapse-icon-rotated: { ... }; //sets CSS for the a11y-collapse icon when rotated
--a11y-collapse-content: { ... }; //sets CSS for the a11y-collapse expanded/collapsed content
--a11y-collapse-content-expanded: { ... }; //sets CSS for the a11y-collapse expanded/collapsed content when expanded
-->
<dom-module id="a11y-collapse">
<template>
<style>
:host {
display: block;
border: var(--a11y-collapse-border, 1px solid);
margin: 15px 0;
transition: all 0.5s;
@apply --a11y-collapse;
}
:host #content {
max-height: 0;
overflow: hidden;
padding: 0em var(--a11y-collapse-horizontal-padding, 1em);
border-top: 0px solid rgba(255,255,255,0);
transition: all 0.5s ease-in-out;
@apply --a11y-collapse-content;
}
:host[disabled] {
opacity: 0.5;
@apply --a11y-collapse-disabled;
}
:host[disabled]:not([accordion]) #expand,
:host[disabled][accordion] #heading {
cursor: not-allowed;
}
:host[expanded] {
@apply --a11y-collapse-expanded;
}
:host[expanded] #content {
max-height: unset;
overflow: visibility: hidden;;
padding: var(--a11y-collapse-vertical-padding, 1em) var(--a11y-collapse-horizontal-padding, 1em);
border-top: var(--a11y-collapse-border, 0px solid);
@apply --a11y-collapse-content-expanded;
}
:host:not([expanded]) #content-inner {
overflow: hidden;
}
</style>
<template is="dom-if" if="[[!accordion]]">
<a11y-collapse-icon-button id="iconbutton"
disabled$="[[disabled]]"
expanded$="[[_setAriaExpanded(expanded)]]"
label$="[[_getExpandCollapse(expanded,label,labelExpanded)]]"
icon$="[[_getExpandCollapse(expanded,icon,iconExpanded)]]"
rotated$="[[__rotateIcon]]"
tooltip$="[[_getExpandCollapse(expanded,tooltip,tooltipExpanded)]]">
<slot name="heading"></slot>
</a11y-collapse-icon-button>
</template>
<template is="dom-if" if="[[accordion]]">
<a11y-collapse-accordion-button id="accordionbutton"
disabled$="[[disabled]]"
expanded$="[[_setAriaExpanded(expanded)]]"
label$="[[_getExpandCollapse(expanded,label,labelExpanded)]]"
icon$="[[_getExpandCollapse(expanded,icon,iconExpanded)]]"
rotated$="[[__rotateIcon]]"
tooltip$="[[_getExpandCollapse(expanded,tooltip,tooltipExpanded)]]">
<slot name="heading"></slot>
</a11y-collapse-accordion-button>
</template>
<div id="content" aria-hidden$="{{!expanded}}" aria-labelledby="heading" aria-live="polite">
<div id="content-inner"><slot></slot></div>
</div>
</template>
<script>
Polymer({
is: 'a11y-collapse',
behaviors: [HAXBehaviors.PropertiesBehaviors, SchemaBehaviors.Schema],
listeners: { 'a11y-collapse-tap': '_onTap' },
properties: {
/**
* accordion-style: whole header acts as button? default is just icon.
*/
accordion: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* is disabled?
*/
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* icon when expanded
*/
expanded: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* icon for the button
*/
icon: {
type: String,
value: 'icons:expand-more'
},
/**
* icon when expanded
*/
iconExpanded: {
type: String,
value: null
},
/**
* label for the button
*/
label: {
type: String,
value: 'expand/collapse'
},
/**
* optional label for the button when expanded
*/
labelExpanded: {
type: String,
value: null
},
/**
* tooltip for the button
*/
tooltip: {
type: String,
value: 'toggle expand/collapse'
},
/**
* optional tooltip for the button when expanded
*/
tooltipExpanded: {
type: String,
value: null
},
/**
* If no expanded icon is set, the default icon will rotate when expanded
*/
__rotateIcon: {
type: Boolean,
computed: '_isRotated(expanded,iconExpanded)'
},
},
/**
* Attached to the DOM, now fire.
*/
attached: function() {
this.fire('a11y-collapse-attached',this);
// Establish hax property binding
let props = {
'canScale': false,
'canPosition': true,
'canEditSource': false,
'gizmo': {
'title': 'Single Expand Collapse',
'description': 'A single instance of an expand collapse.',
'icon': 'view-day',
'color': 'grey',
'groups': ['Text'],
'meta': {
'author': 'Your organization on github'
}
},
'settings': {
'quick': [
],
'configure': [
{
'property': 'expanded',
'title': 'Expanded',
'description': 'Expand by default',
'inputMethod': 'boolean',
},
{
'property': 'label',
'title': 'Label',
'description': 'The label of the toggle expand/collapse button',
'inputMethod': 'textfield',
'icon': 'editor:title',
},
{
'property': 'tooltip',
'title': 'Tooltip',
'description': 'The tooltip for the toggle expand/collapse button',
'inputMethod': 'textfield',
'icon': 'editor:title',
},
{
'property': 'icon',
'title': 'Icon',
'description': 'The icon for the toggle expand/collapse button',
'inputMethod': 'textfield',
'icon': 'editor:title',
},
{
'property': 'iconExpanded',
'title': 'Expanded Icon',
'description': 'Optional: The icon for the toggle expand/collapse button when expanded',
'inputMethod': 'textfield',
'icon': 'editor:title',
},
],
'advanced': [
]
}
};
this.setHaxProperties(props);
},
/**
* Let the group know that this is gone.
*/
detached: function() {
this.fire('a11y-collapse-detached',this);
},
/**
* Toggles based on mode
*/
toggle: function(mode) {
this.expanded = mode !== undefined ? mode : !this.expanded;
this.fire('a11y-collapse-toggle',this);
},
/**
* If no expanded value is set, the default will be same as collapsed
*/
_overrideProp: function(prop,val) {
this[prop] = val;
},
/**
* If no expanded value is set, the default will be same as collapsed
*/
_getExpandCollapse: function(expanded,ifFalse,ifTrue) {
return expanded && ifTrue !== null ? ifTrue : ifFalse;
},
/**
* If no expanded icon is set, the default icon will rotate when expanded
*/
_isRotated: function(expanded,iconExpanded) {
return !expanded && iconExpanded === null;
},
/**
* Handle tap
*/
_onTap: function(e) {
if(!this.disabled) {
this.toggle();
this.fire('a11y-collapse-click',this);
}
},
/**
* Attached to the DOM, now fire.
*/
_setAriaExpanded: function(expanded) {
return ''+expanded;
}
});
</script>
</dom-module>