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,434 @@
1
+ // @ts-nocheck
2
+ import Base from '../Base.js';
3
+ import { createElement, createSlotElement } from "../../utils/createElement.js"
4
+
5
+ const stylesheet = `
6
+ .ea-carousel_wrap {
7
+ position: relative;
8
+ }
9
+ .ea-carousel_wrap.ea-carousel--horizontal {
10
+ overflow-x: hidden;
11
+ }
12
+ .ea-carousel_wrap .ea-carousel_container {
13
+ position: relative;
14
+ color: #fff;
15
+ text-align: center;
16
+ height: 300px;
17
+ transition: transform 0.5s;
18
+ }
19
+ .ea-carousel_wrap .ea-carousel-item_arrow {
20
+ position: absolute;
21
+ top: 50%;
22
+ transform: translateY(-50%);
23
+ opacity: 0;
24
+ width: 1.5rem;
25
+ height: 1.5rem;
26
+ line-height: 1.5;
27
+ text-align: center;
28
+ border-radius: 50%;
29
+ background-color: rgba(31, 45, 61, 0.11);
30
+ color: #fff;
31
+ cursor: pointer;
32
+ user-select: none;
33
+ transition: background-color 0.3s, transform 0.3s, opacity 0.3s;
34
+ }
35
+ .ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--left {
36
+ left: 0;
37
+ transform: translate(-100%, -50%);
38
+ }
39
+ .ea-carousel_wrap .ea-carousel-item_arrow.ea-carousel-item_arrow--right {
40
+ right: 0;
41
+ transform: translate(100%, -50%);
42
+ }
43
+ .ea-carousel_wrap .ea-carousel-item_arrow:hover {
44
+ background-color: rgba(31, 45, 61, 0.3);
45
+ }
46
+ .ea-carousel_wrap .ea-carousel-indicator_wrap {
47
+ position: absolute;
48
+ bottom: 1rem;
49
+ left: 50%;
50
+ transform: translateX(-50%);
51
+ display: flex;
52
+ align-items: center;
53
+ cursor: pointer;
54
+ }
55
+ .ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator {
56
+ width: 0.5rem;
57
+ height: 0.5rem;
58
+ border-radius: 50%;
59
+ background-color: rgba(255, 255, 255, 0.4);
60
+ margin: 0 0.25rem;
61
+ transition: background-color 0.3s;
62
+ }
63
+ .ea-carousel_wrap .ea-carousel-indicator_wrap .ea-carousel-item_indicator.ea-carousel-item_indicator--active {
64
+ background-color: #fff;
65
+ }
66
+
67
+ :host {
68
+ --odd-bgc: #d3dce6;
69
+ }
70
+
71
+ .ea-carousel-item_wrap {
72
+ display: inline-block;
73
+ position: absolute;
74
+ top: 0;
75
+ left: 0;
76
+ width: 100%;
77
+ height: 100%;
78
+ overflow: hidden;
79
+ z-index: 0;
80
+ background-color: var(--odd-bgc);
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ }
85
+ .ea-carousel-item_wrap ::slotted(img) {
86
+ width: 100%;
87
+ height: 100%;
88
+ object-fit: cover;
89
+ }
90
+ `;
91
+
92
+ export class EaCarousel extends Base {
93
+ #wrap;
94
+
95
+ #container;
96
+
97
+ #indicatorWrap;
98
+
99
+ #timer = null;
100
+
101
+ constructor() {
102
+ super();
103
+
104
+ const shadowRoot = this.attachShadow({ mode: 'open' });
105
+ const wrap = document.createElement('div');
106
+ wrap.className = 'ea-carousel_wrap';
107
+
108
+ const carouselSlot = createSlotElement('');
109
+ const container = createElement('div', 'ea-carousel_container', [carouselSlot]);
110
+ wrap.appendChild(container);
111
+
112
+ const indicatorWrap = createElement('div', 'ea-carousel-indicator_wrap');
113
+ wrap.appendChild(indicatorWrap);
114
+
115
+ this.#wrap = wrap;
116
+ this.#container = container;
117
+ this.#indicatorWrap = indicatorWrap;
118
+
119
+ this.build(shadowRoot, stylesheet);
120
+ this.shadowRoot.appendChild(wrap);
121
+ }
122
+
123
+ // ------- direction 轮播图方向 -------
124
+ // #region
125
+ get direction() {
126
+ const direction = this.getAttribute('direction');
127
+ return ["horizontal", "vertical"].includes(direction) ? direction : "horizontal";
128
+ }
129
+
130
+ set direction(value) {
131
+ this.setAttribute('direction', value);
132
+
133
+ this.#wrap.classList.add(`ea-carousel--${value}`);
134
+ }
135
+ // #endregion
136
+ // ------- end -------
137
+
138
+ // ------- index 轮播图索引 -------
139
+ // #region
140
+ get index() {
141
+ return this.getAttrNumber('index') || 0;
142
+ }
143
+
144
+ set index(value) {
145
+ const index = this.#handleIndexOverflow(value);
146
+
147
+ this.setAttribute('index', index);
148
+
149
+ this.#container.style.transform = `translateX(-${index * this.#container.getBoundingClientRect().width}px)`;
150
+
151
+ try {
152
+ const indicators = this.#indicatorWrap.querySelectorAll(`.ea-carousel-item_indicator`);
153
+ indicators.forEach(item => {
154
+ item.classList.remove('ea-carousel-item_indicator--active');
155
+ });
156
+ indicators[index].classList.add('ea-carousel-item_indicator--active');
157
+ } catch (e) { }
158
+ }
159
+ // #endregion
160
+ // ------- end -------
161
+
162
+ // ------- trigger 轮播图指示器触发方式 -------
163
+ // #region
164
+ get trigger() {
165
+ const trigger = this.getAttribute('trigger') || "hover";
166
+ return ["click", "hover"].includes(trigger) ? trigger : "click";
167
+ }
168
+
169
+ set trigger(value) {
170
+ this.setAttribute('trigger', value);
171
+ }
172
+ // #endregion
173
+ // ------- end -------
174
+
175
+ // ------- interval 轮播图自动播放间隔时间 -------
176
+ // #region
177
+ get interval() {
178
+ return this.getAttrNumber('interval') || 3;
179
+ }
180
+
181
+ set interval(value) {
182
+ this.setAttribute('interval', value);
183
+ }
184
+ // #endregion
185
+ // ------- end -------
186
+
187
+ // ------- arrow 轮播图是否一直显示箭头 -------
188
+ // #region
189
+ get arrow() {
190
+ const arrow = this.getAttribute('arrow') || "hover";
191
+ return ["always", "hover", "never"].includes(arrow) ? arrow : "hover";
192
+ }
193
+
194
+ set arrow(value) {
195
+ this.setAttribute('arrow', value);
196
+ }
197
+ // #endregion
198
+ // ------- end -------
199
+
200
+ /**
201
+ * 处理索引溢出问题
202
+ * @param {number} val - 需要检查和调整的索引值
203
+ * @returns {number} - 调整后的合法索引值
204
+ */
205
+ #handleIndexOverflow(val) {
206
+ // 获取容器孩子的数量
207
+ const length = this.querySelectorAll('ea-carousel-item').length - 1;
208
+
209
+ // 如果索引值小于0,将其设置为最后一个索引
210
+ if (val < 0) {
211
+ val = length;
212
+ // 如果索引值大于孩子数量,将其设置为第一个索引
213
+ } else if (val > length) {
214
+ val = 0;
215
+ }
216
+
217
+ // 返回调整后的索引值
218
+ return val;
219
+ }
220
+
221
+ /**
222
+ * 初始化轮播项的位置和样式。
223
+ */
224
+ #initCarouselItem() {
225
+ // 获取所有轮播项元素
226
+ const items = this.querySelectorAll('ea-carousel-item');
227
+
228
+ // 遍历每个轮播项
229
+ items.forEach((item, index) => {
230
+ // 延迟执行,创建动画效果的延迟
231
+ setTimeout(() => {
232
+ // 如果是奇数索引,设置特殊的背景色
233
+ if (index % 2 === 1) {
234
+ item.style.setProperty('--odd-bgc', '#99a9bf');
235
+ }
236
+ // 计算并设置轮播项的初始位置
237
+ item.translate = index * this.#wrap.getBoundingClientRect().width;
238
+ }, 20);
239
+ });
240
+ }
241
+
242
+ /**
243
+ * 初始化轮播指示器
244
+ */
245
+ #initIndicators() {
246
+ const that = this;
247
+
248
+ // 获取所有轮播项元素
249
+ const items = this.querySelectorAll('ea-carousel-item');
250
+ items.forEach((item, index) => {
251
+ const indicator = createElement('div', 'ea-carousel-item_indicator');
252
+ this.#indicatorWrap.appendChild(indicator);
253
+ });
254
+
255
+ // 遍历每个指示器
256
+ const indicators = this.#indicatorWrap.querySelectorAll('.ea-carousel-item_indicator');
257
+ indicators.forEach((indicator, index) => {
258
+ indicator.addEventListener(this.trigger === 'click' ? 'click' : 'mouseenter', () => {
259
+ that.index = index;
260
+
261
+ indicators.forEach((item) => {
262
+ item.classList.remove('ea-carousel-item_active');
263
+ })
264
+ indicator.classList.add('ea-carousel-item_active');
265
+ })
266
+ });
267
+ }
268
+
269
+
270
+ /**
271
+ * 创建箭头项
272
+ * @param {string} arrow - 箭头方向,"left" 或 "right"
273
+ * @param {string} show - 箭头显示的时机,"always"、"hover" 或 "never"
274
+ * @returns {HTMLElement} - 创建的箭头元素
275
+ *
276
+ * 该函数用于创建轮播图的左右箭头元素,并设置其初始状态和点击事件。
277
+ * 箭头元素的样式和位置会在鼠标进入和离开时动态改变。
278
+ */
279
+ #createArrowItem(arrow, show) {
280
+ // 保持当前对象的引用
281
+ const that = this;
282
+ // 创建箭头元素,并根据方向添加相应的类名
283
+ const arrowItem = createElement('div', `ea-carousel-item_arrow ea-carousel-item_arrow--${arrow}`);
284
+ // 根据箭头方向设置箭头的HTML内容
285
+ arrowItem.innerHTML = arrow === "left" ? `&lt;` : `&gt;`;
286
+
287
+ switch (show) {
288
+ case "always":
289
+ // 如果显示时机为“总是”,则设置箭头的初始位置和透明度
290
+ arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? 1 : -1}rem)`;
291
+ arrowItem.style.opacity = 1;
292
+ break;
293
+ case "hover":
294
+ // 当鼠标进入箭头元素时,改变其位置和透明度
295
+ this.#wrap.addEventListener('mouseenter', (e) => {
296
+ arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? 1 : -1}rem)`;
297
+ arrowItem.style.opacity = 1;
298
+ })
299
+
300
+ // 当鼠标离开箭头元素时,恢复其初始位置和透明度
301
+ this.#wrap.addEventListener('mouseleave', (e) => {
302
+ arrowItem.style.transform = `translateY(-50%) translateX(${arrow === "left" ? -100 : 100}%)`;
303
+ arrowItem.style.opacity = 0;
304
+ })
305
+ break;
306
+ }
307
+
308
+ // 绑定点击事件,根据箭头方向改变轮播图的索引
309
+ arrowItem.addEventListener('click', (e) => {
310
+ that.index = arrow === "left" ? --that.index : ++that.index;
311
+ })
312
+
313
+ // 返回创建的箭头元素
314
+ return arrowItem;
315
+ }
316
+
317
+ /**
318
+ * 初始化箭头项
319
+ * 该方法用于创建并添加左右两个箭头项到指定的包装元素中。
320
+ * 这两个箭头项分别代表向左和向右的导航功能。
321
+ *
322
+ * @private
323
+ */
324
+ #initArrowItem(show) {
325
+ if (show === "never") return;
326
+
327
+ // 创建一个向左的箭头项
328
+ const leftArrowItem = this.#createArrowItem("left", show);
329
+ // 创建一个向右的箭头项
330
+ const rightArrowItem = this.#createArrowItem("right", show);
331
+
332
+ // 将左箭头项添加到包装元素中
333
+ this.#wrap.appendChild(leftArrowItem);
334
+ // 将右箭头项添加到包装元素中
335
+ this.#wrap.appendChild(rightArrowItem);
336
+ }
337
+
338
+ /**
339
+ * 初始化轮播图自动播放功能。
340
+ * @param {number} duration - 每张图片展示的时间间隔,单位为秒。
341
+ */
342
+ #initCarouselAutoPlay(duration) {
343
+ // 保存当前上下文的引用
344
+ const that = this;
345
+ // 设置定时器,每隔一定时间自动切换到下一张图片
346
+ this.#timer = setInterval(() => {
347
+ this.index = this.index + 1;
348
+ }, duration * 1000);
349
+
350
+ // 当鼠标进入轮播图区域时,停止自动播放
351
+ this.addEventListener('mouseenter', () => {
352
+ clearInterval(this.#timer);
353
+ that.#timer = null;
354
+ });
355
+
356
+ // 当鼠标离开轮播图区域时,恢复自动播放
357
+ this.addEventListener('mouseleave', () => {
358
+ that.#timer = setInterval(() => {
359
+ this.index = this.index + 1;
360
+ }, duration * 1000)
361
+ });
362
+ }
363
+
364
+ init() {
365
+ const that = this;
366
+
367
+ this.direction = this.direction;
368
+
369
+ this.trigger = this.trigger;
370
+
371
+ this.interval = this.interval;;
372
+
373
+ this.arrow = this.arrow;
374
+
375
+ this.#initCarouselItem();
376
+ this.#initArrowItem(this.arrow);
377
+ this.#initIndicators(this.interval);
378
+ this.#initCarouselAutoPlay(this.interval);
379
+
380
+ this.index = this.index;
381
+ }
382
+
383
+ connectedCallback() {
384
+ this.init();
385
+ }
386
+ }
387
+
388
+ export class EaCarouselItem extends Base {
389
+ #wrap;
390
+ constructor() {
391
+ super();
392
+
393
+ const shadowRoot = this.attachShadow({ mode: 'open' });
394
+ const wrap = document.createElement('div');
395
+ wrap.className = 'ea-carousel-item_wrap';
396
+
397
+ const carouselSlot = createSlotElement('');
398
+ wrap.appendChild(carouselSlot);
399
+
400
+ this.#wrap = wrap;
401
+
402
+ this.build(shadowRoot, stylesheet);
403
+ this.shadowRoot.appendChild(wrap);
404
+ }
405
+
406
+ // ------- translate 图片偏移 -------
407
+ // #region
408
+ get translate() {
409
+ return this.getAttribute('translate') || 0;
410
+ }
411
+
412
+ set translate(value) {
413
+ this.setAttribute('translate', value);
414
+
415
+ this.#wrap.style.transform = `translateX(${value}px) scale(1)`;
416
+ }
417
+ // #endregion
418
+ // ------- end -------
419
+
420
+ init() {
421
+ const that = this;
422
+ }
423
+
424
+ connectedCallback() {
425
+ this.init();
426
+ }
427
+ }
428
+
429
+ if (!customElements.get('ea-carousel')) {
430
+ customElements.define('ea-carousel', EaCarousel);
431
+ }
432
+ if (!customElements.get('ea-carousel-item')) {
433
+ customElements.define('ea-carousel-item', EaCarouselItem);
434
+ }