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,765 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from "../Base.js";
|
|
3
|
+
import "../ea-icon/index.js"
|
|
4
|
+
|
|
5
|
+
const stylesheet = `
|
|
6
|
+
@charset "UTF-8";
|
|
7
|
+
|
|
8
|
+
:host {
|
|
9
|
+
--border-top-left-radius: 0;
|
|
10
|
+
--border-top-right-radius: 0;
|
|
11
|
+
--border-bottom-left-radius: 0;
|
|
12
|
+
--border-bottom-right-radius: 0;
|
|
13
|
+
--border-left-width: 0;
|
|
14
|
+
--border-right-width: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ea-input_wrap {
|
|
18
|
+
position: relative;
|
|
19
|
+
width: 100%;
|
|
20
|
+
/* ------- 特定的属性的图标(clearable, password) ------- */
|
|
21
|
+
/* #region */
|
|
22
|
+
/* #endregion */
|
|
23
|
+
/* ------- end ------- */
|
|
24
|
+
/* ------- 标识图标在输入框前还是后 ------- */
|
|
25
|
+
/* #region */
|
|
26
|
+
/* #endregion */
|
|
27
|
+
/* ------- end ------- */
|
|
28
|
+
/* ------- 输入框前后的dom ------- */
|
|
29
|
+
/* #region */
|
|
30
|
+
/* #endregion */
|
|
31
|
+
/* ------- end ------- */
|
|
32
|
+
}
|
|
33
|
+
.ea-input_wrap .ea-input_inner {
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
box-shadow: none;
|
|
36
|
+
border: 1px solid #dcdfe6;
|
|
37
|
+
outline: 0;
|
|
38
|
+
transition: border 0.2s;
|
|
39
|
+
border-radius: 3px;
|
|
40
|
+
padding: 0.5rem;
|
|
41
|
+
width: 100%;
|
|
42
|
+
line-height: 0.8;
|
|
43
|
+
font-size: 0.8rem;
|
|
44
|
+
scrollbar-width: none;
|
|
45
|
+
}
|
|
46
|
+
.ea-input_wrap .ea-input_inner:focus {
|
|
47
|
+
border-color: #409eff;
|
|
48
|
+
}
|
|
49
|
+
.ea-input_wrap .ea-input_inner::placeholder {
|
|
50
|
+
color: #c0c4cc;
|
|
51
|
+
}
|
|
52
|
+
.ea-input_wrap .ea-input_inner.invalid {
|
|
53
|
+
border-color: #f56c6c;
|
|
54
|
+
}
|
|
55
|
+
.ea-input_wrap .ea-input_inner.disabled {
|
|
56
|
+
background-color: #eeeeee;
|
|
57
|
+
color: #c0c4cc;
|
|
58
|
+
}
|
|
59
|
+
.ea-input_wrap .ea-input_inner.ea-input_clear ::before {
|
|
60
|
+
content: "\e9c3";
|
|
61
|
+
display: block;
|
|
62
|
+
}
|
|
63
|
+
.ea-input_wrap i {
|
|
64
|
+
font-size: 0.9rem;
|
|
65
|
+
line-height: 0.8;
|
|
66
|
+
}
|
|
67
|
+
.ea-input_wrap i[class=icon-cancel-circled2],
|
|
68
|
+
.ea-input_wrap i[class=icon-eye],
|
|
69
|
+
.ea-input_wrap i[class=icon-eye-off] {
|
|
70
|
+
position: absolute;
|
|
71
|
+
left: calc(100% - 1.75rem);
|
|
72
|
+
top: 50%;
|
|
73
|
+
color: #c0c4cc;
|
|
74
|
+
transform: translate(calc(-100% - 0.25rem), -50%);
|
|
75
|
+
}
|
|
76
|
+
.ea-input_wrap.clearable .ea-input_inner, .ea-input_wrap.password .ea-input_inner {
|
|
77
|
+
width: calc(100% - 1.75rem);
|
|
78
|
+
padding-right: 1.75rem;
|
|
79
|
+
}
|
|
80
|
+
.ea-input_wrap.prefix i, .ea-input_wrap.suffix i {
|
|
81
|
+
position: absolute;
|
|
82
|
+
top: 50%;
|
|
83
|
+
color: #c0c4cc;
|
|
84
|
+
}
|
|
85
|
+
.ea-input_wrap.prefix .ea-input_inner, .ea-input_wrap.suffix .ea-input_inner {
|
|
86
|
+
width: calc(100% - 1.75rem);
|
|
87
|
+
}
|
|
88
|
+
.ea-input_wrap.prefix i {
|
|
89
|
+
left: 2.5%;
|
|
90
|
+
transform: translate(-2.5%, -50%);
|
|
91
|
+
}
|
|
92
|
+
.ea-input_wrap.prefix .ea-input_inner {
|
|
93
|
+
padding-left: 1.75rem;
|
|
94
|
+
}
|
|
95
|
+
.ea-input_wrap.suffix i {
|
|
96
|
+
left: calc(100% - 1.75rem);
|
|
97
|
+
transform: translate(calc(-100% - 0.25rem), -50%);
|
|
98
|
+
}
|
|
99
|
+
.ea-input_wrap.suffix .ea-input_inner {
|
|
100
|
+
padding-right: 1.75rem;
|
|
101
|
+
}
|
|
102
|
+
.ea-input_wrap.prepend-slot, .ea-input_wrap.append-slot {
|
|
103
|
+
display: flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
font-size: 0.925rem;
|
|
106
|
+
line-height: 1;
|
|
107
|
+
}
|
|
108
|
+
.ea-input_wrap.prepend-slot ::slotted(div), .ea-input_wrap.append-slot ::slotted(div) {
|
|
109
|
+
border: 1px solid #dcdfe6;
|
|
110
|
+
border-left-width: var(--border-left-width);
|
|
111
|
+
border-right-width: var(--border-right-width);
|
|
112
|
+
border-top-right-radius: var(--border-top-right-radius);
|
|
113
|
+
border-bottom-right-radius: var(--border-bottom-right-radius);
|
|
114
|
+
border-top-left-radius: var(--border-top-left-radius);
|
|
115
|
+
border-bottom-left-radius: var(--border-bottom-left-radius);
|
|
116
|
+
}
|
|
117
|
+
.ea-input_wrap.prepend-slot .ea-input_inner {
|
|
118
|
+
border-top-left-radius: 0;
|
|
119
|
+
border-bottom-left-radius: 0;
|
|
120
|
+
}
|
|
121
|
+
.ea-input_wrap.append-slot .ea-input_inner {
|
|
122
|
+
border-top-right-radius: 0;
|
|
123
|
+
border-bottom-right-radius: 0;
|
|
124
|
+
}
|
|
125
|
+
.ea-input_wrap .ea-input_suggestion-wrap {
|
|
126
|
+
list-style-type: none;
|
|
127
|
+
padding: 0;
|
|
128
|
+
margin: 0;
|
|
129
|
+
margin-block-start: 0;
|
|
130
|
+
margin-block-end: 0;
|
|
131
|
+
padding-inline-start: 0;
|
|
132
|
+
unicode-bidi: unset;
|
|
133
|
+
display: none;
|
|
134
|
+
position: absolute;
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
z-index: 3;
|
|
137
|
+
top: calc(100% + 5px);
|
|
138
|
+
left: 0;
|
|
139
|
+
padding: 0.5rem 0;
|
|
140
|
+
width: 100%;
|
|
141
|
+
max-height: 10rem;
|
|
142
|
+
overflow-y: auto;
|
|
143
|
+
scrollbar-width: thin;
|
|
144
|
+
background-color: white;
|
|
145
|
+
box-shadow: 0 1px 8px 1px rgba(0, 0, 0, 0.2);
|
|
146
|
+
}
|
|
147
|
+
.ea-input_wrap .ea-input_suggestion-wrap li {
|
|
148
|
+
padding: 0.5rem;
|
|
149
|
+
font-size: 0.9rem;
|
|
150
|
+
cursor: pointer;
|
|
151
|
+
}
|
|
152
|
+
.ea-input_wrap .ea-input_suggestion-wrap li:hover {
|
|
153
|
+
background-color: #f5f7fa;
|
|
154
|
+
}
|
|
155
|
+
.ea-input_wrap .ea-input_suggestion-wrap.loading {
|
|
156
|
+
height: 5rem;
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
}
|
|
161
|
+
.ea-input_wrap .ea-input_suggestion-wrap.loading::after {
|
|
162
|
+
font-family: "fontello";
|
|
163
|
+
font-style: normal;
|
|
164
|
+
font-weight: normal;
|
|
165
|
+
speak: never;
|
|
166
|
+
display: inline-block;
|
|
167
|
+
text-decoration: inherit;
|
|
168
|
+
width: 1em;
|
|
169
|
+
margin-right: 0.2em;
|
|
170
|
+
text-align: center;
|
|
171
|
+
font-variant: normal;
|
|
172
|
+
text-transform: none;
|
|
173
|
+
line-height: 1em;
|
|
174
|
+
margin-left: 0.2em;
|
|
175
|
+
-webkit-font-smoothing: antialiased;
|
|
176
|
+
-moz-osx-font-smoothing: grayscale;
|
|
177
|
+
content: "\e839";
|
|
178
|
+
font-size: 1.5rem;
|
|
179
|
+
animation: spin 1s linear infinite;
|
|
180
|
+
animation-play-state: running;
|
|
181
|
+
}
|
|
182
|
+
.ea-input_wrap.word-limit {
|
|
183
|
+
border: 1px solid #dcdfe6;
|
|
184
|
+
border-radius: 3px;
|
|
185
|
+
}
|
|
186
|
+
.ea-input_wrap.word-limit .ea-input_inner {
|
|
187
|
+
border: 0;
|
|
188
|
+
width: calc(100% - 3rem);
|
|
189
|
+
}
|
|
190
|
+
.ea-input_wrap.word-limit .ea-input_word-limit {
|
|
191
|
+
padding-right: 0.5rem;
|
|
192
|
+
width: 2.5rem;
|
|
193
|
+
font-size: 0.75rem;
|
|
194
|
+
text-align: center;
|
|
195
|
+
}
|
|
196
|
+
`;
|
|
197
|
+
|
|
198
|
+
const inputDom = (type) => {
|
|
199
|
+
const input = document.createElement('input');
|
|
200
|
+
|
|
201
|
+
input.className = "ea-input_inner";
|
|
202
|
+
input.type = type || "text";
|
|
203
|
+
input.autocomplete = "off";
|
|
204
|
+
|
|
205
|
+
return input;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const suggestionBoardDom = () => {
|
|
209
|
+
const suggestionBoard = document.createElement('ul');
|
|
210
|
+
suggestionBoard.className = "ea-input_suggestion-wrap";
|
|
211
|
+
|
|
212
|
+
return suggestionBoard;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const slotDom = (name) => {
|
|
216
|
+
const slot = document.createElement('slot');
|
|
217
|
+
slot.name = name;
|
|
218
|
+
|
|
219
|
+
return slot;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export class EaInput extends Base {
|
|
223
|
+
#wrap;
|
|
224
|
+
#input;
|
|
225
|
+
#clearIcon;
|
|
226
|
+
#showPasswordIcon;
|
|
227
|
+
#mounted = false;
|
|
228
|
+
|
|
229
|
+
#suggestion = [];
|
|
230
|
+
#suggestionBoard;
|
|
231
|
+
|
|
232
|
+
#prependSlot;
|
|
233
|
+
#appendSlot;
|
|
234
|
+
|
|
235
|
+
constructor() {
|
|
236
|
+
super();
|
|
237
|
+
|
|
238
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
239
|
+
const wrap = document.createElement('div');
|
|
240
|
+
wrap.className = "ea-input_wrap";
|
|
241
|
+
|
|
242
|
+
const dom = inputDom(this.type);
|
|
243
|
+
|
|
244
|
+
// slot 和 template, 用于输入框前后 的 插槽
|
|
245
|
+
const prependSlot = slotDom('prepend');
|
|
246
|
+
const appendSlot = slotDom('append');
|
|
247
|
+
|
|
248
|
+
const prependTemplate = this.querySelector('[slot=prepend]');
|
|
249
|
+
const appendTemplate = this.querySelector('[slot=append]');
|
|
250
|
+
|
|
251
|
+
if (prependTemplate) {
|
|
252
|
+
wrap.classList.add('prepend-slot');
|
|
253
|
+
|
|
254
|
+
prependTemplate.style.setProperty('--border-top-left-radius', '3px');
|
|
255
|
+
prependTemplate.style.setProperty('--border-bottom-left-radius', '3px');
|
|
256
|
+
|
|
257
|
+
prependTemplate.style.setProperty('--border-right-width', '0');
|
|
258
|
+
prependTemplate.style.setProperty('--border-left-width', '1px');
|
|
259
|
+
|
|
260
|
+
prependSlot.appendChild(prependTemplate.cloneNode(true));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (appendTemplate) {
|
|
264
|
+
wrap.classList.add('append-slot');
|
|
265
|
+
|
|
266
|
+
appendTemplate.style.setProperty('--border-top-right-radius', '3px');
|
|
267
|
+
appendTemplate.style.setProperty('--border-bottom-right-radius', '3px');
|
|
268
|
+
|
|
269
|
+
appendTemplate.style.setProperty('--border-left-width', '0');
|
|
270
|
+
appendTemplate.style.setProperty('--border-right-width', '1px');
|
|
271
|
+
|
|
272
|
+
appendSlot.appendChild(appendTemplate.cloneNode(true));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
wrap.appendChild(dom);
|
|
276
|
+
wrap.insertBefore(prependSlot, dom);
|
|
277
|
+
wrap.appendChild(appendSlot);
|
|
278
|
+
|
|
279
|
+
this.#wrap = wrap;
|
|
280
|
+
this.#input = dom;
|
|
281
|
+
this.#prependSlot = prependSlot;
|
|
282
|
+
this.#appendSlot = appendSlot;
|
|
283
|
+
|
|
284
|
+
// 输入建议
|
|
285
|
+
if (this.suggestion.length > 0 || this.remote) {
|
|
286
|
+
this.suggestionEvent();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
|
|
290
|
+
|
|
291
|
+
this.build(shadowRoot, stylesheet);
|
|
292
|
+
this.shadowRoot.appendChild(wrap);
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ------- type 标识是 input 还是 textarea -------
|
|
297
|
+
// #region
|
|
298
|
+
get type() {
|
|
299
|
+
return this.getAttribute("type") || "text";
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
set type(val) {
|
|
303
|
+
this.setAttribute("type", val);
|
|
304
|
+
}
|
|
305
|
+
// #endregion
|
|
306
|
+
// ------- end -------
|
|
307
|
+
|
|
308
|
+
// ------- value 输入框的值 -------
|
|
309
|
+
// #region
|
|
310
|
+
get value() {
|
|
311
|
+
if (!this.#mounted) {
|
|
312
|
+
this.#input.value = this.getAttribute("value") || '';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return this.getAttribute('value');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
set value(val) {
|
|
319
|
+
if (!val) return;
|
|
320
|
+
|
|
321
|
+
this.setAttribute("value", val);
|
|
322
|
+
this.#input.value = val;
|
|
323
|
+
}
|
|
324
|
+
// #endregion
|
|
325
|
+
// ------- end -------
|
|
326
|
+
|
|
327
|
+
// ------- placeholder 提示 -------
|
|
328
|
+
// #region
|
|
329
|
+
get placeholder() {
|
|
330
|
+
return this.getAttribute("placeholder") || '';
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
set placeholder(val) {
|
|
334
|
+
this.setAttribute("placeholder", val);
|
|
335
|
+
this.#input.placeholder = val;
|
|
336
|
+
}
|
|
337
|
+
// #endregion
|
|
338
|
+
// ------- end -------
|
|
339
|
+
|
|
340
|
+
// ------- disabled 输入框禁用 -------
|
|
341
|
+
// #region
|
|
342
|
+
get disabled() {
|
|
343
|
+
return this.getAttrBoolean("disabled");
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
set disabled(val) {
|
|
347
|
+
this.toggleAttr("disabled", val);
|
|
348
|
+
this.#input.disabled = val;
|
|
349
|
+
this.#input.classList.toggle("disabled", val);
|
|
350
|
+
}
|
|
351
|
+
// #endregion
|
|
352
|
+
// ------- end -------
|
|
353
|
+
|
|
354
|
+
// ------- clearable 可清除 -------
|
|
355
|
+
// #region
|
|
356
|
+
get clearable() {
|
|
357
|
+
return this.getAttrBoolean("clearable");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
set clearable(val) {
|
|
361
|
+
if (!val) return;
|
|
362
|
+
|
|
363
|
+
this.setAttribute("clearable", val);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// 清除图标
|
|
367
|
+
clearableEvent(e) {
|
|
368
|
+
if (!this.clearable) return;
|
|
369
|
+
|
|
370
|
+
if (this.clearable && e.target.value !== '') {
|
|
371
|
+
this.#clearIcon.style.display = 'block';
|
|
372
|
+
} else {
|
|
373
|
+
this.#clearIcon.style.display = 'none';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// 清除图标初始化
|
|
378
|
+
initClearableIcon() {
|
|
379
|
+
if (this.clearable) {
|
|
380
|
+
const clearIcon = this.iconInit('icon-cancel-circled2');
|
|
381
|
+
|
|
382
|
+
clearIcon.addEventListener('click', () => {
|
|
383
|
+
this.value = '';
|
|
384
|
+
this.#input.focus();
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
this.#clearIcon = clearIcon;
|
|
388
|
+
|
|
389
|
+
if (this.value) {
|
|
390
|
+
this.#clearIcon.style.display = 'block';
|
|
391
|
+
} else {
|
|
392
|
+
this.#clearIcon.style.display = 'none';
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
this.iconAppend('clearable', this.clearable, clearIcon);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// #endregion
|
|
399
|
+
// ------- end -------
|
|
400
|
+
|
|
401
|
+
// ------- show-password 密码 -------
|
|
402
|
+
// #region
|
|
403
|
+
get showPassword() {
|
|
404
|
+
return this.getAttrBoolean("show-password");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
set showPassword(val) {
|
|
408
|
+
if (!val) return;
|
|
409
|
+
this.setAttribute("show-password", val);
|
|
410
|
+
|
|
411
|
+
if (val) {
|
|
412
|
+
this.#input.type = "password";
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 显示/隐藏密码图标
|
|
417
|
+
showPasswordEvent(e) {
|
|
418
|
+
if (!this.showPassword) return;
|
|
419
|
+
|
|
420
|
+
if (this.showPassword && e.target.value !== '') {
|
|
421
|
+
this.#showPasswordIcon.style.display = 'block';
|
|
422
|
+
} else {
|
|
423
|
+
this.#showPasswordIcon.style.display = 'none';
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// 初始化 显示/隐藏密码
|
|
428
|
+
initShowPasswordIcon() {
|
|
429
|
+
if (this.showPassword) {
|
|
430
|
+
const showPasswordIcon = this.iconInit('icon-eye');
|
|
431
|
+
if (!this.value) showPasswordIcon.style.display = 'none';
|
|
432
|
+
|
|
433
|
+
showPasswordIcon.addEventListener('click', (e) => {
|
|
434
|
+
this.#showPasswordIcon.className = this.#input.type === "password" ? "icon-eye-off" : "icon-eye";
|
|
435
|
+
this.#input.type = this.#input.type === "password" ? "text" : "password";
|
|
436
|
+
|
|
437
|
+
this.#input.focus();
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
this.#showPasswordIcon = showPasswordIcon;
|
|
441
|
+
|
|
442
|
+
this.iconAppend('password', this.showPassword, showPasswordIcon);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
// #endregion
|
|
446
|
+
// ------- end -------
|
|
447
|
+
|
|
448
|
+
// ------- prefix/surfix 指定图标显示位置 -------
|
|
449
|
+
// #region
|
|
450
|
+
get prefixIcon() {
|
|
451
|
+
return this.getAttribute("prefix-icon") || '';
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
set prefixIcon(val) {
|
|
455
|
+
if (!val) return;
|
|
456
|
+
|
|
457
|
+
this.setAttribute("prefix", val);
|
|
458
|
+
const prefixIcon = this.iconInit(val);
|
|
459
|
+
this.iconAppend('prefix', true, prefixIcon);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
get surfixIcon() {
|
|
463
|
+
return this.getAttribute("suffix-icon") || '';
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
set surfixIcon(val) {
|
|
467
|
+
if (!val) return;
|
|
468
|
+
|
|
469
|
+
this.setAttribute("suffix", val);
|
|
470
|
+
const surfixIcon = this.iconInit(val);
|
|
471
|
+
this.iconAppend('suffix', true, surfixIcon);
|
|
472
|
+
}
|
|
473
|
+
// #endregion
|
|
474
|
+
// ------- end -------
|
|
475
|
+
|
|
476
|
+
// ------- suggestion 建议 -------
|
|
477
|
+
// #region
|
|
478
|
+
|
|
479
|
+
// 建议列表
|
|
480
|
+
get suggestion() {
|
|
481
|
+
return this.#suggestion;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
set suggestion(val) {
|
|
485
|
+
if (!val) return;
|
|
486
|
+
|
|
487
|
+
// console.log(val);
|
|
488
|
+
this.#suggestion = val;
|
|
489
|
+
// this.setAttribute("primary-key", nanoid());
|
|
490
|
+
// this.primaryKey = nanoid();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// 输入框激活时列出输入建议
|
|
494
|
+
get triggerOnFocus() {
|
|
495
|
+
return this.getAttrBoolean("trigger-on-focus");
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
set triggerOnFocus(val) {
|
|
499
|
+
if (!val) return;
|
|
500
|
+
|
|
501
|
+
this.setAttribute("trigger-on-focus", val);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// 输入框输入后匹配输入建议
|
|
505
|
+
get triggerAfterInput() {
|
|
506
|
+
return this.getAttrBoolean("trigger-after-input");
|
|
507
|
+
}
|
|
508
|
+
set triggerAfterInput(val) {
|
|
509
|
+
if (!val) return;
|
|
510
|
+
|
|
511
|
+
this.setAttribute("trigger-after-input", val);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// 数据为远程加载时, 显示加载中
|
|
515
|
+
get remote() {
|
|
516
|
+
return this.getAttrBoolean("remote");
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
set remote(val) {
|
|
520
|
+
if (val === null || val === undefined) return;
|
|
521
|
+
|
|
522
|
+
try {
|
|
523
|
+
const flag = this.#suggestionBoard.style.display
|
|
524
|
+
if (flag == "flex") this.#suggestionBoard.style.display = "block";
|
|
525
|
+
else if (flag == "") this.#suggestionBoard.style.display = "none";
|
|
526
|
+
|
|
527
|
+
this.#suggestionBoard.classList.toggle('loading', val);
|
|
528
|
+
this.setAttribute("remote", val);
|
|
529
|
+
|
|
530
|
+
if (this.#mounted) this.refresh();
|
|
531
|
+
} catch (error) {
|
|
532
|
+
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// 数据更新时调用
|
|
537
|
+
refresh() {
|
|
538
|
+
try {
|
|
539
|
+
this.#suggestionBoard.innerHTML = '';
|
|
540
|
+
this.suggestionEvent();
|
|
541
|
+
} catch (error) {
|
|
542
|
+
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// 输入建议逻辑
|
|
547
|
+
suggestionEvent() {
|
|
548
|
+
const suggestionBoard = !this.#mounted ? suggestionBoardDom() : this.#suggestionBoard;
|
|
549
|
+
|
|
550
|
+
// 利用 li 标签 将用户传入值 进行渲染
|
|
551
|
+
this.suggestion.forEach(item => {
|
|
552
|
+
const li = document.createElement('li');
|
|
553
|
+
li.innerText = item.value;
|
|
554
|
+
|
|
555
|
+
li.addEventListener('click', () => {
|
|
556
|
+
this.value = item.value;
|
|
557
|
+
suggestionBoard.style.display = 'none';
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
suggestionBoard.appendChild(li);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
// 当点击其他地方时, 关闭输入建议
|
|
564
|
+
document.addEventListener('click', (e) => {
|
|
565
|
+
if (e.target !== this) {
|
|
566
|
+
suggestionBoard.style.display = 'none';
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// 匹配输入建议
|
|
571
|
+
this.#input.addEventListener('input', (e) => {
|
|
572
|
+
this.shadowRoot.querySelectorAll('li').forEach(item => {
|
|
573
|
+
if (item.innerText.includes(e.target.value)) {
|
|
574
|
+
item.style.display = 'block';
|
|
575
|
+
} else {
|
|
576
|
+
item.style.display = 'none';
|
|
577
|
+
}
|
|
578
|
+
})
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// 激活时列出输入建议
|
|
582
|
+
if (this.triggerOnFocus) {
|
|
583
|
+
this.#input.addEventListener('focus', (e) => {
|
|
584
|
+
suggestionBoard.style.display = this.remote ? "flex" : 'block';
|
|
585
|
+
});
|
|
586
|
+
// 输入时列出输入建议
|
|
587
|
+
} else if (this.triggerAfterInput) {
|
|
588
|
+
this.#input.addEventListener('input', (e) => {
|
|
589
|
+
if (e.target.value.length > 0) {
|
|
590
|
+
suggestionBoard.style.display = 'block';
|
|
591
|
+
} else {
|
|
592
|
+
suggestionBoard.style.display = 'none';
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (!this.#mounted) {
|
|
598
|
+
this.#suggestionBoard = suggestionBoard;
|
|
599
|
+
this.#wrap.appendChild(suggestionBoard);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// #endregion
|
|
604
|
+
// ------- end -------
|
|
605
|
+
|
|
606
|
+
// ------- max-length 最大长度 -------
|
|
607
|
+
// #region
|
|
608
|
+
|
|
609
|
+
// 获取最大限制值
|
|
610
|
+
get maxLength() {
|
|
611
|
+
return this.getAttribute("max-length");
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
set maxLength(val) {
|
|
615
|
+
if (!val || this.#input.type !== "text") return;
|
|
616
|
+
|
|
617
|
+
this.setAttribute("max-length", val);
|
|
618
|
+
this.#input.maxLength = val;
|
|
619
|
+
|
|
620
|
+
this.#input.addEventListener('input', (e) => {
|
|
621
|
+
if (e.target.value.length > val) {
|
|
622
|
+
e.target.value = e.target.value.slice(0, val);
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
if (this.showWordLimit) this.showWordLimit = true;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// 获取最小限制值
|
|
630
|
+
get minLength() {
|
|
631
|
+
return this.getAttribute("min-length");
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
set minLength(val) {
|
|
635
|
+
if (!val || this.#input.type !== "text") return;
|
|
636
|
+
|
|
637
|
+
this.setAttribute("min-length", val);
|
|
638
|
+
this.#input.minLength = val;
|
|
639
|
+
|
|
640
|
+
this.#input.addEventListener('input', (e) => {
|
|
641
|
+
if (e.target.value.length < val) {
|
|
642
|
+
e.target.classList.add('invalid');
|
|
643
|
+
} else {
|
|
644
|
+
e.target.classList.remove('invalid');
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// 显示 当前文字长度 和 限制值
|
|
650
|
+
get showWordLimit() {
|
|
651
|
+
return this.getAttrBoolean("show-word-limit");
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
set showWordLimit(val) {
|
|
655
|
+
if (!val || this.#input.type !== "text") return;
|
|
656
|
+
|
|
657
|
+
this.setAttribute("show-word-limit", val);
|
|
658
|
+
|
|
659
|
+
// 加入显示的dom
|
|
660
|
+
const wordLimit = document.createElement('span');
|
|
661
|
+
this.#wrap.classList.toggle('word-limit', val);
|
|
662
|
+
this.#wrap.classList.toggle('append-slot', val);
|
|
663
|
+
wordLimit.className = 'ea-input_word-limit';
|
|
664
|
+
wordLimit.innerText = `${this.#input.value.length}/${this.maxLength}`;
|
|
665
|
+
|
|
666
|
+
this.#input.addEventListener('input', (e) => {
|
|
667
|
+
wordLimit.innerText = `${e.target.value.length}/${this.maxLength}`;
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
this.#appendSlot.appendChild(wordLimit);
|
|
672
|
+
this.#wrap.appendChild(wordLimit);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// #endregion
|
|
676
|
+
// ------- end -------
|
|
677
|
+
|
|
678
|
+
// 图标dom初始化
|
|
679
|
+
iconInit(className) {
|
|
680
|
+
const clearIcon = document.createElement('i');
|
|
681
|
+
clearIcon.className = className;
|
|
682
|
+
|
|
683
|
+
return clearIcon;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// 图标dom添加
|
|
687
|
+
iconAppend(className, isClassName, element) {
|
|
688
|
+
this.#wrap.classList.toggle(className, isClassName);
|
|
689
|
+
this.#wrap.appendChild(element);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// 事件初始化
|
|
693
|
+
eventInit(e, eventName) {
|
|
694
|
+
this.dispatchEvent(
|
|
695
|
+
new CustomEvent(eventName, {
|
|
696
|
+
detail: {
|
|
697
|
+
value: e.target.value
|
|
698
|
+
}
|
|
699
|
+
})
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
this.clearableEvent(e);
|
|
703
|
+
this.showPasswordEvent(e);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
init() {
|
|
707
|
+
const that = this;
|
|
708
|
+
|
|
709
|
+
// 按钮类型
|
|
710
|
+
this.type = this.type;
|
|
711
|
+
|
|
712
|
+
// 输入框提示
|
|
713
|
+
this.placeholder = this.placeholder;
|
|
714
|
+
|
|
715
|
+
// 输入框的值
|
|
716
|
+
this.value = this.value;
|
|
717
|
+
|
|
718
|
+
// 禁用
|
|
719
|
+
this.disabled = this.disabled;
|
|
720
|
+
|
|
721
|
+
// 可清除
|
|
722
|
+
this.clearable = this.clearable;
|
|
723
|
+
this.initClearableIcon();
|
|
724
|
+
|
|
725
|
+
// 密码
|
|
726
|
+
this.showPassword = this.showPassword;
|
|
727
|
+
this.initShowPasswordIcon();
|
|
728
|
+
|
|
729
|
+
// 输入框图标
|
|
730
|
+
this.prefixIcon = this.prefixIcon;
|
|
731
|
+
this.surfixIcon = this.surfixIcon;
|
|
732
|
+
|
|
733
|
+
// 输入建议
|
|
734
|
+
this.suggestion = this.suggestion;
|
|
735
|
+
if (this.remote) this.remote = this.remote;
|
|
736
|
+
|
|
737
|
+
// 输入长度限制
|
|
738
|
+
this.maxLength = this.maxLength;
|
|
739
|
+
this.minLength = this.minLength;
|
|
740
|
+
|
|
741
|
+
// 输入时
|
|
742
|
+
this.#input.addEventListener("input", (e) => {
|
|
743
|
+
this.eventInit(e, "change");
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
// 聚焦时
|
|
747
|
+
this.#input.addEventListener("focus", (e) => {
|
|
748
|
+
this.eventInit(e, "focus");
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
// 失焦时
|
|
752
|
+
this.#input.addEventListener("blur", (e) => {
|
|
753
|
+
this.eventInit(e, "blur");
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
connectedCallback() {
|
|
758
|
+
this.init();
|
|
759
|
+
this.#mounted = true;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (!window.customElements.get("ea-input")) {
|
|
764
|
+
window.customElements.define("ea-input", EaInput);
|
|
765
|
+
}
|