forked from ReadingPlus/paper-expansion-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper-expansion-panel.js
155 lines (130 loc) · 3.95 KB
/
paper-expansion-panel.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
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
/**
A Material Design [expansion panel with header and collapsible content](https://material.google.com/components/expansion-panels.html)
### Example
```html
<paper-expansion-panel header="Panel" summary="With event" on-toggle="onToggle">
Lots of very interesting content.
</paper-expansion-panel>
```
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
--paper-expansion-panel-header|Mixin applied to the header of the panel|{}
--paper-expansion-panel-summary|Mixin applied to the summary of the panel|{}
--paper-expansion-panel-content|Mixin applied to collapsible content|{}
@demo demo/index.html
*/
/*
FIXME(polymer-modulizer): the above comments were extracted
from HTML and may be out of place here. Review them and
then delete this comment!
*/
import '@polymer/iron-icons/iron-icons.js';
import '@polymer/iron-collapse/iron-collapse.js';
import '@polymer/paper-icon-button/paper-icon-button.js';
import '@polymer/paper-item/paper-item.js';
import '@polymer/paper-styles/paper-styles.js';
import '@polymer/iron-flex-layout/iron-flex-layout.js';
import '@polymer/polymer/polymer-legacy.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
class PaperExpansionPanel extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
.header {
min-height: 48px;
color: var(--primary-text-color);
@apply --layout-center;
@apply --layout-justified;
@apply --paper-font-subhead;
@apply --paper-expansion-panel-header;
--paper-item-focused-before: {
background: inherit;
}
}
.toggle {
color: var(--disabled-text-color);
}
.content {
@apply --paper-font-body1;
@apply --paper-expansion-panel-content;
}
.summary {
@apply --paper-expansion-panel-summary;
color: var(--secondary-text-color);
}
.flex {
@apply --layout-flex;
}
</style>
<paper-item class="header" on-tap="_toggleOpened">
<template is="dom-if" if="[[header]]">
<div class="flex">[[header]]</div>
<template is="dom-if" if="[[summary]]">
<div hidden$="[[opened]]" class="flex summary">[[summary]]</div>
</template>
</template>
<template is="dom-if" if="[[!header]]">
<slot name="header"><div class="flex"> </div></slot>
</template>
<paper-icon-button class="toggle" icon="[[_toggleIcon]]"></paper-icon-button>
</paper-item>
<iron-collapse class="content" opened="{{opened}}" no-animation="[[noAnimation]]">
<slot></slot>
</iron-collapse>
`;
}
static get is() {
return 'paper-expansion-panel';
}
static get properties() {
return {
/**
* Text in the header row
*/
header: {
type: String,
value: '',
},
/**
* Summary of the expandible area
*/
summary: String,
/**
* True if the content section is opened
*/
opened: {
type: Boolean,
reflectToAttribute: true,
notify: true
},
noAnimation: {
type: Boolean,
value: false
},
_toggleIcon: {
type: String,
computed: '_computeToggleIcon(opened)'
}
}
}
// Private methods
/**
* Fired whenever the status is changed (opened/closed)
*
* @event toggle
*/
_toggleOpened(e) {
this.opened = !this.opened;
this.dispatchEvent(new Event('toggle'));
}
_computeToggleIcon(opened) {
return opened ? 'icons:expand-less' : 'icons:expand-more';
}
}
customElements.define(PaperExpansionPanel.is, PaperExpansionPanel);