-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathetools-content-panel.js
197 lines (178 loc) · 5.4 KB
/
etools-content-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
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
import {LitElement, html} from 'lit-element';
import '@polymer/iron-icons/iron-icons.js';
import '@polymer/iron-collapse/iron-collapse.js';
import '@polymer/paper-icon-button/paper-icon-button.js';
import {elevationStyles} from './styles/elevation-styles';
/**
* `etools-content-panel`
* A simple panel with header to display a collapsible content.
*
* ### Styling
*
* You can use defined variables and css shadow parts to change panel style.
*
* Custom property | Description | Default
* ----------------|-------------|----------
* `--ecp-header-height` | Header height | `48px`
* `--ecp-header-bg` | Header background color | `#0099ff`
* `--ecp-header-color` | Header color | `#ffffff`
* `etools-content-panel::part(ecp-header)` | CSS Shadow Part applied to header | `{}`
* `etools-content-panel::part(ecp-toggle-btn)` | CSS Shadow Part applied to expand content button | `{}`
* `etools-content-panel::part(ecp-header-title)` | CSS Shadow Part applied to the header title | `{}`
* `etools-content-panel::part(ecp-header-btns-wrapper)`
* | CSS Shadow Part appplied to panel header right btns container
* | `{}`
* `etools-content-panel::part(ecp-content)` | CSS Shadow Part applied to content | `{}`
* `--ecp-content-bg-color` | Content Header color | `#ffffff`
* `etools-content-panel::part(ecp-header):disabled` | CSS Shadow Part applied in disabled state | `{}`
* `--ecp-content-padding` | CSS Shadow Part applied to content | `8px 24px 16px 24px`
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class EtoolsContentPanel extends LitElement {
static get styles() {
return [elevationStyles];
}
render() {
// language=HTML
return html`
<style>
:host {
display: block;
position: var(--ecp-host-position, relative);
}
*[hidden] {
display: none !important;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
box-sizing: border-box;
background-color: var(--ecp-header-bg, #0099ff);
height: var(--ecp-header-height, 48px);
padding: 4px 16px;
}
:host(:not([show-expand-btn])) .panel-header {
padding: 4px 0px;
padding-inline: 24px 16px;
}
h2.title,
.toggle-btn,
.panel-btns-wrapper ::slotted(*) {
color: var(--ecp-header-color, #ffffff);
}
.toggle-btn,
.panel-btns-wrapper ::slotted(*) {
opacity: 0.8;
}
h2.title {
margin: auto;
font-size: 21px;
font-weight: bold;
min-width: 0;
flex: 1;
}
h2.title span {
white-space: var(--ecp-title-white-space, nowrap);
overflow: hidden;
text-overflow: ellipsis;
display: block;
}
.content-wrapper {
background-color: var(--ecp-content-bg-color, #ffffff);
box-sizing: border-box;
padding: var(--ecp-content-padding, 8px 24px 16px 24px);
}
:host([disabled]) .panel-header,
:host([disabled]) ::slotted(*) {
opacity: 0.5;
@apply --ecp-disabled;
}
.panel-header .flex-h {
display: flex;
max-width: 100%;
}
:host-context([dir='rtl']) [icon='chevron-right'] {
transform: rotate(180deg);
}
</style>
<div class="elevation" elevation="${this.elevation}">
<div class="panel-header" part="ecp-header" ?hidden="${this.noHeader}">
<div class="flex-h">
<paper-icon-button
class="toggle-btn"
part="ecp-toggle-btn"
@click="${this._toggle}"
icon="${this._getExpandBtnIcon(this.open)}"
?hidden="${!this.showExpandBtn}"
?disabled="${this.disabled}"
></paper-icon-button>
<h2 class="title" part="ecp-header-title">
<span>${this.panelTitle}</span>
</h2>
<slot name="after-title"></slot>
</div>
<div class="panel-btns-wrapper" part="ecp-header-btns-wrapper">
<slot name="panel-btns"></slot>
</div>
</div>
<iron-collapse ?opened="${this.open}">
<div class="content-wrapper" part="ecp-content">
<slot></slot>
</div>
</iron-collapse>
</div>
`;
}
static get is() {
return 'etools-content-panel';
}
static get properties() {
return {
panelTitle: {
type: String,
reflect: true,
attribute: 'panel-title'
},
elevation: {
type: Number
},
open: {
type: Boolean
},
noHeader: {
type: Boolean,
reflect: true,
attribute: 'no-header'
},
disabled: {
type: Boolean
},
showExpandBtn: {
type: Boolean,
reflect: true,
attribute: 'show-expand-btn'
}
};
}
constructor() {
super();
this.panelTitle = 'Panel Title';
this.elevation = 1;
this.open = true;
this.noHeader = false;
this.disabled = false;
this.showExpandBtn = false;
}
_toggle() {
this.open = !this.open;
}
_getExpandBtnIcon(open) {
return open ? 'expand-more' : 'chevron-right';
}
}
window.customElements.define(EtoolsContentPanel.is, EtoolsContentPanel);