easy-component-ui 0.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Base.js +90 -0
- package/components/ea-alert/index.js +298 -0
- package/components/ea-avatar/index.js +277 -0
- package/components/ea-backtop/index.js +232 -0
- package/components/ea-badge/index.js +160 -0
- package/components/ea-button/index.js +584 -0
- package/components/ea-button-group/index.js +459 -0
- package/components/ea-calendar/index.js +409 -0
- package/components/ea-card/index.js +77 -0
- package/components/ea-carousel/index.js +434 -0
- package/components/ea-checkbox/index.js +314 -0
- package/components/ea-checkbox-group/index.js +107 -0
- package/components/ea-collapse/index.js +293 -0
- package/components/ea-descriptions/index.js +240 -0
- package/components/ea-descriptions-item/index.js +110 -0
- package/components/ea-empty/index.js +141 -0
- package/{icon → components/ea-icon}/config.json +1017 -1017
- package/{icon → components/ea-icon}/css/animation.css +85 -85
- package/{icon → components/ea-icon}/css/fontello.css +224 -224
- package/components/ea-icon/font/fontello.svg +683 -0
- package/components/ea-icon/index.css +2 -0
- package/components/ea-icon/index.js +47 -0
- package/components/ea-image/index.js +412 -0
- package/components/ea-infinite-scroll/index.js +170 -0
- package/components/ea-input/index.js +765 -0
- package/components/ea-input-number/index.js +458 -0
- package/components/ea-link/index.js +200 -0
- package/components/ea-loading/index.js +218 -0
- package/components/ea-message/MessageClass.js +71 -0
- package/components/ea-message/index.js +233 -0
- package/components/ea-message-box/EaMessageBoxClass.js +48 -0
- package/components/ea-message-box/index.js +202 -0
- package/components/ea-pagination/index.js +444 -0
- package/components/ea-progress/index.js +333 -0
- package/components/ea-radio/index.js +287 -0
- package/components/ea-radio-group/index.js +59 -0
- package/components/ea-rate/index.js +326 -0
- package/components/ea-result/index.js +167 -0
- package/components/ea-select/index.js +34 -0
- package/components/ea-skeleton/index.js +341 -0
- package/components/ea-switch/index.js +301 -0
- package/components/ea-tag/index.js +212 -0
- package/components/ea-textarea/index.js +333 -0
- package/components/ea-timeline/index.js +334 -0
- package/components/ea-ui-base-style.css +0 -0
- package/package.json +1 -1
- package/utils/createElement.js +30 -0
- package/utils/handleTemplate.js +19 -0
- package/utils/setStyle.js +8 -0
- package/icon/font/fontello.svg +0 -346
- package/icon/index.css +0 -2
- package/index.js +0 -1693
- /package/{icon → components/ea-icon}/css/fontello-codes.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-embedded.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-ie7-codes.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-ie7.css +0 -0
- /package/{icon → components/ea-icon}/font/fontello.eot +0 -0
- /package/{icon → components/ea-icon}/font/fontello.ttf +0 -0
- /package/{icon → components/ea-icon}/font/fontello.woff +0 -0
- /package/{icon → components/ea-icon}/font/fontello.woff2 +0 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js'
|
|
3
|
+
|
|
4
|
+
const stylesheet = `:host {
|
|
5
|
+
--margin-right: 1rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.ea-checkbox_wrap {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-right: var(--margin-right);
|
|
12
|
+
}
|
|
13
|
+
.ea-checkbox_wrap .__ea-checkbox-input_wrap {
|
|
14
|
+
margin-right: 0.5rem;
|
|
15
|
+
}
|
|
16
|
+
.ea-checkbox_wrap .__ea-checkbox-input_wrap .__ea-checkbox-input_inner {
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
position: relative;
|
|
19
|
+
display: block;
|
|
20
|
+
width: 0.8125rem;
|
|
21
|
+
height: 0.8125rem;
|
|
22
|
+
line-height: 0.8125;
|
|
23
|
+
border-radius: 3px;
|
|
24
|
+
border: 1px solid #ccc;
|
|
25
|
+
transition: background-color 0.2s, border-color 0.2s;
|
|
26
|
+
}
|
|
27
|
+
.ea-checkbox_wrap .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::after {
|
|
28
|
+
content: "";
|
|
29
|
+
position: absolute;
|
|
30
|
+
left: 52.5%;
|
|
31
|
+
top: 45%;
|
|
32
|
+
transform: translate(-50%, -50%) rotate(-135deg);
|
|
33
|
+
display: block;
|
|
34
|
+
width: 3px;
|
|
35
|
+
height: 7px;
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transition: opacity 0.2s;
|
|
38
|
+
}
|
|
39
|
+
.ea-checkbox_wrap .__ea-checkbox-input_wrap .__ea-checkbox-input_input {
|
|
40
|
+
display: none;
|
|
41
|
+
}
|
|
42
|
+
.ea-checkbox_wrap .__ea-checkbox-label_desc {
|
|
43
|
+
transition: color 0.2s;
|
|
44
|
+
}
|
|
45
|
+
.ea-checkbox_wrap.checked .__ea-checkbox-input_wrap .__ea-checkbox-input_inner {
|
|
46
|
+
border-color: #409eff;
|
|
47
|
+
background-color: #409eff;
|
|
48
|
+
}
|
|
49
|
+
.ea-checkbox_wrap.checked .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::after {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
border-left: 2px solid white;
|
|
52
|
+
border-top: 2px solid white;
|
|
53
|
+
}
|
|
54
|
+
.ea-checkbox_wrap.checked .__ea-checkbox-label_desc {
|
|
55
|
+
color: #409eff;
|
|
56
|
+
}
|
|
57
|
+
.ea-checkbox_wrap.disabled .__ea-checkbox-input_wrap .__ea-checkbox-input_inner {
|
|
58
|
+
border-color: #eeeeee;
|
|
59
|
+
background-color: #eeeeee;
|
|
60
|
+
}
|
|
61
|
+
.ea-checkbox_wrap.disabled .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::before {
|
|
62
|
+
background-color: transparent;
|
|
63
|
+
}
|
|
64
|
+
.ea-checkbox_wrap.disabled .__ea-checkbox-label_desc {
|
|
65
|
+
color: #c0c4cc;
|
|
66
|
+
}
|
|
67
|
+
.ea-checkbox_wrap.disabled[checked=true] .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::before {
|
|
68
|
+
background-color: #c0c4cc;
|
|
69
|
+
}
|
|
70
|
+
.ea-checkbox_wrap.indeterminate .__ea-checkbox-input_wrap .__ea-checkbox-input_inner {
|
|
71
|
+
border-color: #409eff;
|
|
72
|
+
background-color: #409eff;
|
|
73
|
+
}
|
|
74
|
+
.ea-checkbox_wrap.indeterminate .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::after {
|
|
75
|
+
opacity: 1;
|
|
76
|
+
left: 50%;
|
|
77
|
+
top: 50%;
|
|
78
|
+
width: 80%;
|
|
79
|
+
height: 3px;
|
|
80
|
+
background-color: white;
|
|
81
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
82
|
+
}
|
|
83
|
+
.ea-checkbox_wrap.indeterminate .__ea-checkbox-label_desc {
|
|
84
|
+
color: #409eff;
|
|
85
|
+
}
|
|
86
|
+
.ea-checkbox_wrap.indeterminate[checked=true] .__ea-checkbox-input_wrap .__ea-checkbox-input_inner {
|
|
87
|
+
border-color: #409eff;
|
|
88
|
+
background-color: #409eff;
|
|
89
|
+
}
|
|
90
|
+
.ea-checkbox_wrap.indeterminate[checked=true] .__ea-checkbox-input_wrap .__ea-checkbox-input_inner::after {
|
|
91
|
+
width: 3px;
|
|
92
|
+
height: 7px;
|
|
93
|
+
left: 52.5%;
|
|
94
|
+
top: 45%;
|
|
95
|
+
transform: translate(-50%, -50%) rotate(-135deg);
|
|
96
|
+
opacity: 1;
|
|
97
|
+
border-left: 2px solid white;
|
|
98
|
+
border-top: 2px solid white;
|
|
99
|
+
background-color: transparent;
|
|
100
|
+
}
|
|
101
|
+
.ea-checkbox_wrap.indeterminate[checked=true] .__ea-checkbox-label_desc {
|
|
102
|
+
color: #409eff;
|
|
103
|
+
}`;
|
|
104
|
+
|
|
105
|
+
const inputDom = () => {
|
|
106
|
+
const wrap = document.createElement('span');
|
|
107
|
+
wrap.className = "__ea-checkbox-input_wrap";
|
|
108
|
+
|
|
109
|
+
const checkbox = document.createElement('span');
|
|
110
|
+
checkbox.className = "__ea-checkbox-input_inner";
|
|
111
|
+
wrap.appendChild(checkbox);
|
|
112
|
+
|
|
113
|
+
const input = document.createElement('input');
|
|
114
|
+
input.type = 'checkbox';
|
|
115
|
+
input.className = "__ea-checkbox-input_input";
|
|
116
|
+
|
|
117
|
+
wrap.appendChild(input);
|
|
118
|
+
|
|
119
|
+
return { wrap, input };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const labelDom = () => {
|
|
123
|
+
const labelDesc = document.createElement('span');
|
|
124
|
+
labelDesc.className = "__ea-checkbox-label_desc";
|
|
125
|
+
const slot = document.createElement('slot');
|
|
126
|
+
labelDesc.appendChild(slot);
|
|
127
|
+
|
|
128
|
+
return labelDesc;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export class EaCheckbox extends Base {
|
|
132
|
+
#checkbox;
|
|
133
|
+
#label;
|
|
134
|
+
|
|
135
|
+
static get observedAttributes() {
|
|
136
|
+
return ['checked', 'disabled'];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
constructor() {
|
|
140
|
+
super();
|
|
141
|
+
|
|
142
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
143
|
+
const that = this;
|
|
144
|
+
let dom = document.createElement('label');
|
|
145
|
+
dom.className = "ea-checkbox_wrap";
|
|
146
|
+
|
|
147
|
+
// input + checkbox
|
|
148
|
+
const input = inputDom();
|
|
149
|
+
dom.appendChild(input.wrap);
|
|
150
|
+
|
|
151
|
+
// label 标签文字
|
|
152
|
+
const label = labelDom();
|
|
153
|
+
dom.appendChild(label);
|
|
154
|
+
|
|
155
|
+
this.#label = dom;
|
|
156
|
+
this.#checkbox = input.input;
|
|
157
|
+
|
|
158
|
+
this.build(shadowRoot, stylesheet);
|
|
159
|
+
shadowRoot.appendChild(dom);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ------- checked 选中 -------
|
|
163
|
+
// #region
|
|
164
|
+
get checked() {
|
|
165
|
+
return this.getAttrBoolean('checked');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
set checked(val) {
|
|
169
|
+
this.#checkbox.checked = val;
|
|
170
|
+
|
|
171
|
+
if (val) {
|
|
172
|
+
this.setAttribute('checked', true);
|
|
173
|
+
this.#label.setAttribute('checked', true);
|
|
174
|
+
this.#label.classList.add('checked');
|
|
175
|
+
} else {
|
|
176
|
+
this.removeAttribute('checked');
|
|
177
|
+
this.#label.removeAttribute('checked');
|
|
178
|
+
this.#label.classList.remove('checked');
|
|
179
|
+
this.#label.classList.remove('indeterminate');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// #endregion
|
|
183
|
+
// ------- end -------
|
|
184
|
+
|
|
185
|
+
// ------- name 单选框的唯一键 -------
|
|
186
|
+
// #region
|
|
187
|
+
get name() {
|
|
188
|
+
return this.getAttribute('name');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
set name(val) {
|
|
192
|
+
this.#checkbox.setAttribute('name', val);
|
|
193
|
+
}
|
|
194
|
+
// #endregion
|
|
195
|
+
// ------- end -------
|
|
196
|
+
|
|
197
|
+
// ------- value 单选框的值 -------
|
|
198
|
+
// #region
|
|
199
|
+
get value() {
|
|
200
|
+
return this.getAttribute('value');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
set value(val) {
|
|
204
|
+
this.#label.setAttribute('for', val);
|
|
205
|
+
this.#checkbox.setAttribute('id', val);
|
|
206
|
+
this.#checkbox.setAttribute('value', val);
|
|
207
|
+
}
|
|
208
|
+
// #endregion
|
|
209
|
+
// ------- end -------
|
|
210
|
+
|
|
211
|
+
// ------- disabled 禁用状态 -------
|
|
212
|
+
// #region
|
|
213
|
+
get disabled() {
|
|
214
|
+
return this.getAttrBoolean('disabled');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
set disabled(val) {
|
|
218
|
+
this.#checkbox.disabled = val;
|
|
219
|
+
this.#label.toggleAttribute('disabled', val);
|
|
220
|
+
this.#label.classList.toggle('disabled', val);
|
|
221
|
+
}
|
|
222
|
+
// #endregion
|
|
223
|
+
// ------- end -------
|
|
224
|
+
|
|
225
|
+
// ------- border 是否带有边框 -------
|
|
226
|
+
// #region
|
|
227
|
+
get border() {
|
|
228
|
+
return this.getAttrBoolean('border');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
set border(val) {
|
|
232
|
+
this.#label.classList.toggle('border', val);
|
|
233
|
+
}
|
|
234
|
+
// #endregion
|
|
235
|
+
// ------- end -------
|
|
236
|
+
|
|
237
|
+
// ------- indeterminate 状态 -------
|
|
238
|
+
// #region
|
|
239
|
+
get indeterminate() {
|
|
240
|
+
return this.getAttrBoolean('indeterminate');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
set indeterminate(val) {
|
|
244
|
+
if (val) {
|
|
245
|
+
this.checked = false;
|
|
246
|
+
this.#label.classList.remove('checked');
|
|
247
|
+
|
|
248
|
+
this.setAttribute('indeterminate', true);
|
|
249
|
+
this.#label.classList.add('indeterminate');
|
|
250
|
+
console.log(val);
|
|
251
|
+
} else {
|
|
252
|
+
this.removeAttribute('indeterminate');
|
|
253
|
+
this.#label.classList.remove('indeterminate');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// #endregion
|
|
257
|
+
// ------- end -------
|
|
258
|
+
|
|
259
|
+
init() {
|
|
260
|
+
const that = this;
|
|
261
|
+
|
|
262
|
+
// checkbox 的 checked 属性
|
|
263
|
+
this.checked = this.checked;
|
|
264
|
+
|
|
265
|
+
// label 的 for 属性
|
|
266
|
+
this.name = this.name;
|
|
267
|
+
|
|
268
|
+
// checkbox 的 value 属性
|
|
269
|
+
this.value = this.value;
|
|
270
|
+
|
|
271
|
+
// checkbox 的 disabled 属性
|
|
272
|
+
this.disabled = this.disabled;
|
|
273
|
+
|
|
274
|
+
// border 属性
|
|
275
|
+
this.border = this.border;
|
|
276
|
+
|
|
277
|
+
// indeterminate 属性
|
|
278
|
+
this.indeterminate = this.indeterminate;
|
|
279
|
+
|
|
280
|
+
// 监听 change 事件, 修改 checked 属性
|
|
281
|
+
this.#checkbox.addEventListener('change', function (e) {
|
|
282
|
+
e.preventDefault();
|
|
283
|
+
that.checked = e.target.checked;
|
|
284
|
+
if (e.target.checked) {
|
|
285
|
+
// document.querySelectorAll(`ea-checkbox[name="${that.name}"]`).forEach(btn => {
|
|
286
|
+
// const btnInput = btn.shadowRoot.querySelector('input');
|
|
287
|
+
|
|
288
|
+
// if (btnInput !== this) {
|
|
289
|
+
// btn.checked = false;
|
|
290
|
+
// } else {
|
|
291
|
+
// btn.checked = true;
|
|
292
|
+
// }
|
|
293
|
+
// });
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
connectedCallback() {
|
|
299
|
+
this.init();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
303
|
+
// switch (name) {
|
|
304
|
+
// case 'disabled':
|
|
305
|
+
// this.#label.setAttribute('checked', true);
|
|
306
|
+
// this.#label.classList.add('checked');
|
|
307
|
+
// break;
|
|
308
|
+
// }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!window.customElements.get("ea-checkbox")) {
|
|
313
|
+
window.customElements.define("ea-checkbox", EaCheckbox);
|
|
314
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from "../Base.js";
|
|
3
|
+
|
|
4
|
+
const stylesheet = `
|
|
5
|
+
.ea-checkbox-group {
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
.ea-checkbox-group ::slotted(ea-checkbox) {
|
|
9
|
+
margin-right: 1.5rem;
|
|
10
|
+
}`;
|
|
11
|
+
|
|
12
|
+
export class EaCheckboxGroup extends Base {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
17
|
+
|
|
18
|
+
const dom = document.createElement('div');
|
|
19
|
+
shadowRoot.appendChild(dom);
|
|
20
|
+
const slot = document.createElement('slot');
|
|
21
|
+
dom.className = "ea-checkbox-group";
|
|
22
|
+
dom.appendChild(slot);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
this.dom = dom;
|
|
26
|
+
|
|
27
|
+
this.build(shadowRoot, stylesheet);
|
|
28
|
+
|
|
29
|
+
shadowRoot.appendChild(dom);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ------- name 唯一键值 -------
|
|
33
|
+
// #region
|
|
34
|
+
get name() {
|
|
35
|
+
return this.getAttribute('name');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set name(val) {
|
|
39
|
+
this.querySelectorAll('ea-checkbox').forEach(checkbox => {
|
|
40
|
+
checkbox.setAttribute('name', val);
|
|
41
|
+
checkbox.name = val;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// #endregion
|
|
45
|
+
// ------- end -------
|
|
46
|
+
|
|
47
|
+
// ------- value 指定选中值 -------
|
|
48
|
+
// #region
|
|
49
|
+
get value() {
|
|
50
|
+
if (!this.getAttribute('value')) return;
|
|
51
|
+
|
|
52
|
+
return this.getAttribute('value');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set value(val) {
|
|
56
|
+
if (!val) return;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const valArr = val.split(',').map(item => item.trimStart());
|
|
60
|
+
|
|
61
|
+
valArr.map(item => {
|
|
62
|
+
const checkbox = document.querySelector(`ea-checkbox[name="${this.name}"][value="${item}"]`);
|
|
63
|
+
checkbox.setAttribute('checked', 'true');
|
|
64
|
+
checkbox.checked = 'true';
|
|
65
|
+
})
|
|
66
|
+
} catch (error) {
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// #endregion
|
|
71
|
+
// ------- end -------
|
|
72
|
+
|
|
73
|
+
// ------- disabled 禁用 -------
|
|
74
|
+
// #region
|
|
75
|
+
get disabled() {
|
|
76
|
+
return this.getAttrBoolean('disabled');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
set disabled(val) {
|
|
80
|
+
const checkboxs = document.querySelectorAll(`ea-checkbox[name="${this.name}"]`);
|
|
81
|
+
|
|
82
|
+
checkboxs.forEach(checkbox => {
|
|
83
|
+
checkbox.disabled = val;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// #endregion
|
|
87
|
+
// ------- end -------
|
|
88
|
+
|
|
89
|
+
init() {
|
|
90
|
+
// name 唯一键值
|
|
91
|
+
this.name = this.name;
|
|
92
|
+
|
|
93
|
+
// value 指定选中值
|
|
94
|
+
this.value = this.value;
|
|
95
|
+
|
|
96
|
+
// disabled 禁用
|
|
97
|
+
this.disabled = this.disabled;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
connectedCallback() {
|
|
101
|
+
this.init();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!window.customElements.get("ea-checkbox-group")) {
|
|
106
|
+
window.customElements.define("ea-checkbox-group", EaCheckboxGroup);
|
|
107
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
import { createElement, createSlotElement } from '../../utils/createElement.js';
|
|
4
|
+
|
|
5
|
+
const stylesheet = `
|
|
6
|
+
|
|
7
|
+
.ea-collapse-item_wrap .ea-collapse-item_title {
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
border-bottom: 1px solid #ebeef5;
|
|
12
|
+
height: 48px;
|
|
13
|
+
line-height: 48px;
|
|
14
|
+
font-size: 13px;
|
|
15
|
+
font-weight: 700;
|
|
16
|
+
color: #303133;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
}
|
|
19
|
+
.ea-collapse-item_wrap .ea-collapse-item_title .ea-collapse-item_title-icon {
|
|
20
|
+
width: 0.35rem;
|
|
21
|
+
height: 0.35rem;
|
|
22
|
+
margin-right: 1rem;
|
|
23
|
+
border: 3px solid #9ca0a5;
|
|
24
|
+
border-left-color: transparent;
|
|
25
|
+
border-top-color: transparent;
|
|
26
|
+
rotate: -45deg;
|
|
27
|
+
transition: rotate 0.3s;
|
|
28
|
+
}
|
|
29
|
+
.ea-collapse-item_wrap .ea-collapse-item_content {
|
|
30
|
+
will-change: height;
|
|
31
|
+
overflow: hidden;
|
|
32
|
+
height: 0;
|
|
33
|
+
padding-bottom: 0;
|
|
34
|
+
transition: height 0.3s, padding-bottom 0.3s;
|
|
35
|
+
font-size: 13px;
|
|
36
|
+
color: #303133;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export class EaCollapse extends Base {
|
|
41
|
+
#wrap;
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
|
|
45
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
46
|
+
|
|
47
|
+
const slot = createSlotElement('');
|
|
48
|
+
const wrap = createElement('div', 'ea-collapse_wrap', [slot]);
|
|
49
|
+
|
|
50
|
+
this.#wrap = wrap;
|
|
51
|
+
|
|
52
|
+
this.build(shadowRoot, stylesheet);
|
|
53
|
+
this.shadowRoot.appendChild(wrap);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ------- active 当前展开项 -------
|
|
57
|
+
// #region
|
|
58
|
+
get active() {
|
|
59
|
+
return this.getAttribute('active') || 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set active(name) {
|
|
63
|
+
this.setAttribute('active', name);
|
|
64
|
+
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
this.#handleCollapse(this.accordion, name);
|
|
67
|
+
}, 20);
|
|
68
|
+
}
|
|
69
|
+
// #endregion
|
|
70
|
+
// ------- end -------
|
|
71
|
+
|
|
72
|
+
// ------- accordion 是否为手风琴模式 -------
|
|
73
|
+
// #region
|
|
74
|
+
get accordion() {
|
|
75
|
+
return this.getAttrBoolean('accordion') || false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set accordion(flag) {
|
|
79
|
+
this.setAttribute('accordion', flag);
|
|
80
|
+
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
this.#handleCollapse(flag, this.active);
|
|
83
|
+
}, 20);
|
|
84
|
+
}
|
|
85
|
+
// #endregion
|
|
86
|
+
// ------- end -------
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 处理折叠面板的展开/折叠状态。
|
|
90
|
+
* 根据传入的标志位flag和激活项名称activeItemName,来决定哪些折叠项应该展开。
|
|
91
|
+
* 当flag为true时,只允许一个折叠项展开,即单选模式;
|
|
92
|
+
* 当flag为false时,可以允许多个折叠项展开,即多选模式。
|
|
93
|
+
*
|
|
94
|
+
* @param {boolean} flag - 控制单选或多选模式的标志。true表示单选模式,false表示多选模式。
|
|
95
|
+
* @param {string} activeItemName - 激活项的名称,用于决定哪些折叠项应该展开。
|
|
96
|
+
*/
|
|
97
|
+
#handleCollapse(flag, activeItemName) {
|
|
98
|
+
const that = this;
|
|
99
|
+
// 将所有ea-collapse-item元素转换为数组
|
|
100
|
+
const items = Array.from(this.querySelectorAll('ea-collapse-item'));
|
|
101
|
+
// 初始化用于记录展开状态的变量
|
|
102
|
+
let collapseItem = flag ? "" : [];
|
|
103
|
+
|
|
104
|
+
// 遍历每个折叠项,绑定状态改变事件的监听器
|
|
105
|
+
items.forEach(item => {
|
|
106
|
+
item.addEventListener('collapseItemStatusChange', (e) => {
|
|
107
|
+
// 在单选模式下,关闭所有其他折叠项
|
|
108
|
+
if (flag) items.forEach(item => {
|
|
109
|
+
item.isOpen = false;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// 更新当前折叠项的展开状态
|
|
113
|
+
item.isOpen = !e.detail.isOpen;
|
|
114
|
+
|
|
115
|
+
// 触发change事件,通知外部当前折叠项的状态改变
|
|
116
|
+
that.dispatchEvent(new CustomEvent("change", {
|
|
117
|
+
detail: {
|
|
118
|
+
name: item.name,
|
|
119
|
+
isOpen: item.isOpen,
|
|
120
|
+
},
|
|
121
|
+
}))
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
// 根据flag的值来处理折叠项的展开状态
|
|
127
|
+
if (flag) {
|
|
128
|
+
// 在单选模式下,根据activeItemName确定哪个折叠项应该展开
|
|
129
|
+
collapseItem = activeItemName.toString().trim()[0];
|
|
130
|
+
|
|
131
|
+
items.forEach(item => {
|
|
132
|
+
// 根据collapseItem的值,决定当前折叠项是否展开
|
|
133
|
+
if (item.name === collapseItem) {
|
|
134
|
+
item.isOpen = true;
|
|
135
|
+
} else {
|
|
136
|
+
item.isOpen = false;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
// 在多选模式下,将activeItemName解析为数组,并处理每个折叠项的展开状态
|
|
141
|
+
collapseItem = activeItemName.split(',').map(item => {
|
|
142
|
+
return item.trim();
|
|
143
|
+
}).concat();
|
|
144
|
+
|
|
145
|
+
items.forEach(item => {
|
|
146
|
+
// 根据collapseItem数组中的值,决定当前折叠项是否展开
|
|
147
|
+
if (collapseItem.includes(item.name)) {
|
|
148
|
+
item.isOpen = true;
|
|
149
|
+
} else {
|
|
150
|
+
item.isOpen = false;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} catch (error) { }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#handleChildrenItemName() {
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
init() {
|
|
163
|
+
const that = this;
|
|
164
|
+
|
|
165
|
+
this.accordion = this.accordion;
|
|
166
|
+
|
|
167
|
+
this.active = this.active;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
connectedCallback() {
|
|
171
|
+
this.init();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!customElements.get('ea-collapse')) {
|
|
176
|
+
customElements.define('ea-collapse', EaCollapse);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export class EaCollapseItem extends Base {
|
|
180
|
+
#wrap;
|
|
181
|
+
|
|
182
|
+
#titleWrap;
|
|
183
|
+
#titleContent;
|
|
184
|
+
#titleIcon;
|
|
185
|
+
|
|
186
|
+
#contentWrap;
|
|
187
|
+
|
|
188
|
+
constructor() {
|
|
189
|
+
super();
|
|
190
|
+
|
|
191
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
192
|
+
|
|
193
|
+
const titleContent = createElement('span', 'ea-collapse-item_title-content');
|
|
194
|
+
const icon = createElement('span', 'ea-collapse-item_title-icon');
|
|
195
|
+
const titleWrap = createElement('div', 'ea-collapse-item_title', [titleContent, icon]);
|
|
196
|
+
const contentSlot = createSlotElement('');
|
|
197
|
+
const contentWrap = createElement('div', 'ea-collapse-item_content', [contentSlot]);
|
|
198
|
+
|
|
199
|
+
const wrap = createElement('div', 'ea-collapse-item_wrap', [titleWrap, contentWrap]);
|
|
200
|
+
|
|
201
|
+
this.#wrap = wrap;
|
|
202
|
+
this.#titleWrap = titleWrap;
|
|
203
|
+
this.#titleContent = titleContent;
|
|
204
|
+
this.#titleIcon = icon;
|
|
205
|
+
this.#contentWrap = contentWrap;
|
|
206
|
+
|
|
207
|
+
this.build(shadowRoot, stylesheet);
|
|
208
|
+
this.shadowRoot.appendChild(wrap);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ------- title 标题 -------
|
|
212
|
+
// #region
|
|
213
|
+
get title() {
|
|
214
|
+
return this.getAttribute('title');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
set title(title) {
|
|
218
|
+
this.setAttribute('title', title);
|
|
219
|
+
|
|
220
|
+
this.#titleContent.innerHTML = title;
|
|
221
|
+
}
|
|
222
|
+
// #endregion
|
|
223
|
+
// ------- end -------
|
|
224
|
+
|
|
225
|
+
// ------- name 唯一标识符 -------
|
|
226
|
+
// #region
|
|
227
|
+
get name() {
|
|
228
|
+
return this.getAttribute('name');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
set name(name) {
|
|
232
|
+
this.setAttribute('name', name);
|
|
233
|
+
}
|
|
234
|
+
// #endregion
|
|
235
|
+
// ------- end -------
|
|
236
|
+
|
|
237
|
+
// ------- isOpen 是否展开 -------
|
|
238
|
+
// #region
|
|
239
|
+
get isOpen() {
|
|
240
|
+
return this.getAttrBoolean('is-open') || false;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
set isOpen(flag) {
|
|
244
|
+
if (flag === this.isOpen) return;
|
|
245
|
+
|
|
246
|
+
this.toggleAttr('is-open', flag);
|
|
247
|
+
|
|
248
|
+
const height = this.#contentWrap.scrollHeight;
|
|
249
|
+
|
|
250
|
+
if (this.isOpen) {
|
|
251
|
+
this.#contentWrap.style.height = `${height}px`;
|
|
252
|
+
this.#contentWrap.style.paddingBottom = '20px';
|
|
253
|
+
this.#titleIcon.style.rotate = '45deg';
|
|
254
|
+
|
|
255
|
+
} else {
|
|
256
|
+
this.#contentWrap.style.height = '0px';
|
|
257
|
+
this.#contentWrap.style.paddingBottom = '0px';
|
|
258
|
+
this.#titleIcon.style.rotate = '-45deg';
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// #endregion
|
|
262
|
+
// ------- end -------
|
|
263
|
+
|
|
264
|
+
#initCollapseChange() {
|
|
265
|
+
const that = this;
|
|
266
|
+
|
|
267
|
+
this.#titleWrap.addEventListener('click', () => {
|
|
268
|
+
that.dispatchEvent(new CustomEvent('collapseItemStatusChange', {
|
|
269
|
+
detail: {
|
|
270
|
+
name: that.name,
|
|
271
|
+
isOpen: that.isOpen,
|
|
272
|
+
},
|
|
273
|
+
}));
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
init() {
|
|
278
|
+
const that = this;
|
|
279
|
+
|
|
280
|
+
this.title = this.title;
|
|
281
|
+
this.name = this.name;
|
|
282
|
+
|
|
283
|
+
this.#initCollapseChange();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
connectedCallback() {
|
|
287
|
+
this.init();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!customElements.get('ea-collapse-item')) {
|
|
292
|
+
customElements.define('ea-collapse-item', EaCollapseItem);
|
|
293
|
+
}
|