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.
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,326 @@
1
+ // @ts-nocheck
2
+ import Base from '../Base.js';
3
+ import "../ea-icon/index.js"
4
+
5
+ const stylesheet = `
6
+ :host {
7
+ --i-color: rgb(247, 186, 42);
8
+ }
9
+ .ea-rate_wrap {
10
+ --i-color: rgb(247, 186, 42);
11
+ position: relative;
12
+ display: flex;
13
+ align-items: center;
14
+ }
15
+ .ea-rate_wrap .ea-rate_item {
16
+ cursor: pointer;
17
+ width: 24px;
18
+ height: 24px;
19
+ }
20
+ .ea-rate_wrap .ea-rate_item > i {
21
+ color: #c0c4cc;
22
+ font-size: 1rem;
23
+ line-height: 1;
24
+ transition: color 0.3s, font-size 0.1s;
25
+ }
26
+ .ea-rate_wrap .ea-rate_item.ea-rate_item--active > i {
27
+ color: var(--i-color);
28
+ font-size: 1.1rem;
29
+ }
30
+ .ea-rate_wrap .ea-rate_item.ea-rate_item--disabled {
31
+ pointer-events: none;
32
+ cursor: default;
33
+ }
34
+ .ea-rate_wrap .ea-rate_text {
35
+ margin-left: 0.25rem;
36
+ min-width: 2rem;
37
+ font-size: 0.8rem;
38
+ line-height: 0.8;
39
+ vertical-align: middle;
40
+ }
41
+ .ea-rate_wrap .ea-rate_score {
42
+ position: absolute;
43
+ left: 0;
44
+ top: 0;
45
+ }
46
+ .ea-rate_wrap .ea-rate_score .ea-rate_score_item {
47
+ width: 24px;
48
+ height: 24px;
49
+ }
50
+ .ea-rate_wrap .ea-rate_score .ea-rate_score_item > i {
51
+ color: #c0c4cc;
52
+ font-size: 1rem;
53
+ line-height: 1;
54
+ }
55
+ `;
56
+
57
+ const rateDom = (index) => {
58
+ const dom = document.createElement('span');
59
+ dom.className = 'ea-rate_item';
60
+ dom.setAttribute('data-index', index);
61
+
62
+ const icon = document.createElement('i');
63
+ icon.className = 'icon-star-empty';
64
+
65
+ dom.appendChild(icon);
66
+
67
+ return dom;
68
+ }
69
+
70
+
71
+ export class EaRate extends Base {
72
+ #mounted = false;
73
+ #wrap;
74
+ #appendSlot;
75
+ #textList = ["极差", "失望", "一般", "满意", "惊喜"];
76
+
77
+ static get observedAttributes() {
78
+ return ['value'];
79
+ }
80
+
81
+ constructor() {
82
+ super();
83
+
84
+ const shadowRoot = this.attachShadow({ mode: 'open' });
85
+ const wrap = document.createElement('div');
86
+ wrap.className = 'ea-rate_wrap';
87
+
88
+ for (let i = 0; i < 5; i++) {
89
+ const dom = rateDom(i);
90
+
91
+ wrap.appendChild(dom);
92
+ }
93
+
94
+ const text = document.createElement('span');
95
+ text.className = 'ea-rate_text';
96
+ wrap.appendChild(text);
97
+
98
+ this.#wrap = wrap;
99
+ this.#appendSlot = text;
100
+
101
+ this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
102
+
103
+ this.build(shadowRoot, stylesheet);
104
+ this.shadowRoot.appendChild(wrap);
105
+ }
106
+
107
+ // 设置/显示选中状态
108
+ setCheckedStatus(index) {
109
+ const item = this.#wrap.querySelectorAll('.ea-rate_item');
110
+
111
+ for (let i = 0; i < index; i++) {
112
+ item[i].classList.add('ea-rate_item--active');
113
+ item[i].querySelector('i').className = this.activeIconClass;
114
+
115
+ if (this.showText) {
116
+ this.#appendSlot.innerText = this.showTextList[index - 1];
117
+ }
118
+ }
119
+ }
120
+
121
+ // 当未选中时, 清除选中状态
122
+ clearCheckedStatus() {
123
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(item => {
124
+ item.classList.remove('ea-rate_item--active');
125
+ item.querySelector('i').className = this.voidIconClass;
126
+
127
+ if (this.showText) {
128
+ const text = this.#wrap.querySelector('.ea-rate_text');
129
+ text.innerText = "";
130
+ }
131
+ })
132
+ }
133
+
134
+ // ------- value 当前选中值 -------
135
+ // #region
136
+ get value() {
137
+ const value = this.getAttrNumber('value') || 0;
138
+
139
+ if (value < 1 || value > 5 || !value) return 0;
140
+ else return Number(value);
141
+ }
142
+
143
+ set value(val) {
144
+ val = Number(val);
145
+
146
+ this.setAttribute('value', val);
147
+
148
+ this.clearCheckedStatus();
149
+
150
+ this.setCheckedStatus(val);
151
+ }
152
+
153
+ // #endregion
154
+ // ------- end -------
155
+
156
+ // ------- color 颜色 -------
157
+ // #region
158
+ get color() {
159
+ return this.getAttribute('color') || 'rgb(247, 186, 42)';
160
+ }
161
+
162
+ set color(val) {
163
+ this.setAttribute('color', val);
164
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(item => {
165
+ item.querySelector('i').style.setProperty('--i-color', val);
166
+ })
167
+ }
168
+ // #endregion
169
+ // ------- end -------
170
+
171
+ // ------- show-text 显示文本 -------
172
+ // #region
173
+
174
+ get showText() {
175
+ return this.getAttrBoolean('show-text');
176
+ }
177
+
178
+ set showText(val) {
179
+ this.toggleAttr('show-text', val);
180
+ }
181
+
182
+ get showTextList() {
183
+ return this.#textList;
184
+ }
185
+
186
+ set showTextList(val) {
187
+ if (typeof val === "object" && val.length === 5) this.#textList = val;
188
+ }
189
+ // #endregion
190
+ // ------- end -------
191
+
192
+ // ------- void-icon-class 自定空图标样式类 -------
193
+ // #region
194
+ get voidIconClass() {
195
+ return this.getAttribute('void-icon-class') || 'icon-star-empty';
196
+ }
197
+
198
+ set voidIconClass(val) {
199
+ this.setAttribute('void-icon-class', val);
200
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(item => {
201
+ item.querySelector('i').className = val;
202
+ })
203
+ }
204
+ // #endregion
205
+ // ------- end -------
206
+
207
+ // ------- active-icon-class 自定图标样式类 -------
208
+ // #region
209
+ get activeIconClass() {
210
+ return this.getAttribute('active-icon-class') || 'icon-star';
211
+ }
212
+
213
+ set activeIconClass(val) {
214
+ this.setAttribute('active-icon-class', val);
215
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(item => {
216
+ item.querySelector('i').className = val;
217
+ })
218
+ }
219
+ // #endregion
220
+ // ------- end -------
221
+
222
+ // ------- disabled 禁用 -------
223
+ // #region
224
+ get disabled() {
225
+ return this.getAttrBoolean('disabled');
226
+ }
227
+
228
+ set disabled(val) {
229
+ this.toggleAttr('disabled', val);
230
+
231
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(item => {
232
+ item.classList.toggle('ea-rate_item--disabled', val);
233
+ })
234
+ }
235
+ // #endregion
236
+ // ------- end -------
237
+
238
+ // 初始化鼠标事件
239
+ initRateEvent() {
240
+ const that = this;
241
+
242
+ this.#wrap.querySelectorAll('.ea-rate_item').forEach(dom => {
243
+
244
+ // 鼠标移入: 显示选中状态
245
+ dom.addEventListener('mouseenter', function (e) {
246
+ const index = Number(this.getAttribute('data-index'));
247
+
248
+ that.clearCheckedStatus();
249
+ that.setCheckedStatus(index + 1);
250
+
251
+ that.dispatchEvent(new CustomEvent("hover", {
252
+ detail: {
253
+ value: index + 1,
254
+ rateText: that.#textList[index]
255
+ }
256
+ }));
257
+ })
258
+
259
+ // 鼠标移出: 清除选中状态
260
+ dom.addEventListener('mouseleave', function (e) {
261
+ that.clearCheckedStatus();
262
+
263
+ that.setCheckedStatus(that.value);
264
+ })
265
+
266
+ // 点击: 设置选中状态
267
+ dom.addEventListener('click', function (e) {
268
+ const index = Number(this.getAttribute('data-index'));
269
+
270
+ that.value = index + 1;
271
+ that.dispatchEvent(new CustomEvent("change", {
272
+ detail: {
273
+ value: index + 1,
274
+ rateText: that.#textList[index]
275
+ }
276
+ }))
277
+ })
278
+ })
279
+ }
280
+
281
+ init() {
282
+ const that = this;
283
+
284
+ // icon-class 自定图标样式类初始化
285
+ this.activeIconClass = this.activeIconClass;
286
+
287
+ // void-icon-class 自定空图标样式类初始化
288
+ this.voidIconClass = this.voidIconClass;
289
+
290
+ // show-text 显示文本初始化
291
+ this.showText = this.showText;
292
+
293
+ // color 颜色初始化
294
+ this.color = this.color;
295
+
296
+ // value 星级初始化
297
+ this.value = this.value;
298
+
299
+ // disabled 禁用初始化
300
+ this.disabled = this.disabled;
301
+
302
+ // 初始化鼠标事件
303
+ if (!this.disabled) this.initRateEvent();
304
+ }
305
+
306
+ connectedCallback() {
307
+ this.init();
308
+
309
+ this.#mounted = true;
310
+ }
311
+
312
+ attributeChangedCallback(name, oldVal, newVal) {
313
+ if (!this.#mounted) return;
314
+
315
+ if (name == "value") {
316
+
317
+ this.clearCheckedStatus();
318
+
319
+ this.setCheckedStatus(newVal);
320
+ }
321
+ }
322
+ }
323
+
324
+ if (!customElements.get('ea-rate')) {
325
+ customElements.define('ea-rate', EaRate);
326
+ }
@@ -0,0 +1,167 @@
1
+ // @ts-nocheck
2
+ import { createElement, createSlotElement } from '../../utils/createElement.js';
3
+ import { handleTemplate } from '../../utils/handleTemplate.js';
4
+ import Base from '../Base.js';
5
+ import "../ea-icon/index.js"
6
+
7
+ const stylesheet = `
8
+ .ea-result_wrap {
9
+ display: flex;
10
+ flex-direction: column;
11
+ justify-content: center;
12
+ align-items: center;
13
+ box-sizing: border-box;
14
+ padding: 40px 30px;
15
+ }
16
+ .ea-result_wrap .ea-result_icon {
17
+ font-size: 3rem;
18
+ }
19
+ .ea-result_wrap .ea-result_icon i[class=icon-ok-circled] {
20
+ color: #67c23a;
21
+ }
22
+ .ea-result_wrap .ea-result_icon i[class=icon-cancel-circled] {
23
+ color: #f56c6c;
24
+ }
25
+ .ea-result_wrap .ea-result_icon i[class=icon-attention-alt] {
26
+ color: #e6a23c;
27
+ }
28
+ .ea-result_wrap .ea-result_icon i[class=icon-info] {
29
+ color: #909399;
30
+ }
31
+ .ea-result_wrap .ea-result_title,
32
+ .ea-result_wrap .ea-result_subtitle {
33
+ color: #5e6d82;
34
+ font-size: 14px;
35
+ }
36
+ .ea-result_wrap .ea-result_title {
37
+ margin-top: 20px;
38
+ }
39
+ .ea-result_wrap .ea-result_subtitle {
40
+ margin-top: 10px;
41
+ }
42
+ .ea-result_wrap .ea-result_extra {
43
+ margin-top: 30px;
44
+ }
45
+ `;
46
+
47
+ export class EaResult extends Base {
48
+ #wrap;
49
+
50
+ #resultIcon;
51
+ #resultTitle;
52
+ #resultSubtitle;
53
+ #resultExtraWrap;
54
+
55
+ #resultIconSlot;
56
+ #resultTitleSlot;
57
+ #resultSubtitleSlot;
58
+ #resultExtraSlot;
59
+
60
+ constructor() {
61
+ super();
62
+
63
+ const shadowRoot = this.attachShadow({ mode: 'open' });
64
+ const wrap = document.createElement('div');
65
+ wrap.className = 'ea-result_wrap';
66
+
67
+ const iconWrap = createElement('div', 'ea-result_icon');
68
+ wrap.appendChild(iconWrap);
69
+
70
+ const resultTitle = createElement('div', 'ea-result_title');
71
+ wrap.appendChild(resultTitle);
72
+
73
+ const resultSubtitle = createElement('div', 'ea-result_subtitle');
74
+ wrap.appendChild(resultSubtitle);
75
+
76
+ const resultExtraWrap = createElement('div', 'ea-result_extra');
77
+ wrap.appendChild(resultExtraWrap);
78
+
79
+ const resultIconSlot = createSlotElement('icon');
80
+ const resultTitleSlot = createSlotElement('title');
81
+ const resultSubtitleSlot = createSlotElement('subTitle');
82
+ const resultExtraSlot = createSlotElement('extra');
83
+
84
+ this.#wrap = wrap;
85
+ this.#resultIcon = iconWrap;
86
+ this.#resultTitle = resultTitle;
87
+ this.#resultSubtitle = resultSubtitle;
88
+ this.#resultExtraWrap = resultExtraWrap;
89
+
90
+ this.#resultIconSlot = resultIconSlot;
91
+ this.#resultTitleSlot = resultTitleSlot;
92
+ this.#resultSubtitleSlot = resultSubtitleSlot;
93
+ this.#resultExtraSlot = resultExtraSlot;
94
+
95
+ this.build(shadowRoot, stylesheet);
96
+ this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
97
+ this.shadowRoot.appendChild(wrap);
98
+
99
+ shadowRoot.appendChild(resultIconSlot);
100
+ shadowRoot.appendChild(resultTitleSlot);
101
+ shadowRoot.appendChild(resultSubtitleSlot);
102
+ shadowRoot.appendChild(resultExtraSlot);
103
+ }
104
+
105
+ // ------- icon 设置自定义icon -------
106
+ // #region
107
+ get icon() {
108
+ return this.getAttribute('icon') || '';
109
+ }
110
+
111
+ set icon(value) {
112
+ this.setAttribute('icon', value);
113
+
114
+ this.#resultIcon.innerHTML = `<i class="${value}"></i>`;
115
+ }
116
+ // #endregion
117
+ // ------- end -------
118
+
119
+ // ------- title 设置标题 -------
120
+ // #region
121
+ get title() {
122
+ return this.getAttribute('title') || '';
123
+ }
124
+
125
+ set title(value) {
126
+ this.setAttribute('title', value);
127
+
128
+ this.#resultTitle.innerText = value;
129
+ }
130
+ // #endregion
131
+ // ------- end -------
132
+
133
+ // ------- sub-title 设置副标题 -------
134
+ // #region
135
+ get subtitle() {
136
+ return this.getAttribute('sub-title') || '';
137
+ }
138
+
139
+ set subtitle(value) {
140
+ this.setAttribute('sub-title', value);
141
+
142
+ this.#resultSubtitle.innerText = value;
143
+ }
144
+ // #endregion
145
+ // ------- end -------
146
+
147
+ init() {
148
+ const that = this;
149
+
150
+ this.icon = this.icon;
151
+ this.title = this.title;
152
+ this.subtitle = this.subtitle;
153
+
154
+ handleTemplate(this, "icon", this.#resultIcon, this.#resultIconSlot);
155
+ handleTemplate(this, "title", this.#resultTitle, this.#resultTitleSlot);
156
+ handleTemplate(this, "subTitle", this.#resultSubtitle, this.#resultSubtitleSlot);
157
+ handleTemplate(this, "extra", this.#resultExtraWrap, this.#resultExtraSlot);
158
+ }
159
+
160
+ connectedCallback() {
161
+ this.init();
162
+ }
163
+ }
164
+
165
+ if (!customElements.get('ea-result')) {
166
+ customElements.define('ea-result', EaResult);
167
+ }
@@ -0,0 +1,34 @@
1
+ import Base from '../Base';
2
+
3
+ const stylesheet = `
4
+ @import url('/ea_ui_component/icon/index.css');
5
+ `;
6
+
7
+ export class EaSelect extends Base {
8
+ #wrap;
9
+ constructor() {
10
+ super();
11
+
12
+ const shadowRoot = this.attachShadow({ mode: 'open' });
13
+ this.shadowRoot = shadowRoot;
14
+ const wrap = document.createElement('div');
15
+ wrap.className = 'ea-select_wrap';
16
+
17
+ this.#wrap = wrap;
18
+
19
+ this.build(shadowRoot, stylesheet);
20
+ this.shadowRoot.appendChild(wrap);
21
+ }
22
+
23
+ init() {
24
+ const that = this;
25
+ }
26
+
27
+ connectedCallback() {
28
+ this.init();
29
+ }
30
+ }
31
+
32
+ if (!window.customElements.get("ea-select")) {
33
+ window.customElements.define("ea-select", EaSelect);
34
+ }