easy-component-ui 0.0.2 → 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.
Files changed (60) hide show
  1. package/components/Base.js +90 -0
  2. package/components/ea-alert/index.js +298 -0
  3. package/components/ea-avatar/index.js +277 -0
  4. package/components/ea-backtop/index.js +232 -0
  5. package/components/ea-badge/index.js +160 -0
  6. package/components/ea-button/index.js +584 -0
  7. package/components/ea-button-group/index.js +459 -0
  8. package/components/ea-calendar/index.js +409 -0
  9. package/components/ea-card/index.js +77 -0
  10. package/components/ea-carousel/index.js +434 -0
  11. package/components/ea-checkbox/index.js +314 -0
  12. package/components/ea-checkbox-group/index.js +107 -0
  13. package/components/ea-collapse/index.js +293 -0
  14. package/components/ea-descriptions/index.js +240 -0
  15. package/components/ea-descriptions-item/index.js +110 -0
  16. package/components/ea-empty/index.js +141 -0
  17. package/{icon → components/ea-icon}/config.json +1017 -1017
  18. package/{icon → components/ea-icon}/css/animation.css +85 -85
  19. package/{icon → components/ea-icon}/css/fontello.css +224 -224
  20. package/components/ea-icon/font/fontello.svg +683 -0
  21. package/components/ea-icon/index.css +2 -0
  22. package/components/ea-icon/index.js +47 -0
  23. package/components/ea-image/index.js +412 -0
  24. package/components/ea-infinite-scroll/index.js +170 -0
  25. package/components/ea-input/index.js +765 -0
  26. package/components/ea-input-number/index.js +458 -0
  27. package/components/ea-link/index.js +200 -0
  28. package/components/ea-loading/index.js +218 -0
  29. package/components/ea-message/MessageClass.js +71 -0
  30. package/components/ea-message/index.js +233 -0
  31. package/components/ea-message-box/EaMessageBoxClass.js +48 -0
  32. package/components/ea-message-box/index.js +202 -0
  33. package/components/ea-pagination/index.js +444 -0
  34. package/components/ea-progress/index.js +333 -0
  35. package/components/ea-radio/index.js +287 -0
  36. package/components/ea-radio-group/index.js +59 -0
  37. package/components/ea-rate/index.js +326 -0
  38. package/components/ea-result/index.js +167 -0
  39. package/components/ea-select/index.js +34 -0
  40. package/components/ea-skeleton/index.js +341 -0
  41. package/components/ea-switch/index.js +301 -0
  42. package/components/ea-tag/index.js +212 -0
  43. package/components/ea-textarea/index.js +333 -0
  44. package/components/ea-timeline/index.js +334 -0
  45. package/components/ea-ui-base-style.css +0 -0
  46. package/package.json +1 -1
  47. package/utils/createElement.js +30 -0
  48. package/utils/handleTemplate.js +19 -0
  49. package/utils/setStyle.js +8 -0
  50. package/icon/font/fontello.svg +0 -346
  51. package/icon/index.css +0 -2
  52. package/index.js +0 -1693
  53. /package/{icon → components/ea-icon}/css/fontello-codes.css +0 -0
  54. /package/{icon → components/ea-icon}/css/fontello-embedded.css +0 -0
  55. /package/{icon → components/ea-icon}/css/fontello-ie7-codes.css +0 -0
  56. /package/{icon → components/ea-icon}/css/fontello-ie7.css +0 -0
  57. /package/{icon → components/ea-icon}/font/fontello.eot +0 -0
  58. /package/{icon → components/ea-icon}/font/fontello.ttf +0 -0
  59. /package/{icon → components/ea-icon}/font/fontello.woff +0 -0
  60. /package/{icon → components/ea-icon}/font/fontello.woff2 +0 -0
@@ -0,0 +1,212 @@
1
+ // @ts-nocheck
2
+ import Base from '../Base.js';
3
+
4
+ const stylesheet = `
5
+ .ea-tag_wrap {
6
+ display: inline-block;
7
+ height: 2rem;
8
+ line-height: 30px;
9
+ white-space: nowrap;
10
+ padding: 0 0.625rem;
11
+ border-width: 1px;
12
+ border-style: solid;
13
+ border-radius: 4px;
14
+ }
15
+ .ea-tag_wrap.ea-tag--default {
16
+ color: #409eff;
17
+ background-color: #ecf5ff;
18
+ border-color: #dcdfe6;
19
+ }
20
+ .ea-tag_wrap.ea-tag--default.ea-tag--dark {
21
+ color: #fff;
22
+ background-color: #409eff;
23
+ border-color: #409eff;
24
+ }
25
+ .ea-tag_wrap.ea-tag--default.ea-tag--plain {
26
+ color: #409eff;
27
+ background-color: #fff;
28
+ border-color: #dcdfe6;
29
+ }
30
+ .ea-tag_wrap.ea-tag--success {
31
+ color: #67c23a;
32
+ background-color: #f0f9eb;
33
+ border-color: #e1f3d8;
34
+ }
35
+ .ea-tag_wrap.ea-tag--success.ea-tag--dark {
36
+ color: #fff;
37
+ background-color: #67c23a;
38
+ border-color: #67c23a;
39
+ }
40
+ .ea-tag_wrap.ea-tag--success.ea-tag--plain {
41
+ color: #67c23a;
42
+ background-color: #fff;
43
+ border-color: #e1f3d8;
44
+ }
45
+ .ea-tag_wrap.ea-tag--info {
46
+ color: #909399;
47
+ background-color: #f4f4f5;
48
+ border-color: #e9e9eb;
49
+ }
50
+ .ea-tag_wrap.ea-tag--info.ea-tag--dark {
51
+ color: #fff;
52
+ background-color: #909399;
53
+ border-color: #909399;
54
+ }
55
+ .ea-tag_wrap.ea-tag--info.ea-tag--plain {
56
+ color: #909399;
57
+ background-color: #fff;
58
+ border-color: #e9e9eb;
59
+ }
60
+ .ea-tag_wrap.ea-tag--warning {
61
+ color: #e6a23c;
62
+ background-color: #fdf6ec;
63
+ border-color: #faecd8;
64
+ }
65
+ .ea-tag_wrap.ea-tag--warning.ea-tag--dark {
66
+ color: #fff;
67
+ background-color: #e6a23c;
68
+ border-color: #e6a23c;
69
+ }
70
+ .ea-tag_wrap.ea-tag--warning.ea-tag--plain {
71
+ color: #e6a23c;
72
+ background-color: #fff;
73
+ border-color: #faecd8;
74
+ }
75
+ .ea-tag_wrap.ea-tag--danger {
76
+ color: #f56c6c;
77
+ background-color: #fef0f0;
78
+ border-color: #fbc4c4;
79
+ }
80
+ .ea-tag_wrap.ea-tag--danger.ea-tag--dark {
81
+ color: #fff;
82
+ background-color: #f56c6c;
83
+ border-color: #f56c6c;
84
+ }
85
+ .ea-tag_wrap.ea-tag--danger.ea-tag--plain {
86
+ color: #f56c6c;
87
+ background-color: #fff;
88
+ border-color: #fbc4c4;
89
+ }
90
+ `;
91
+
92
+ const closeDom = () => {
93
+ const closeIcon = document.createElement('i');
94
+ closeIcon.className = 'icon-cancel-circled2';
95
+ closeIcon.style.cssText = `
96
+ font-size: 1rem;
97
+ margin-left: 0.5rem;
98
+ cursor: pointer;
99
+ `;
100
+
101
+ return closeIcon;
102
+ }
103
+
104
+ export class EaTag extends Base {
105
+ #wrap;
106
+ #closeSlot;
107
+ constructor() {
108
+ super();
109
+
110
+ const shadowRoot = this.attachShadow({ mode: 'open' });
111
+ const wrap = document.createElement('div');
112
+ wrap.className = 'ea-tag_wrap';
113
+
114
+ const textSlot = document.createElement('slot');
115
+ wrap.appendChild(textSlot);
116
+
117
+ const closeSlot = document.createElement('slot');
118
+ closeSlot.name = 'close';
119
+ wrap.appendChild(closeSlot);
120
+
121
+ this.#wrap = wrap;
122
+ this.#closeSlot = closeSlot;
123
+
124
+ this.build(shadowRoot, stylesheet);
125
+ this.shadowRoot.appendChild(wrap);
126
+ }
127
+
128
+ // ------- type tag类型样式 -------
129
+ // #region
130
+ get type() {
131
+ return this.getAttribute('type') || "default";
132
+ }
133
+
134
+ set type(value) {
135
+ this.setAttribute('type', value);
136
+ this.#wrap.classList.add(`ea-tag--${value}`);
137
+ }
138
+ // #endregion
139
+ // ------- end -------
140
+
141
+ // ------- closable 是否显示可关闭 -------
142
+ // #region
143
+ get closable() {
144
+ return this.getAttrBoolean('closable');
145
+ }
146
+
147
+ set closable(value) {
148
+ this.toggleAttr('closable', value);
149
+ }
150
+ // #endregion
151
+ // ------- end -------
152
+
153
+ // ------- effect 不同主题 -------
154
+ // #region
155
+ get effect() {
156
+ return this.getAttribute('effect') || "light";
157
+ }
158
+
159
+ set effect(value) {
160
+ if (value === "light") return;
161
+
162
+ this.setAttribute('effect', value);
163
+ this.#wrap.classList.add(`ea-tag--${value}`);
164
+ }
165
+ // #endregion
166
+ // ------- end -------
167
+ initCloseEvent() {
168
+ const that = this;
169
+ const closeIcon = closeDom();
170
+
171
+ closeIcon.addEventListener('mouseenter', function (e) {
172
+ closeIcon.className = 'icon-cancel-circled';
173
+ });
174
+
175
+ closeIcon.addEventListener('mouseleave', function (e) {
176
+ closeIcon.className = 'icon-cancel-circled2';
177
+ });
178
+
179
+ closeIcon.addEventListener('click', function (e) {
180
+ that.dispatchEvent(new CustomEvent('close', {
181
+ detail: {
182
+ value: that.innerText
183
+ },
184
+ bubbles: true,
185
+ }));
186
+ });
187
+
188
+ this.#closeSlot.appendChild(closeIcon);
189
+ }
190
+
191
+ init() {
192
+ const that = this;
193
+
194
+ // tag类型
195
+ this.type = this.type;
196
+
197
+ // 显示可关闭
198
+ this.closable = this.closable;
199
+ if (this.closable) this.initCloseEvent();
200
+
201
+ // 主题
202
+ this.effect = this.effect;
203
+ }
204
+
205
+ connectedCallback() {
206
+ this.init();
207
+ }
208
+ }
209
+
210
+ if (!customElements.get('ea-tag')) {
211
+ customElements.define('ea-tag', EaTag);
212
+ }
@@ -0,0 +1,333 @@
1
+ // @ts-nocheck
2
+ import Base from "../Base.js";
3
+
4
+ const stylesheet = `
5
+ .ea-textarea_wrap {
6
+ position: relative;
7
+ width: 100%;
8
+ }
9
+ .ea-textarea_wrap .ea-textarea_inner {
10
+ box-sizing: border-box;
11
+ box-shadow: none;
12
+ resize: vertical;
13
+ min-height: 1.75rem;
14
+ border: 1px solid #dcdfe6;
15
+ outline: 0;
16
+ transition: border 0.2s;
17
+ border-radius: 3px;
18
+ padding: 0.5rem;
19
+ line-height: 0.8;
20
+ font-size: 0.8rem;
21
+ scrollbar-width: none;
22
+ }
23
+ .ea-textarea_wrap .ea-textarea_inner:focus {
24
+ border-color: #409eff;
25
+ }
26
+ .ea-textarea_wrap .ea-textarea_inner::placeholder {
27
+ color: #c0c4cc;
28
+ }
29
+ .ea-textarea_wrap .ea-textarea_inner.disabled {
30
+ background-color: #eeeeee;
31
+ color: #c0c4cc;
32
+ }
33
+ .ea-textarea_wrap .ea-textarea_inner.invalid {
34
+ border-color: #f56c6c;
35
+ }
36
+ .ea-textarea_wrap .ea-input_word-limit {
37
+ position: absolute;
38
+ font-size: 0.75rem;
39
+ bottom: 0.5rem;
40
+ right: 0.5rem;
41
+ }
42
+ `;
43
+
44
+ const inputDom = () => {
45
+ let input = document.createElement('textarea');
46
+
47
+ input.className = "ea-textarea_inner";
48
+
49
+ return input;
50
+ }
51
+
52
+ export class EaTextarea extends Base {
53
+ #wrap;
54
+ #input;
55
+ #mounted = false;
56
+
57
+ constructor() {
58
+ super();
59
+
60
+ const shadowRoot = this.attachShadow({ mode: 'open' });
61
+ const wrap = document.createElement('div');
62
+ wrap.className = "ea-textarea_wrap";
63
+ this.#wrap = wrap;
64
+
65
+ const dom = inputDom();
66
+ this.#input = dom;
67
+
68
+ this.#wrap.appendChild(dom);
69
+
70
+ this.build(shadowRoot, stylesheet);
71
+ this.shadowRoot.appendChild(wrap);
72
+ }
73
+
74
+ // ------- value 输入框的值 -------
75
+ // #region
76
+ get value() {
77
+ if (!this.#mounted) {
78
+ this.#input.value = this.getAttribute("value") || '';
79
+ }
80
+
81
+ return this.getAttribute('value');
82
+ }
83
+
84
+ set value(val) {
85
+ if (!val) return;
86
+
87
+ this.setAttribute("value", val);
88
+ this.#input.value = val;
89
+ }
90
+ // #endregion
91
+ // ------- end -------
92
+
93
+ // ------- placeholder 提示 -------
94
+ // #region
95
+ get placeholder() {
96
+ return this.getAttribute("placeholder") || '';
97
+ }
98
+
99
+ set placeholder(val) {
100
+ this.setAttribute("placeholder", val);
101
+ this.#input.placeholder = val;
102
+ }
103
+ // #endregion
104
+ // ------- end -------
105
+
106
+ // ------- rows 默认行数 -------
107
+ // #region
108
+ get rows() {
109
+ return this.getAttribute("rows") || 2;
110
+ }
111
+
112
+ set rows(val) {
113
+ if (!val) return;
114
+
115
+ this.setAttribute("rows", val);
116
+ this.#input.rows = val;
117
+ this.#input.setAttribute("rows", val);
118
+ }
119
+ // #endregion
120
+ // ------- end -------
121
+
122
+ // ------- autosize 自动调整高度 -------
123
+ // #region
124
+ get autosize() {
125
+ return this.getAttrBoolean("autosize");
126
+ }
127
+
128
+ set autosize(val) {
129
+ if (!val) return;
130
+
131
+ this.setAttribute("autosize", val);
132
+
133
+ this.#input.addEventListener('input', (e) => {
134
+ if (e.target.type === 'textarea') {
135
+ const cols = this.#input.cols;
136
+ const chars = e.target.value.length;
137
+
138
+ let rows = Math.ceil(chars / cols) <= Number(this.#input.rows) ? Number(this.#input.rows) : Math.ceil(chars / cols);
139
+ if (chars % cols == 1) {
140
+ if (this.minRows > rows) this.setTextareaHeight(this.minRows);
141
+ else if (this.maxRows < rows) this.setTextareaHeight(this.maxRows);
142
+ else this.setTextareaHeight(rows);
143
+ }
144
+ }
145
+ })
146
+ }
147
+ // #endregion
148
+ // ------- end -------
149
+
150
+ // ------- min-rows/max-rows 最小/最大行数 -------
151
+ // #region
152
+
153
+ setTextareaHeight(rows) {
154
+ rows = Number(rows);
155
+ this.#input.rows = rows;
156
+ }
157
+
158
+ get minRows() {
159
+ const val = Number(this.getAttribute("min-rows"));
160
+ return val !== 0 && val > 0
161
+ ? val
162
+ : 1;
163
+ }
164
+
165
+ set minRows(val) {
166
+ if (!val) return;
167
+
168
+ this.setAttribute("min-rows", val);
169
+ this.setTextareaHeight(Number(val));
170
+ }
171
+
172
+ get maxRows() {
173
+ const val = Number(this.getAttribute("max-rows"));
174
+ return val !== 0 && val > 0
175
+ ? val
176
+ : 10;
177
+ }
178
+
179
+ set maxRows(val) {
180
+ if (!val) return;
181
+
182
+ this.setAttribute("max-rows", val);
183
+ this.setTextareaHeight(Number(val));
184
+ }
185
+
186
+ // #endregion
187
+ // ------- end -------
188
+
189
+ // ------- max-length/min-length 最大/最小字符长度 -------
190
+ // #region
191
+
192
+ // 获取最大限制值
193
+ get maxLength() {
194
+ return this.getAttribute("max-length");
195
+ }
196
+
197
+ set maxLength(val) {
198
+ if (!val) return;
199
+
200
+ this.setAttribute("max-length", val);
201
+ this.#input.maxLength = val;
202
+
203
+ this.#input.addEventListener('input', (e) => {
204
+ if (e.target.value.length > val) {
205
+ e.target.value = e.target.value.slice(0, val);
206
+ }
207
+ });
208
+
209
+ if (this.showWordLimit) this.showWordLimit = true;
210
+ }
211
+
212
+ // 获取最小限制值
213
+ get minLength() {
214
+ return this.getAttribute("min-length");
215
+ }
216
+
217
+ set minLength(val) {
218
+ if (!val) return;
219
+
220
+ this.setAttribute("min-length", val);
221
+ this.#input.minLength = val;
222
+
223
+ this.#input.addEventListener('input', (e) => {
224
+ if (e.target.value.length < val) {
225
+ e.target.classList.add('invalid');
226
+ } else {
227
+ e.target.classList.remove('invalid');
228
+ }
229
+ });
230
+ }
231
+ // #endregion
232
+ // ------- end -------
233
+
234
+ // ------- 显示 当前文字长度 和 限制值 -------
235
+ // #region
236
+
237
+ get showWordLimit() {
238
+ return this.getAttrBoolean("show-word-limit");
239
+ }
240
+
241
+ set showWordLimit(val) {
242
+ if (!val) return;
243
+
244
+ this.setAttribute("show-word-limit", val);
245
+
246
+ // 加入显示的dom
247
+ const wordLimit = document.createElement('span');
248
+ this.#wrap.classList.toggle('word-limit', val);
249
+ this.#wrap.classList.toggle('append-slot', val);
250
+ wordLimit.className = 'ea-input_word-limit';
251
+ wordLimit.innerText = `${this.#input.value.length}/${this.maxLength}`;
252
+
253
+
254
+ this.#input.addEventListener('input', (e) => {
255
+ wordLimit.innerText = `${e.target.value.length}/${this.maxLength}`;
256
+ });
257
+
258
+ this.#wrap.appendChild(wordLimit);
259
+ wordLimit.style.left = (this.#input.getBoundingClientRect().width - wordLimit.getBoundingClientRect().width - 5) + 'px';
260
+ }
261
+ // #endregion
262
+ // ------- end -------
263
+
264
+
265
+ init() {
266
+ const that = this;
267
+
268
+ // 输入框提示
269
+ this.placeholder = this.placeholder;
270
+
271
+ // 输入框的值
272
+ this.value = this.value;
273
+
274
+ // 禁用
275
+ this.disabled = this.disabled;
276
+
277
+ // 自动调整高度
278
+ this.autosize = this.autosize;
279
+
280
+ // 最大最小行数
281
+ if (this.maxRows) this.maxRows = this.maxRows;
282
+ if (this.minRows) this.minRows = this.minRows;
283
+
284
+ // 默认行数
285
+ this.rows = this.rows;
286
+
287
+ // 输入长度限制
288
+ this.maxLength = this.maxLength;
289
+ this.minLength = this.minLength;
290
+
291
+ // 输入时
292
+ this.#input.addEventListener("input", (e) => {
293
+ this.dispatchEvent(
294
+ new CustomEvent("change", {
295
+ detail: {
296
+ value: e.target.value
297
+ }
298
+ })
299
+ );
300
+ });
301
+
302
+ // 聚焦时
303
+ this.#input.addEventListener("focus", (e) => {
304
+ this.dispatchEvent(
305
+ new CustomEvent("focus", {
306
+ detail: {
307
+ value: e.target.value
308
+ }
309
+ })
310
+ );
311
+ });
312
+
313
+ // 失焦时
314
+ this.#input.addEventListener("blur", (e) => {
315
+ this.dispatchEvent(
316
+ new CustomEvent("blur", {
317
+ detail: {
318
+ value: e.target.value
319
+ }
320
+ })
321
+ );
322
+ });
323
+ }
324
+
325
+ connectedCallback() {
326
+ this.init();
327
+ this.#mounted = true;
328
+ }
329
+ }
330
+
331
+ if (!window.customElements.get("ea-textarea")) {
332
+ window.customElements.define("ea-textarea", EaTextarea);
333
+ }