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,333 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
import "../ea-icon/index.js"
|
|
4
|
+
|
|
5
|
+
const stylesheet = `
|
|
6
|
+
.ea-progress_wrap {
|
|
7
|
+
position: relative;
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
width: 100%;
|
|
11
|
+
line-height: 1;
|
|
12
|
+
height: 1rem;
|
|
13
|
+
}
|
|
14
|
+
.ea-progress_wrap .ea-progress_track,
|
|
15
|
+
.ea-progress_wrap .ea-progress_path {
|
|
16
|
+
height: 0.5rem;
|
|
17
|
+
line-height: 1;
|
|
18
|
+
background-color: rgb(235, 238, 245);
|
|
19
|
+
border-radius: 999px;
|
|
20
|
+
}
|
|
21
|
+
.ea-progress_wrap .ea-progress_track {
|
|
22
|
+
width: 100%;
|
|
23
|
+
}
|
|
24
|
+
.ea-progress_wrap .ea-progress_track .ea-progress_path {
|
|
25
|
+
box-sizing: border-box;
|
|
26
|
+
padding-right: 0.5rem;
|
|
27
|
+
color: aliceblue;
|
|
28
|
+
font-size: 0.8rem;
|
|
29
|
+
text-align: right;
|
|
30
|
+
width: 0%;
|
|
31
|
+
background-color: #409eff;
|
|
32
|
+
transition: width 0.2s;
|
|
33
|
+
}
|
|
34
|
+
.ea-progress_wrap .ea-progress_text {
|
|
35
|
+
margin-left: 0.5rem;
|
|
36
|
+
font-size: 0.8rem;
|
|
37
|
+
width: 3rem;
|
|
38
|
+
}
|
|
39
|
+
.ea-progress_wrap .ea-progress_text--circle,
|
|
40
|
+
.ea-progress_wrap .ea-progress_text--dashboard {
|
|
41
|
+
position: absolute;
|
|
42
|
+
left: 50%;
|
|
43
|
+
top: 50%;
|
|
44
|
+
transform: translate(-50%, -50%);
|
|
45
|
+
}
|
|
46
|
+
.ea-progress_wrap svg circle {
|
|
47
|
+
stroke-width: 4px;
|
|
48
|
+
transform-origin: center center;
|
|
49
|
+
transition: stroke-dashoffset 0.2s;
|
|
50
|
+
}
|
|
51
|
+
.ea-progress_wrap svg .track--circle,
|
|
52
|
+
.ea-progress_wrap svg .path--circle {
|
|
53
|
+
transform: rotate(-90deg);
|
|
54
|
+
}
|
|
55
|
+
.ea-progress_wrap svg .track--dashboard,
|
|
56
|
+
.ea-progress_wrap svg .path--dashboard {
|
|
57
|
+
transform: rotate(161deg);
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const SVGTemplate = {
|
|
62
|
+
dashboard: `
|
|
63
|
+
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
64
|
+
<circle class="track--dashboard" cx="50" cy="50" r="40" fill="none" stroke-dasharray="252px" stroke="aliceblue"
|
|
65
|
+
stroke-width="4px" stroke-dashoffset="100" stroke-linecap="round" />
|
|
66
|
+
<circle class="path--dashboard" cx="50" cy="50" r="40" fill="none" stroke-dasharray="252px" stroke="rgb(32, 160, 255)" stroke-width="4px"
|
|
67
|
+
stroke-dashoffset="252" stroke-linecap="round" />
|
|
68
|
+
</svg>
|
|
69
|
+
<span class="ea-progress_text--dashboard"></span>
|
|
70
|
+
`,
|
|
71
|
+
circle: `
|
|
72
|
+
<svg viewBox="0 0 100 100">
|
|
73
|
+
<circle class="track--circle" cx="50" cy="50" r="48" fill="none" stroke="aliceblue" stroke-width="4" stroke-dasharray="302px" stroke-dashoffset="0" />
|
|
74
|
+
<circle class="path--circle" cx="50" cy="50" r="48" fill="none" stroke="rgb(32, 160, 255)" stroke-width="4" stroke-dasharray="302px" stroke-dashoffset="0" stroke-linecap="round" />
|
|
75
|
+
</svg>
|
|
76
|
+
<span class="ea-progress_text--circle"></span>
|
|
77
|
+
`,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class EaProgress extends Base {
|
|
81
|
+
#wrap;
|
|
82
|
+
#track;
|
|
83
|
+
#path;
|
|
84
|
+
#progressText;
|
|
85
|
+
|
|
86
|
+
constructor() {
|
|
87
|
+
super();
|
|
88
|
+
|
|
89
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
90
|
+
const wrap = document.createElement('div');
|
|
91
|
+
wrap.className = 'ea-progress_wrap';
|
|
92
|
+
|
|
93
|
+
// 背景条
|
|
94
|
+
const track = document.createElement('section');
|
|
95
|
+
track.className = 'ea-progress_track';
|
|
96
|
+
|
|
97
|
+
// 进度条
|
|
98
|
+
const path = document.createElement('section');
|
|
99
|
+
path.className = 'ea-progress_path';
|
|
100
|
+
|
|
101
|
+
track.appendChild(path);
|
|
102
|
+
wrap.appendChild(track);
|
|
103
|
+
|
|
104
|
+
// 进度文字
|
|
105
|
+
const progressText = document.createElement('section');
|
|
106
|
+
progressText.className = 'ea-progress_text';
|
|
107
|
+
|
|
108
|
+
wrap.appendChild(progressText);
|
|
109
|
+
|
|
110
|
+
this.#wrap = wrap;
|
|
111
|
+
this.#track = track;
|
|
112
|
+
this.#path = path;
|
|
113
|
+
this.#progressText = progressText;
|
|
114
|
+
|
|
115
|
+
this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
|
|
116
|
+
this.build(shadowRoot, stylesheet);
|
|
117
|
+
this.shadowRoot.appendChild(wrap);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ------- type 进度条类型 -------
|
|
121
|
+
// #region
|
|
122
|
+
|
|
123
|
+
handleSVGTemplate(type) {
|
|
124
|
+
this.#wrap.style.height = '126px';
|
|
125
|
+
this.#wrap.style.width = '126px';
|
|
126
|
+
|
|
127
|
+
this.#wrap.innerHTML = SVGTemplate[type];
|
|
128
|
+
|
|
129
|
+
const track = this.#wrap.querySelector(`circle[class="track--${type}"]`);
|
|
130
|
+
const path = this.#wrap.querySelector(`circle[class="path--${type}"]`);
|
|
131
|
+
const progressText = this.#wrap.querySelector(`span[class="ea-progress_text--${type}"]`);
|
|
132
|
+
|
|
133
|
+
this.#track = track;
|
|
134
|
+
this.#path = path;
|
|
135
|
+
this.#progressText = progressText;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get type() {
|
|
139
|
+
return this.getAttribute('type');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
set type(value) {
|
|
143
|
+
if (value === null || value === undefined || value === '') return;
|
|
144
|
+
|
|
145
|
+
this.setAttribute('type', value);
|
|
146
|
+
|
|
147
|
+
switch (this.type) {
|
|
148
|
+
case "circle":
|
|
149
|
+
this.handleSVGTemplate("circle");
|
|
150
|
+
break;
|
|
151
|
+
case "dashboard":
|
|
152
|
+
this.handleSVGTemplate("dashboard");
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// #endregion
|
|
157
|
+
// ------- end -------
|
|
158
|
+
|
|
159
|
+
// ------- percentage 进度百分比 -------
|
|
160
|
+
// #region
|
|
161
|
+
get percentage() {
|
|
162
|
+
return this.getAttribute('percentage') || 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getCirclePercentageValue(value) {
|
|
166
|
+
return 302 * (100 - Number(value)) / 100;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getDashboardPercentageValue(value) {
|
|
170
|
+
return 152 * (100 - Number(value)) / 100 + 100;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
set percentage(value) {
|
|
174
|
+
if (value === null || value === undefined || value === '') return;
|
|
175
|
+
else if (Number(value) < 0) value = 0;
|
|
176
|
+
else if (Number(value) > 100) value = 100;
|
|
177
|
+
|
|
178
|
+
this.setAttribute('percentage', value);
|
|
179
|
+
this.#progressText.innerHTML = `${value}%`;
|
|
180
|
+
|
|
181
|
+
switch (this.type) {
|
|
182
|
+
case "circle": {
|
|
183
|
+
this.#path.style.strokeDashoffset = `${this.getCirclePercentageValue(value)}px`;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case "dashboard": {
|
|
187
|
+
this.#path.style.strokeDashoffset = `${this.getDashboardPercentageValue(value)}px`;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
default: {
|
|
191
|
+
this.#path.style.width = `${value}%`;
|
|
192
|
+
|
|
193
|
+
if (this.textInside) this.handleTextInside(value);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// #endregion
|
|
199
|
+
// ------- end -------
|
|
200
|
+
|
|
201
|
+
// ------- status 进度条状态样式 -------
|
|
202
|
+
// #region
|
|
203
|
+
|
|
204
|
+
// 样式配置
|
|
205
|
+
get statusList() {
|
|
206
|
+
return {
|
|
207
|
+
success: {
|
|
208
|
+
icon: 'icon-ok-circled',
|
|
209
|
+
color: '#67c23a'
|
|
210
|
+
},
|
|
211
|
+
warning: {
|
|
212
|
+
icon: 'icon-attention-circled',
|
|
213
|
+
color: '#e6a23c'
|
|
214
|
+
},
|
|
215
|
+
exception: {
|
|
216
|
+
icon: 'icon-cancel-circled',
|
|
217
|
+
color: '#f56c6c'
|
|
218
|
+
},
|
|
219
|
+
primary: '',
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 状态处理
|
|
224
|
+
handleStatusStyle(value, className) {
|
|
225
|
+
this.#progressText.innerText = !this.statusList[value] ? `${this.percentage}%` : '';
|
|
226
|
+
this.#progressText.className = `${className} ${this.statusList[value].icon || ''}`;
|
|
227
|
+
this.#progressText.style.color = this.statusList[value].color;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
get status() {
|
|
231
|
+
return this.getAttribute('status') || 'primary';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
set status(value) {
|
|
235
|
+
this.setAttribute('status', value);
|
|
236
|
+
|
|
237
|
+
switch (this.type) {
|
|
238
|
+
case "circle":
|
|
239
|
+
this.handleStatusStyle(value, 'ea-progress_text--circle');
|
|
240
|
+
this.#path.style.stroke = this.statusList[value].color;
|
|
241
|
+
break;
|
|
242
|
+
case "dashboard":
|
|
243
|
+
this.handleStatusStyle(value, 'ea-progress_text--dashboard');
|
|
244
|
+
this.#path.style.stroke = this.statusList[value].color;
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
this.handleStatusStyle(value, 'ea-progress_text');
|
|
248
|
+
this.#path.style.backgroundColor = this.statusList[value].color;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// #endregion
|
|
253
|
+
// ------- end -------
|
|
254
|
+
|
|
255
|
+
// ------- text-inside 进度文字内显 -------
|
|
256
|
+
// #region
|
|
257
|
+
handleTextInside(value) {
|
|
258
|
+
if (this.type === "circle") return;
|
|
259
|
+
|
|
260
|
+
if (value) {
|
|
261
|
+
this.#progressText.style.display = "none";
|
|
262
|
+
this.#path.innerText = `${this.percentage}%`;
|
|
263
|
+
} else {
|
|
264
|
+
this.#progressText.style.display = "block";
|
|
265
|
+
this.#path.innerText = ``;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
get textInside() {
|
|
270
|
+
return this.getAttrBoolean("text-inside");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
set textInside(value) {
|
|
274
|
+
this.setAttribute("text-inside", value);
|
|
275
|
+
|
|
276
|
+
this.handleTextInside(value);
|
|
277
|
+
}
|
|
278
|
+
// #endregion
|
|
279
|
+
// ------- end -------
|
|
280
|
+
|
|
281
|
+
// ------- stroke-width 进度条高度 -------
|
|
282
|
+
// #region
|
|
283
|
+
get strokeWidth() {
|
|
284
|
+
return this.getAttribute("stroke-width");
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
set strokeWidth(value) {
|
|
288
|
+
value = value ? value : 4;
|
|
289
|
+
|
|
290
|
+
this.toggleAttr("stroke-width", value);
|
|
291
|
+
|
|
292
|
+
if (this.type === "circle") {
|
|
293
|
+
this.#track.style.strokeWidth = `${Number(value)}px`;
|
|
294
|
+
this.#path.style.strokeWidth = `${Number(value)}px`;
|
|
295
|
+
} else {
|
|
296
|
+
value = Number(value) + 4;
|
|
297
|
+
|
|
298
|
+
this.#track.style.height = `${value}px`;
|
|
299
|
+
this.#track.style.lineHeight = `${value}px`;
|
|
300
|
+
this.#path.style.height = `${value}px`;
|
|
301
|
+
this.#path.style.lineHeight = `${value}px`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// #endregion
|
|
305
|
+
// ------- end -------
|
|
306
|
+
|
|
307
|
+
init() {
|
|
308
|
+
const that = this;
|
|
309
|
+
|
|
310
|
+
// type 进度条类型
|
|
311
|
+
this.type = this.type;
|
|
312
|
+
|
|
313
|
+
// percentage 百分比
|
|
314
|
+
this.percentage = this.percentage;
|
|
315
|
+
|
|
316
|
+
// status 状态
|
|
317
|
+
this.status = this.status;
|
|
318
|
+
|
|
319
|
+
// text-inside 文本内显
|
|
320
|
+
this.textInside = this.textInside;
|
|
321
|
+
|
|
322
|
+
// stroke-width 进度条的高度
|
|
323
|
+
this.strokeWidth = this.strokeWidth;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
connectedCallback() {
|
|
327
|
+
this.init();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (!customElements.get("ea-progress")) {
|
|
332
|
+
customElements.define("ea-progress", EaProgress);
|
|
333
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js'
|
|
3
|
+
|
|
4
|
+
const stylesheet = `
|
|
5
|
+
:host(ea-radio) {
|
|
6
|
+
--margin-right: 0.75rem;
|
|
7
|
+
--text-color: #606266;
|
|
8
|
+
--radio-show-type: inline-block;
|
|
9
|
+
--button-size: 1rem;
|
|
10
|
+
--button-margin: 0.5rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ea-radio_wrap {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
margin-right: 1rem;
|
|
17
|
+
}
|
|
18
|
+
.ea-radio_wrap .__ea-radio-input_wrap {
|
|
19
|
+
width: var(--button-size);
|
|
20
|
+
height: var(--button-size);
|
|
21
|
+
line-height: 1;
|
|
22
|
+
margin-right: var(--button-margin);
|
|
23
|
+
}
|
|
24
|
+
.ea-radio_wrap .__ea-radio-input_wrap input {
|
|
25
|
+
display: none;
|
|
26
|
+
}
|
|
27
|
+
.ea-radio_wrap .__ea-radio-input_wrap .__ea-radio-input_inner {
|
|
28
|
+
position: relative;
|
|
29
|
+
display: var(--radio-show-type);
|
|
30
|
+
width: 1rem;
|
|
31
|
+
height: 1rem;
|
|
32
|
+
line-height: 1;
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
border-radius: 50%;
|
|
35
|
+
border: 1px solid #606266;
|
|
36
|
+
}
|
|
37
|
+
.ea-radio_wrap .__ea-radio-input_wrap .__ea-radio-input_inner::before {
|
|
38
|
+
position: absolute;
|
|
39
|
+
left: 50%;
|
|
40
|
+
top: 50%;
|
|
41
|
+
transform: translate(-50%, -50%);
|
|
42
|
+
content: "";
|
|
43
|
+
width: 0.35rem;
|
|
44
|
+
height: 0.35rem;
|
|
45
|
+
border-radius: 50%;
|
|
46
|
+
background-color: transparent;
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
transition: all 0.3s ease;
|
|
49
|
+
}
|
|
50
|
+
.ea-radio_wrap .__ea-radio-input_wrap .__ea-radio-input_inner:hover {
|
|
51
|
+
border-color: #409eff;
|
|
52
|
+
}
|
|
53
|
+
.ea-radio_wrap .__ea-radio-label_desc {
|
|
54
|
+
color: var(--text-color);
|
|
55
|
+
}
|
|
56
|
+
.ea-radio_wrap.checked .__ea-radio-input_wrap .__ea-radio-input_inner {
|
|
57
|
+
border-color: #409eff;
|
|
58
|
+
background-color: #409eff;
|
|
59
|
+
}
|
|
60
|
+
.ea-radio_wrap.checked .__ea-radio-input_wrap .__ea-radio-input_inner::before {
|
|
61
|
+
background-color: white;
|
|
62
|
+
}
|
|
63
|
+
.ea-radio_wrap.checked .__ea-radio-label_desc {
|
|
64
|
+
color: #409eff;
|
|
65
|
+
}
|
|
66
|
+
.ea-radio_wrap.disabled .__ea-radio-input_wrap .__ea-radio-input_inner {
|
|
67
|
+
border-color: #eeeeee;
|
|
68
|
+
background-color: #eeeeee;
|
|
69
|
+
}
|
|
70
|
+
.ea-radio_wrap.disabled .__ea-radio-input_wrap .__ea-radio-input_inner::before {
|
|
71
|
+
background-color: transparent;
|
|
72
|
+
}
|
|
73
|
+
.ea-radio_wrap.disabled .__ea-radio-label_desc {
|
|
74
|
+
color: #c0c4cc;
|
|
75
|
+
}
|
|
76
|
+
.ea-radio_wrap.disabled[checked=true] .__ea-radio-input_wrap .__ea-radio-input_inner::before {
|
|
77
|
+
background-color: #c0c4cc;
|
|
78
|
+
}
|
|
79
|
+
.ea-radio_wrap.border {
|
|
80
|
+
border: 1px solid #ccc;
|
|
81
|
+
padding: 0.25rem 0.5rem;
|
|
82
|
+
border-radius: 8px;
|
|
83
|
+
}
|
|
84
|
+
.ea-radio_wrap.border[checked=true] {
|
|
85
|
+
border: 1px solid #409eff;
|
|
86
|
+
}`;
|
|
87
|
+
|
|
88
|
+
const inputDom = () => {
|
|
89
|
+
const wrap = document.createElement('span');
|
|
90
|
+
wrap.className = "__ea-radio-input_wrap";
|
|
91
|
+
|
|
92
|
+
const radio = document.createElement('span');
|
|
93
|
+
radio.className = "__ea-radio-input_inner";
|
|
94
|
+
wrap.appendChild(radio);
|
|
95
|
+
|
|
96
|
+
const input = document.createElement('input');
|
|
97
|
+
input.type = 'radio';
|
|
98
|
+
input.className = "__ea-radio-input_input";
|
|
99
|
+
|
|
100
|
+
wrap.appendChild(input);
|
|
101
|
+
|
|
102
|
+
return { wrap, input };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const labelDom = () => {
|
|
106
|
+
const labelDesc = document.createElement('span');
|
|
107
|
+
labelDesc.className = "__ea-radio-label_desc";
|
|
108
|
+
const slot = document.createElement('slot');
|
|
109
|
+
labelDesc.appendChild(slot);
|
|
110
|
+
|
|
111
|
+
return labelDesc;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class EaRadio extends Base {
|
|
115
|
+
#radio;
|
|
116
|
+
#label;
|
|
117
|
+
|
|
118
|
+
static get observedAttributes() {
|
|
119
|
+
return ['checked'];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
constructor() {
|
|
123
|
+
super();
|
|
124
|
+
|
|
125
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
126
|
+
let dom = document.createElement('label');
|
|
127
|
+
dom.className = "ea-radio_wrap";
|
|
128
|
+
|
|
129
|
+
// input + radio
|
|
130
|
+
const input = inputDom();
|
|
131
|
+
dom.appendChild(input.wrap);
|
|
132
|
+
|
|
133
|
+
// label 标签文字
|
|
134
|
+
const label = labelDom();
|
|
135
|
+
dom.appendChild(label);
|
|
136
|
+
|
|
137
|
+
this.#label = dom;
|
|
138
|
+
this.#radio = input.input;
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
// ------- 打包 -------
|
|
142
|
+
// #region
|
|
143
|
+
const styleNode = document.createElement('style');
|
|
144
|
+
styleNode.innerHTML = stylesheet;
|
|
145
|
+
this.shadowRoot.appendChild(styleNode);
|
|
146
|
+
// #endregion
|
|
147
|
+
// ------- end -------
|
|
148
|
+
|
|
149
|
+
// ------- 本地调试 -------
|
|
150
|
+
// #region
|
|
151
|
+
// setStyle(shadowRoot, new URL('./index.css', import.meta.url).href);
|
|
152
|
+
// #endregion
|
|
153
|
+
// ------- end -------
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
shadowRoot.appendChild(dom);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ------- 选中 -------
|
|
160
|
+
// #region
|
|
161
|
+
get checked() {
|
|
162
|
+
return this.getAttrBoolean('checked');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
set checked(val) {
|
|
166
|
+
this.#radio.checked = val;
|
|
167
|
+
|
|
168
|
+
if (val) {
|
|
169
|
+
this.setAttribute('checked', true);
|
|
170
|
+
this.#label.setAttribute('checked', true);
|
|
171
|
+
this.#label.classList.add('checked');
|
|
172
|
+
} else {
|
|
173
|
+
this.removeAttribute('checked');
|
|
174
|
+
this.#label.removeAttribute('checked');
|
|
175
|
+
this.#label.classList.remove('checked');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// #endregion
|
|
179
|
+
// ------- end -------
|
|
180
|
+
|
|
181
|
+
// ------- label_for 单选框的唯一键 -------
|
|
182
|
+
// #region
|
|
183
|
+
get name() {
|
|
184
|
+
return this.getAttribute('name');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
set name(val) {
|
|
188
|
+
this.#radio.setAttribute('name', val);
|
|
189
|
+
}
|
|
190
|
+
// #endregion
|
|
191
|
+
// ------- end -------
|
|
192
|
+
|
|
193
|
+
// ------- value 单选框的值 -------
|
|
194
|
+
// #region
|
|
195
|
+
get value() {
|
|
196
|
+
return this.getAttribute('value');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
set value(val) {
|
|
200
|
+
this.#label.setAttribute('for', val);
|
|
201
|
+
this.#radio.setAttribute('id', val);
|
|
202
|
+
this.#radio.setAttribute('value', val);
|
|
203
|
+
}
|
|
204
|
+
// #endregion
|
|
205
|
+
// ------- end -------
|
|
206
|
+
|
|
207
|
+
// ------- disabled 禁用状态 -------
|
|
208
|
+
// #region
|
|
209
|
+
get disabled() {
|
|
210
|
+
return this.getAttrBoolean('disabled');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
set disabled(val) {
|
|
214
|
+
this.#radio.disabled = val;
|
|
215
|
+
this.#label.toggleAttribute('disabled', val);
|
|
216
|
+
this.#label.classList.toggle('disabled', val);
|
|
217
|
+
}
|
|
218
|
+
// #endregion
|
|
219
|
+
// ------- end -------
|
|
220
|
+
|
|
221
|
+
// ------- border 是否带有边框 -------
|
|
222
|
+
// #region
|
|
223
|
+
get border() {
|
|
224
|
+
return this.getAttrBoolean('border');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
set border(val) {
|
|
228
|
+
this.#label.classList.toggle('border', val);
|
|
229
|
+
}
|
|
230
|
+
// #endregion
|
|
231
|
+
// ------- end -------
|
|
232
|
+
|
|
233
|
+
init() {
|
|
234
|
+
const that = this;
|
|
235
|
+
|
|
236
|
+
// radio 的 checked 属性
|
|
237
|
+
this.checked = this.checked;
|
|
238
|
+
|
|
239
|
+
// label 的 for 属性
|
|
240
|
+
this.name = this.name;
|
|
241
|
+
|
|
242
|
+
// radio 的 value 属性
|
|
243
|
+
this.value = this.value;
|
|
244
|
+
|
|
245
|
+
// radio 的 disabled 属性
|
|
246
|
+
this.disabled = this.disabled;
|
|
247
|
+
|
|
248
|
+
// border 属性
|
|
249
|
+
this.border = this.border;
|
|
250
|
+
|
|
251
|
+
// 监听 change 事件, 修改 checked 属性
|
|
252
|
+
this.#radio.addEventListener('change', function (e) {
|
|
253
|
+
if (e.target.checked) {
|
|
254
|
+
document.querySelectorAll(`ea-radio[name="${that.name}"]`).forEach(btn => {
|
|
255
|
+
const btnInput = btn.shadowRoot.querySelector('input');
|
|
256
|
+
|
|
257
|
+
if (btnInput !== this) {
|
|
258
|
+
btn.checked = false;
|
|
259
|
+
} else {
|
|
260
|
+
btn.checked = true;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
that.dispatchEvent(new CustomEvent('change', {
|
|
266
|
+
detail: {
|
|
267
|
+
value: this.value,
|
|
268
|
+
checked: this.checked
|
|
269
|
+
}
|
|
270
|
+
}))
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
connectedCallback() {
|
|
277
|
+
this.init();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
281
|
+
// console.log(name);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (!window.customElements.get("ea-radio")) {
|
|
286
|
+
window.customElements.define("ea-radio", EaRadio);
|
|
287
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from "../Base.js";
|
|
3
|
+
|
|
4
|
+
const stylesheet = `
|
|
5
|
+
.ea-radio-group {
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
.ea-radio-group ea-radio {
|
|
9
|
+
margin-right: 2rem;
|
|
10
|
+
}`;
|
|
11
|
+
|
|
12
|
+
export class EaRadioGroup extends Base {
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
18
|
+
|
|
19
|
+
const dom = document.createElement('div');
|
|
20
|
+
shadowRoot.appendChild(dom);
|
|
21
|
+
const slot = document.createElement('slot');
|
|
22
|
+
dom.className = "ea-radio-group";
|
|
23
|
+
dom.appendChild(slot);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
this.dom = dom;
|
|
27
|
+
|
|
28
|
+
this.build(shadowRoot, stylesheet);
|
|
29
|
+
|
|
30
|
+
shadowRoot.appendChild(dom);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ------- name 唯一键值 -------
|
|
34
|
+
// #region
|
|
35
|
+
get name() {
|
|
36
|
+
return this.getAttribute('name');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set name(val) {
|
|
40
|
+
this.querySelectorAll('ea-radio').forEach(radio => {
|
|
41
|
+
radio.setAttribute('name', val);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// #endregion
|
|
45
|
+
// ------- end -------
|
|
46
|
+
|
|
47
|
+
init() {
|
|
48
|
+
// name 唯一键值
|
|
49
|
+
this.name = this.name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
this.init();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!window.customElements.get("ea-radio-group")) {
|
|
58
|
+
window.customElements.define("ea-radio-group", EaRadioGroup);
|
|
59
|
+
}
|