easy-component-ui 1.0.3 → 2.0.1
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/.github/workflows/publish.yml +28 -0
- package/components/Base.js +1 -90
- package/components/ea-alert/index.js +1 -298
- package/components/ea-alert/src/style/stylesheet.js +1 -0
- package/components/ea-aside/index.js +1 -0
- package/components/ea-avatar/index.js +1 -277
- package/components/ea-avatar/src/assets/defaultAvatar.js +1 -0
- package/components/ea-avatar/src/assets/errorAvatar.js +1 -0
- package/components/ea-avatar/src/assets/iconAndTextAvatar.js +1 -0
- package/components/ea-avatar/src/style/stylesheet.js +1 -0
- package/components/ea-backtop/index.js +1 -232
- package/components/ea-backtop/src/style/stylesheet.js +1 -0
- package/components/ea-badge/index.js +1 -160
- package/components/ea-badge/src/style/stylesheet.js +1 -0
- package/components/ea-breadcrumb/index.js +1 -0
- package/components/ea-breadcrumb/src/style/stylesheet.js +1 -0
- package/components/ea-breadcrumb-item/index.js +1 -0
- package/components/ea-breadcrumb-item/src/style/style.js +1 -0
- package/components/ea-button/index.js +1 -584
- package/components/ea-button/src/components/ButtonComm.js +1 -0
- package/components/ea-button/src/components/HrefComm.js +1 -0
- package/components/ea-button/src/style/stylesheet.js +1 -0
- package/components/ea-button-group/index.js +1 -459
- package/components/ea-button-group/src/style/stylesheet.js +1 -0
- package/components/ea-calendar/index.js +1 -409
- package/components/ea-calendar/src/style/stylesheet.js +1 -0
- package/components/ea-calendar/src/utils/createChangerElement.js +1 -0
- package/components/ea-calendar/src/utils/createThead.js +1 -0
- package/components/ea-calendar/src/utils/getDate.js +1 -0
- package/components/ea-calendar/src/utils/getUserWeekStart.js +1 -0
- package/components/ea-card/index.js +1 -77
- package/components/ea-card/src/style/stylesheet.js +1 -0
- package/components/ea-carousel/index.js +1 -434
- package/components/ea-carousel/src/style/stylesheet.js +1 -0
- package/components/ea-carousel/src/utils/handleIndexOverflow.js +1 -0
- package/components/ea-carousel-item/index.js +1 -0
- package/components/ea-carousel-item/src/style/stylesheet.js +1 -0
- package/components/ea-checkbox/index.js +1 -314
- package/components/ea-checkbox/src/style/stylesheet.js +1 -0
- package/components/ea-checkbox-group/index.js +1 -107
- package/components/ea-checkbox-group/src/style/stylesheet.js +1 -0
- package/components/ea-collapse/index.js +1 -293
- package/components/ea-collapse-item/index.js +1 -0
- package/components/ea-collapse-item/src/style/stylesheet.js +1 -0
- package/components/ea-container/index.js +1 -0
- package/components/ea-date-picker/index.js +1 -0
- package/components/ea-date-picker/src/style/stylesheet.js +1 -0
- package/components/ea-descriptions/index.js +1 -240
- package/components/ea-descriptions/src/components/contentTemplate.js +1 -0
- package/components/ea-descriptions/src/components/getTdTemplate_border.js +1 -0
- package/components/ea-descriptions/src/components/getTdTemplate_direction.js +1 -0
- package/components/ea-descriptions/src/components/getThTemplate_direction.js +1 -0
- package/components/ea-descriptions/src/components/getThTemplate_normal.js +1 -0
- package/components/ea-descriptions/src/style/stylesheet.js +1 -0
- package/components/ea-descriptions-item/index.js +1 -110
- package/components/ea-descriptions-item/src/stylesheet.js +1 -0
- package/components/ea-drawer/index.js +1 -0
- package/components/ea-drawer/src/style/stylesheet.js +1 -0
- package/components/ea-empty/index.js +1 -141
- package/components/ea-empty/src/assets/emptyStatusSVG.js +1 -0
- package/components/ea-empty/src/style/stylesheet.js +1 -0
- package/components/ea-footer/index.js +1 -0
- package/components/ea-form/index.js +1 -0
- package/components/ea-form-item/index.js +1 -0
- package/components/ea-form-item/src/style/stylesheet.js +1 -0
- package/components/ea-header/index.js +1 -0
- package/components/ea-icon/config.json +1029 -1017
- package/components/ea-icon/css/animation.css +85 -85
- package/components/ea-icon/css/fontello.css +226 -224
- package/components/ea-icon/font/fontello.eot +0 -0
- package/components/ea-icon/font/fontello.svg +350 -683
- package/components/ea-icon/font/fontello.ttf +0 -0
- package/components/ea-icon/font/fontello.woff +0 -0
- package/components/ea-icon/font/fontello.woff2 +0 -0
- package/components/ea-icon/index.js +1 -47
- package/components/ea-image/index.js +1 -412
- package/components/ea-image/src/assets/errorImage.js +1 -0
- package/components/ea-image/src/style/stylesheet.js +1 -0
- package/components/ea-image/src/utils/createPreviewTools.js +1 -0
- package/components/ea-infinite-scroll/index.js +1 -170
- package/components/ea-infinite-scroll-item/index.js +1 -0
- package/components/ea-input/index.js +1 -765
- package/components/ea-input/src/components/createFixIcon.js +1 -0
- package/components/ea-input/src/components/createSuggestionBoard.js +1 -0
- package/components/ea-input/src/components/createWordLimitElement.js +1 -0
- package/components/ea-input/src/style/stylesheet.js +1 -0
- package/components/ea-input/src/utils/dispatchEvent.js +1 -0
- package/components/ea-input/src/utils/handleSearchResult.js +1 -0
- package/components/ea-input/src/utils/handleSuggestionBoardTrigger.js +1 -0
- package/components/ea-input-number/index.js +1 -458
- package/components/ea-input-number/src/style/stylesheet.js +1 -0
- package/components/ea-input-number/src/utils/handleCustomEvent.js +1 -0
- package/components/ea-link/index.js +1 -200
- package/components/ea-link/src/style/stylesheet.js +1 -0
- package/components/ea-loading/index.js +1 -218
- package/components/ea-loading/src/style/stylesheet.js +1 -0
- package/components/ea-main/index.js +1 -0
- package/components/ea-menu/index.js +1 -0
- package/components/ea-menu/src/style/stylesheet.js +1 -0
- package/components/ea-menu/src/utils/handleMenuItemEvent.js +1 -0
- package/components/ea-menu-item/index.js +1 -0
- package/components/ea-menu-item/src/style/stylesheet.js +1 -0
- package/components/ea-menu-item-group/index.js +1 -0
- package/components/ea-menu-item-group/src/style/stylesheet.js +1 -0
- package/components/ea-message/index.js +1 -233
- package/components/ea-message/src/style/stylesheet.js +1 -0
- package/components/ea-message/src/utils/MessageClass.js +1 -0
- package/components/ea-message-box/index.js +1 -202
- package/components/ea-message-box/src/style/stylesheet.js +1 -0
- package/components/ea-message-box/src/utils/EaMessageBoxClass.js +1 -0
- package/components/ea-option/index.js +1 -0
- package/components/ea-option/src/style/stylesheet.js +1 -0
- package/components/ea-option-gropu/index.js +1 -0
- package/components/ea-page-header/index.js +1 -0
- package/components/ea-page-header/src/style/stylesheet.js +1 -0
- package/components/ea-pagination/index.js +1 -444
- package/components/ea-pagination/src/components/getMoreItem.js +1 -0
- package/components/ea-pagination/src/components/getPageItem.js +1 -0
- package/components/ea-pagination/src/components/getShowTotalItem.js +1 -0
- package/components/ea-pagination/src/style/stylesheet.js +1 -0
- package/components/ea-pane/index.js +1 -0
- package/components/ea-pane/src/stylesheet.js +1 -0
- package/components/ea-progress/index.js +1 -333
- package/components/ea-progress/src/components/SVGComm.js +1 -0
- package/components/ea-progress/src/style/stylesheet.js +1 -0
- package/components/ea-radio/index.js +1 -287
- package/components/ea-radio/src/style/stylesheet.js +1 -0
- package/components/ea-radio-group/index.js +1 -59
- package/components/ea-rate/index.js +1 -326
- package/components/ea-rate/src/components/rateComm.js +1 -0
- package/components/ea-rate/src/style/stylesheet.js +1 -0
- package/components/ea-result/index.js +1 -167
- package/components/ea-result/src/style/stylesheet.js +1 -0
- package/components/ea-select/index.js +1 -34
- package/components/ea-select/src/style/stylesheet.js +1 -0
- package/components/ea-skeleton/index.js +1 -341
- package/components/ea-skeleton/src/style/stylesheet.js +1 -0
- package/components/ea-skeleton/src/utils/createSkeletonElement.js +1 -0
- package/components/ea-skeleton-item/index.js +1 -0
- package/components/ea-skeleton-item/src/assets/imageSVG.js +1 -0
- package/components/ea-skeleton-item/src/style/stylesheet.js +1 -0
- package/components/ea-step/index.js +1 -0
- package/components/ea-step/src/style/stylesheet.js +1 -0
- package/components/ea-steps/index.js +1 -0
- package/components/ea-steps/src/style/stylesheet.js +1 -0
- package/components/ea-submenu/index.js +1 -0
- package/components/ea-submenu/src/style/stylesheet.js +1 -0
- package/components/ea-switch/index.js +1 -301
- package/components/ea-switch/src/style/stylesheet.js +1 -0
- package/components/ea-tab/index.js +1 -0
- package/components/ea-tab/src/style/stylesheet.js +1 -0
- package/components/ea-table/index.js +1 -0
- package/components/ea-table/src/style/stylesheet.js +1 -0
- package/components/ea-table-column/index.js +1 -0
- package/components/ea-tabs/index.js +1 -0
- package/components/ea-tabs/src/style/stylesheet.js +1 -0
- package/components/ea-tag/index.js +1 -212
- package/components/ea-tag/src/style/stylesheet.js +1 -0
- package/components/ea-textarea/index.js +1 -333
- package/components/ea-textarea/src/style/stylesheet.js +1 -0
- package/components/ea-time-picker/index.js +1 -0
- package/components/ea-time-picker/src/style/stylesheet.js +1 -0
- package/components/ea-timeline/index.js +1 -334
- package/components/ea-timeline/style/stylesheet.js +1 -0
- package/components/ea-timeline-item/index.js +1 -0
- package/components/ea-timeline-item/src/style/stylesheet.js +1 -0
- package/package.json +11 -11
- package/utils/Validator.js +1 -0
- package/utils/createElement.js +1 -30
- package/utils/handleDefaultAttrIsTrue.js +1 -0
- package/utils/handleTemplate.js +1 -19
- package/utils/setStyle.js +1 -8
- package/utils/timeout.js +1 -0
- package/components/ea-message/MessageClass.js +0 -71
- package/components/ea-message-box/EaMessageBoxClass.js +0 -48
- package/components/ea-ui-base-style.css +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function createFixIcon(e,n,a){const c=document.createElement("ea-icon");return c.className=`fix-icon ${a}-icon`,c.icon=n,c.part=`${a}-icon`,e.classList.add(a),e.appendChild(c),c}function handleIconDisplay(e,n){e.style.display=n?"block":"none"}function clearableEvent(e,n,a){n.addEventListener(e,(e=>{handleIconDisplay(a,e.target?.value)}))}export function createClearableFixIcon(e,n,a){const c=createFixIcon(e,a,"surfix");return c.addEventListener("click",(()=>{this.value="",n.focus()})),handleIconDisplay(c,n.value),clearableEvent("input",n,c),clearableEvent("focus",n,c),clearableEvent("blur",n,c),c}export function createShowPasswordIcon(e,n,a){const c=createFixIcon(e,a,"surfix");return c.addEventListener("click",(()=>{n.type="password"===n.type?"text":"password",c.icon="password"===n.type?"icon-eye":"icon-eye-off",n.focus()})),n.addEventListener("input",(()=>{handleIconDisplay(c,n.value)})),handleIconDisplay(c,n.value),c}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function handleSuggestionBoardClose(e){e.classList.remove("is-open")}export function createSuggestionBoard(e,n){const t=this.shadowRoot.querySelector(".ea-input_suggestion-wrap"),a=document.createElement("ul");a.className="ea-input_suggestion-wrap",n.forEach((e=>{const n=document.createElement("li");n.innerText=e.value,n.addEventListener("click",(()=>{this.value=e.value,handleSuggestionBoardClose(a)})),a.appendChild(n)}));const o=document.createElement("ea-icon");return o.className="loading-icon animate-spin",o.icon="icon-spin6 ",a.appendChild(o),window.addEventListener("click",(e=>{this.contains(e.target)||handleSuggestionBoardClose(a)})),t&&(t.remove(),a.classList.add("is-open")),e.appendChild(a),a}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function createWordLimitElement(e){const t=document.createElement("span");return t.className="ea-input_word-limit",t.innerText=`${e.value.length}/${this.maxLength}`,e.addEventListener("input",(e=>{t.innerText=`${e.target.value.length}/${this.maxLength}`})),t}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const stylesheet="\n.ea-input_container {\n display: flex;\n align-items: stretch;\n width: 100%;\n}\n.ea-input_container .ea-input_wrap {\n position: relative;\n display: flex;\n align-items: stretch;\n width: 100%;\n}\n.ea-input_container .ea-input_wrap .ea-input_inner {\n flex: 1;\n box-sizing: border-box;\n box-shadow: none;\n border: 1px solid #dcdfe6;\n outline: 0;\n border-radius: 3px;\n padding: 0.5rem;\n width: 100%;\n line-height: 0.8;\n font-size: 0.8rem;\n scrollbar-width: none;\n}\n.ea-input_container .ea-input_wrap .ea-input_inner:focus {\n border-color: #409eff;\n}\n.ea-input_container .ea-input_wrap .ea-input_inner::placeholder {\n color: #c0c4cc;\n}\n.ea-input_container .ea-input_wrap .ea-input_inner:invalid {\n border-color: #f56c6c;\n}\n.ea-input_container .ea-input_wrap .ea-input_inner[disabled] {\n background-color: #eeeeee;\n color: #c0c4cc;\n}\n.ea-input_container .ea-input_wrap .fix-icon {\n position: absolute;\n top: 50%;\n font-size: 0.8rem;\n line-height: 0.8rem;\n}\n.ea-input_container .ea-input_wrap.prefix .ea-input_inner {\n padding-left: 1.75rem;\n}\n.ea-input_container .ea-input_wrap.prefix .prefix-icon {\n left: 1rem;\n transform: translate(-50%, -50%);\n}\n.ea-input_container .ea-input_wrap.surfix .ea-input_inner {\n padding-right: 1.75rem;\n}\n.ea-input_container .ea-input_wrap.surfix .surfix-icon {\n right: 1rem;\n transform: translate(50%, -50%);\n}\n.ea-input_container .ea-input_wrap .ea-input_prepend-slot,\n.ea-input_container .ea-input_wrap .ea-input_append-slot {\n height: 100%;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap {\n list-style-type: none;\n padding: 0;\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n padding-inline-start: 0;\n unicode-bidi: unset;\n position: absolute;\n box-sizing: border-box;\n z-index: 3;\n top: calc(100% + 5px);\n left: 0;\n transform-origin: top center;\n transform: scaleY(0);\n padding: 0.5rem 0;\n width: 100%;\n max-height: 10rem;\n overflow-y: auto;\n scrollbar-width: thin;\n background-color: white;\n box-shadow: 0 1px 8px 1px rgba(0, 0, 0, 0.2);\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap li {\n padding: 0.5rem;\n font-size: 0.9rem;\n cursor: pointer;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap li:hover {\n background-color: #f5f7fa;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap .loading-icon {\n display: none;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap.loading {\n height: 5rem;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap.loading li {\n display: none;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap.loading .loading-icon {\n display: block;\n}\n.ea-input_container .ea-input_wrap .ea-input_suggestion-wrap.is-open {\n transform: scaleY(1);\n}\n.ea-input_container .ea-input_wrap.word-limit {\n border: 1px solid #dcdfe6;\n border-radius: 3px;\n}\n.ea-input_container .ea-input_wrap.word-limit .ea-input_inner {\n border: 0;\n}\n.ea-input_container .ea-input_wrap.word-limit .ea-input_word-limit {\n display: flex;\n justify-content: center;\n align-items: center;\n flex-wrap: wrap;\n padding-right: 0.5rem;\n font-size: 0.75rem;\n text-align: center;\n}\n.ea-input_container .ea-input_wrap.with-transition .ea-input_inner {\n transition: border 0.3s;\n}\n.ea-input_container .ea-input_wrap.with-transition .ea-input_suggestion-wrap {\n transition: transform 0.3s;\n}\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function dispatchEvent(t,e){this.dispatchEvent(new CustomEvent(e,{detail:{value:t.target.value}}))}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function handleSearchResult(e,l){e.querySelectorAll("li").forEach((e=>{e.innerText.includes(l)?e.style.display="block":e.style.display="none"}))}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function initTriggerAfterInputEvent(e,t){e.addEventListener("input",(e=>{const n=Array.from(t.querySelectorAll("li")).some(((t,n)=>t.innerText.includes(e.target.value)));t.classList.toggle("is-open",n&&""!==e.target.value)}))}export function initTriggerOnFocusEvent(e,t){t.addEventListener("focus",(t=>{e.classList.add("is-open")}))}
|
|
@@ -1,458 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import Base from '../Base.js';
|
|
3
|
-
|
|
4
|
-
const stylesheet = `
|
|
5
|
-
.ea-input-number_wrap {
|
|
6
|
-
display: flex;
|
|
7
|
-
align-items: center;
|
|
8
|
-
border: 1px solid transparent;
|
|
9
|
-
border-radius: 3px;
|
|
10
|
-
transition: border 0.2s;
|
|
11
|
-
}
|
|
12
|
-
.ea-input-number_wrap .ea-input-number_sign {
|
|
13
|
-
display: flex;
|
|
14
|
-
align-items: center;
|
|
15
|
-
justify-content: center;
|
|
16
|
-
box-sizing: border-box;
|
|
17
|
-
border: 1px solid #dcdfe6;
|
|
18
|
-
background-color: #f5f7fa;
|
|
19
|
-
height: 2rem;
|
|
20
|
-
width: 2rem;
|
|
21
|
-
cursor: pointer;
|
|
22
|
-
font-size: 1rem;
|
|
23
|
-
line-height: 1;
|
|
24
|
-
user-select: none;
|
|
25
|
-
}
|
|
26
|
-
.ea-input-number_wrap .ea-input-number_sign:first-child {
|
|
27
|
-
border-top-left-radius: 3px;
|
|
28
|
-
border-bottom-left-radius: 3px;
|
|
29
|
-
border-right: 0;
|
|
30
|
-
}
|
|
31
|
-
.ea-input-number_wrap .ea-input-number_sign:last-child {
|
|
32
|
-
border-top-right-radius: 3px;
|
|
33
|
-
border-bottom-right-radius: 3px;
|
|
34
|
-
border-left: 0;
|
|
35
|
-
}
|
|
36
|
-
.ea-input-number_wrap .ea-input-number_sign:hover {
|
|
37
|
-
color: #409eff;
|
|
38
|
-
}
|
|
39
|
-
.ea-input-number_wrap .ea-input-number_sign.disabled {
|
|
40
|
-
pointer-events: none;
|
|
41
|
-
cursor: not-allowed;
|
|
42
|
-
color: #c0c4cc;
|
|
43
|
-
}
|
|
44
|
-
.ea-input-number_wrap .ea-input-number_sign.ea-input-number_sign--medium {
|
|
45
|
-
height: 1.75rem;
|
|
46
|
-
width: 1.75rem;
|
|
47
|
-
}
|
|
48
|
-
.ea-input-number_wrap .ea-input-number_sign.ea-input-number_sign--small {
|
|
49
|
-
height: 1.5rem;
|
|
50
|
-
width: 1.5rem;
|
|
51
|
-
}
|
|
52
|
-
.ea-input-number_wrap .ea-input-number_sign.ea-input-number_sign--mini {
|
|
53
|
-
height: 1.25rem;
|
|
54
|
-
width: 1.25rem;
|
|
55
|
-
}
|
|
56
|
-
.ea-input-number_wrap .ea-input-number_inner {
|
|
57
|
-
box-sizing: border-box;
|
|
58
|
-
box-shadow: none;
|
|
59
|
-
border: 1px solid #dcdfe6;
|
|
60
|
-
outline: 0;
|
|
61
|
-
transition: border 0.2s;
|
|
62
|
-
border-radius: 3px;
|
|
63
|
-
padding: 0.5rem;
|
|
64
|
-
line-height: 0.8;
|
|
65
|
-
font-size: 0.8rem;
|
|
66
|
-
scrollbar-width: none;
|
|
67
|
-
width: 5rem;
|
|
68
|
-
height: 2rem;
|
|
69
|
-
border-radius: 0;
|
|
70
|
-
text-align: center;
|
|
71
|
-
}
|
|
72
|
-
.ea-input-number_wrap .ea-input-number_inner:focus {
|
|
73
|
-
border-color: #409eff;
|
|
74
|
-
}
|
|
75
|
-
.ea-input-number_wrap .ea-input-number_inner::placeholder {
|
|
76
|
-
color: #c0c4cc;
|
|
77
|
-
}
|
|
78
|
-
.ea-input-number_wrap .ea-input-number_inner.invalid {
|
|
79
|
-
border-color: #f56c6c;
|
|
80
|
-
}
|
|
81
|
-
.ea-input-number_wrap .ea-input-number_inner.disabled {
|
|
82
|
-
background-color: #eeeeee;
|
|
83
|
-
color: #c0c4cc;
|
|
84
|
-
}
|
|
85
|
-
.ea-input-number_wrap .ea-input-number_inner.ea-input_clear ::before {
|
|
86
|
-
content: "\e9c3";
|
|
87
|
-
display: block;
|
|
88
|
-
}
|
|
89
|
-
.ea-input-number_wrap .ea-input-number_inner:focus {
|
|
90
|
-
border-color: #dcdfe6;
|
|
91
|
-
}
|
|
92
|
-
.ea-input-number_wrap .ea-input-number_inner.disabled {
|
|
93
|
-
pointer-events: none;
|
|
94
|
-
color: #c0c4cc;
|
|
95
|
-
cursor: not-allowed;
|
|
96
|
-
background-color: #f5f7fa;
|
|
97
|
-
}
|
|
98
|
-
.ea-input-number_wrap .ea-input-number_inner.ea-input-number_inner--medium {
|
|
99
|
-
height: 1.75rem;
|
|
100
|
-
line-height: 1.75rem;
|
|
101
|
-
}
|
|
102
|
-
.ea-input-number_wrap .ea-input-number_inner.ea-input-number_inner--small {
|
|
103
|
-
height: 1.5rem;
|
|
104
|
-
line-height: 1.5rem;
|
|
105
|
-
}
|
|
106
|
-
.ea-input-number_wrap .ea-input-number_inner.ea-input-number_inner--mini {
|
|
107
|
-
height: 1.25rem;
|
|
108
|
-
line-height: 1.25rem;
|
|
109
|
-
}
|
|
110
|
-
.ea-input-number_wrap.focus {
|
|
111
|
-
border: 1px solid #409eff;
|
|
112
|
-
}
|
|
113
|
-
.ea-input-number_wrap.focus .ea-input-number_sign {
|
|
114
|
-
border-color: transparent;
|
|
115
|
-
}
|
|
116
|
-
`;
|
|
117
|
-
|
|
118
|
-
// +/- 符号dom
|
|
119
|
-
const signDom = (sign) => {
|
|
120
|
-
const dom = document.createElement('span');
|
|
121
|
-
dom.className = `ea-input-number_sign ${sign}`;
|
|
122
|
-
|
|
123
|
-
dom.innerHTML = sign === 'minus' ? '-' : '+';
|
|
124
|
-
|
|
125
|
-
return dom;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// input dom
|
|
129
|
-
const inputDom = () => {
|
|
130
|
-
const input = document.createElement('input');
|
|
131
|
-
input.className = 'ea-input-number_inner';
|
|
132
|
-
input.type = 'text';
|
|
133
|
-
input.value = 0;
|
|
134
|
-
|
|
135
|
-
return input;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export class EaInputNumber extends Base {
|
|
139
|
-
#wrap;
|
|
140
|
-
#input;
|
|
141
|
-
#signMinus;
|
|
142
|
-
#signPlus;
|
|
143
|
-
constructor() {
|
|
144
|
-
super();
|
|
145
|
-
|
|
146
|
-
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
147
|
-
const wrap = document.createElement('div');
|
|
148
|
-
wrap.className = 'ea-input-number_wrap';
|
|
149
|
-
|
|
150
|
-
const input = inputDom();
|
|
151
|
-
const signMinus = signDom('minus');
|
|
152
|
-
const signPlus = signDom('plus');
|
|
153
|
-
wrap.appendChild(signMinus);
|
|
154
|
-
wrap.appendChild(input);
|
|
155
|
-
wrap.appendChild(signPlus);
|
|
156
|
-
|
|
157
|
-
this.#wrap = wrap;
|
|
158
|
-
this.#input = input;
|
|
159
|
-
this.#signMinus = signMinus;
|
|
160
|
-
this.#signPlus = signPlus;
|
|
161
|
-
|
|
162
|
-
this.build(shadowRoot, stylesheet);
|
|
163
|
-
this.shadowRoot.appendChild(wrap);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// 处理输入框加减事件
|
|
167
|
-
signEvent(sign, precision, eventName) {
|
|
168
|
-
if (this.getAttrBoolean('disabled')) return;
|
|
169
|
-
|
|
170
|
-
const val = Number(this.#input.value);
|
|
171
|
-
|
|
172
|
-
const defaultStepPrecision = this.#input.value.split('.')[1]; // 简单处理精度问题
|
|
173
|
-
const res = sign === "minu" ? val - this.step : val + this.step; // 处理加减问题
|
|
174
|
-
|
|
175
|
-
if (precision) {
|
|
176
|
-
this.#input.value = (res).toFixed(precision);
|
|
177
|
-
}
|
|
178
|
-
// 简单处理精度问题
|
|
179
|
-
else if (defaultStepPrecision?.length) {
|
|
180
|
-
this.#input.value = (res).toFixed(defaultStepPrecision.length);
|
|
181
|
-
} else {
|
|
182
|
-
this.#input.value = res;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 为外部dom添加事件监听
|
|
186
|
-
if (eventName) {
|
|
187
|
-
this.#input.dispatchEvent(
|
|
188
|
-
new CustomEvent(eventName, {
|
|
189
|
-
detail: {
|
|
190
|
-
value: this.#input.value
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 限制输入框的值
|
|
197
|
-
this.handleLimitVal();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// 处理连加连减事件
|
|
201
|
-
handleCounterEvent(sign) {
|
|
202
|
-
let timer = setInterval(() => {
|
|
203
|
-
this.signEvent(sign, this.precision);
|
|
204
|
-
this.handleLimitVal();
|
|
205
|
-
}, 100);
|
|
206
|
-
|
|
207
|
-
this.addEventListener('mouseup', function () {
|
|
208
|
-
clearInterval(timer);
|
|
209
|
-
timer = null;
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// 处理输入框聚焦失焦事件
|
|
214
|
-
handleWrapBorder(flag) {
|
|
215
|
-
this.#wrap.classList.toggle('focus', flag)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
handleLimitVal() {
|
|
219
|
-
if (this.min === false && this.max === false) return;
|
|
220
|
-
|
|
221
|
-
// 限制输入框的值
|
|
222
|
-
if (this.min !== undefined && this.#input.value < this.min) {
|
|
223
|
-
this.#input.value = this.min;
|
|
224
|
-
} else if (this.max !== undefined && this.#input.value > this.max) {
|
|
225
|
-
this.#input.value = this.max;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// 当达到限制值时, 禁用加减按钮
|
|
229
|
-
if (this.#input.value == this.min) {
|
|
230
|
-
this.#signMinus.classList.add('disabled');
|
|
231
|
-
} else if (this.#input.value == this.max) {
|
|
232
|
-
this.#signPlus.classList.add('disabled');
|
|
233
|
-
} else {
|
|
234
|
-
try {
|
|
235
|
-
this.#signMinus.classList.remove('disabled');
|
|
236
|
-
this.#signPlus.classList.remove('disabled');
|
|
237
|
-
} catch (error) {
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ------- value 值 -------
|
|
244
|
-
// #region
|
|
245
|
-
get value() {
|
|
246
|
-
return this.getAttribute('value') || 0;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
set value(val) {
|
|
250
|
-
val = this.precision ? Number(val).toFixed(this.precision) : Number(val);
|
|
251
|
-
this.setAttribute('value', val);
|
|
252
|
-
|
|
253
|
-
this.#input.value = val;
|
|
254
|
-
}
|
|
255
|
-
// #endregion
|
|
256
|
-
// ------- end -------
|
|
257
|
-
|
|
258
|
-
// ------- disabled 禁用 -------
|
|
259
|
-
// #region
|
|
260
|
-
get disabled() {
|
|
261
|
-
return this.getAttrBoolean('disabled');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
set disabled(flag) {
|
|
265
|
-
this.toggleAttr('disabled', flag);
|
|
266
|
-
|
|
267
|
-
this.#input.disabled = flag;
|
|
268
|
-
this.#input.classList.toggle('disabled', flag);
|
|
269
|
-
this.#signMinus.classList.toggle('disabled', flag);
|
|
270
|
-
this.#signPlus.classList.toggle('disabled', flag);
|
|
271
|
-
}
|
|
272
|
-
// #endregion
|
|
273
|
-
// ------- end -------
|
|
274
|
-
|
|
275
|
-
// ------- step 加减的步长 -------
|
|
276
|
-
// #region
|
|
277
|
-
get step() {
|
|
278
|
-
return Number(this.getAttribute('step')) || 1;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
set step(step) {
|
|
282
|
-
this.setAttribute('step', step);
|
|
283
|
-
}
|
|
284
|
-
// #endregion
|
|
285
|
-
// ------- end -------
|
|
286
|
-
|
|
287
|
-
// ------- step-strictly 严格步长 -------
|
|
288
|
-
// #region
|
|
289
|
-
get stepStrictly() {
|
|
290
|
-
return this.getAttrBoolean('step-strictly');
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
set stepStrictly(flag) {
|
|
294
|
-
this.toggleAttr('step-strictly', flag);
|
|
295
|
-
}
|
|
296
|
-
// #endregion
|
|
297
|
-
// ------- end -------
|
|
298
|
-
|
|
299
|
-
// ------- min/max 限制最大/最小值 -------
|
|
300
|
-
// #region
|
|
301
|
-
get min() {
|
|
302
|
-
if (this.getAttribute('min') === null) return false;
|
|
303
|
-
else return Number(this.getAttribute('min')) || 0;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
set min(min) {
|
|
307
|
-
if (min === false) {
|
|
308
|
-
this.removeAttribute('min');
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
this.setAttribute('min', min);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
get max() {
|
|
316
|
-
if (this.getAttribute('max') === null) return false;
|
|
317
|
-
else return Number(this.getAttribute('max'));
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
set max(max) {
|
|
321
|
-
this.setAttribute('max', max);
|
|
322
|
-
}
|
|
323
|
-
// #endregion
|
|
324
|
-
// ------- end -------
|
|
325
|
-
|
|
326
|
-
// ------- precision 精度 -------
|
|
327
|
-
// #region
|
|
328
|
-
get precision() {
|
|
329
|
-
const num = Number(this.getAttribute('precision'));
|
|
330
|
-
if (num < 0 || !Number.isInteger(num)) {
|
|
331
|
-
console.warn(`precision must be a positive integer(precisionValue: ${num})`);
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return Number(this.getAttribute('precision')) || 0;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
set precision(precision) {
|
|
339
|
-
this.setAttribute('precision', precision);
|
|
340
|
-
}
|
|
341
|
-
// #endregion
|
|
342
|
-
// ------- end -------
|
|
343
|
-
|
|
344
|
-
// ------- size 按钮大小(medium、small、mini) -------
|
|
345
|
-
// #region
|
|
346
|
-
get size() {
|
|
347
|
-
return this.getAttribute('size') || '';
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
handleSize(size) {
|
|
351
|
-
this.#signMinus.classList.add(`ea-input-number_sign--${size}`);
|
|
352
|
-
this.#signPlus.classList.add(`ea-input-number_sign--${size}`);
|
|
353
|
-
this.#input.classList.add(`ea-input-number_inner--${size}`);
|
|
354
|
-
this.setAttribute('size', size);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
set size(size) {
|
|
358
|
-
switch (size) {
|
|
359
|
-
case 'medium':
|
|
360
|
-
this.handleSize('medium');
|
|
361
|
-
break;
|
|
362
|
-
case 'small':
|
|
363
|
-
this.handleSize('small');
|
|
364
|
-
break;
|
|
365
|
-
case 'mini':
|
|
366
|
-
this.handleSize('mini');
|
|
367
|
-
break;
|
|
368
|
-
default:
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
// #endregion
|
|
373
|
-
// ------- end -------
|
|
374
|
-
|
|
375
|
-
init() {
|
|
376
|
-
const that = this;
|
|
377
|
-
|
|
378
|
-
// 禁用
|
|
379
|
-
this.disabled = this.disabled;
|
|
380
|
-
|
|
381
|
-
// 大小
|
|
382
|
-
this.size = this.size;
|
|
383
|
-
|
|
384
|
-
// 默认值
|
|
385
|
-
if (this.min) this.value = this.min;
|
|
386
|
-
else this.value = this.value;
|
|
387
|
-
|
|
388
|
-
// 限制值初始化
|
|
389
|
-
this.handleLimitVal();
|
|
390
|
-
|
|
391
|
-
// 输入框获取焦点
|
|
392
|
-
this.#input.addEventListener('focus', function (e) {
|
|
393
|
-
that.handleWrapBorder(true);
|
|
394
|
-
|
|
395
|
-
this.dispatchEvent(new CustomEvent("blur",
|
|
396
|
-
{ detail: { value: this.value } }
|
|
397
|
-
))
|
|
398
|
-
})
|
|
399
|
-
|
|
400
|
-
// 输入框失去焦点
|
|
401
|
-
this.#input.addEventListener('blur', function (e) {
|
|
402
|
-
that.handleWrapBorder(false);
|
|
403
|
-
|
|
404
|
-
if (that.stepStrictly) {
|
|
405
|
-
const step = that.step;
|
|
406
|
-
const val = Number(that.#input.value);
|
|
407
|
-
const mod = val % step;
|
|
408
|
-
|
|
409
|
-
if (val < 0 && mod !== 0) that.#input.value = val - mod - step;
|
|
410
|
-
else if (val < 0 && mod === 0) that.#input.value = val;
|
|
411
|
-
else if (mod === 0) that.#input.value = val;
|
|
412
|
-
else that.#input.value = val - mod + step;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
that.handleLimitVal();
|
|
416
|
-
|
|
417
|
-
this.dispatchEvent(new CustomEvent("blur",
|
|
418
|
-
{ detail: { value: this.value } }
|
|
419
|
-
))
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
// 减号
|
|
423
|
-
this.#signMinus.addEventListener('click', function () {
|
|
424
|
-
that.signEvent("minu", that.precision, "minus");
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
// 加号
|
|
428
|
-
this.#signPlus.addEventListener('click', function (e) {
|
|
429
|
-
that.signEvent("plus", that.precision, "plus");
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
// 连减
|
|
433
|
-
this.#signMinus.addEventListener('mousedown', function (e) {
|
|
434
|
-
that.handleCounterEvent("minu", that.precision);
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
// 连加
|
|
438
|
-
this.#signPlus.addEventListener('mousedown', function () {
|
|
439
|
-
that.handleCounterEvent("plus", that.precision);
|
|
440
|
-
})
|
|
441
|
-
|
|
442
|
-
// 输入框值改变时
|
|
443
|
-
this.#input.addEventListener('change', function (e) {
|
|
444
|
-
that.handleLimitVal();
|
|
445
|
-
|
|
446
|
-
this.dispatchEvent(new CustomEvent("change", { detail: { value: this.value } }))
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
connectedCallback() {
|
|
452
|
-
this.init();
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (!window.customElements.get("ea-input-number")) {
|
|
457
|
-
window.customElements.define("ea-input-number", EaInputNumber);
|
|
458
|
-
}
|
|
1
|
+
import Base from"../Base.js";import{stylesheet}from"./src/style/stylesheet.js";import{handleCustomEvent}from"./src/utils/handleCustomEvent.js";export class EaInputNumber extends Base{#t;#e;#i;#s;constructor(){super();const t=this.attachShadow({mode:"open"});t.innerHTML='\n <div class="ea-input-number_wrap" part="container">\n <span class="ea-input-number_sign minus" part="minus-wrap">-</span>\n <input class="ea-input-number_inner" part="input" type="text" />\n <span class="ea-input-number_sign plus" part="plus-wrap">+</span>\n </div>\n ',this.#t=t.querySelector(".ea-input-number_wrap"),this.#e=t.querySelector(".ea-input-number_inner"),this.#i=t.querySelector(".minus"),this.#s=t.querySelector(".plus"),this.build(t,stylesheet)}#n(t,e,i){if(this.getAttrBoolean("disabled"))return;const s=Number(this.#e.value),n=this.#e.value.split(".")[1],u="minus"===t?s-this.step:s+this.step;this.#e.value=e?u.toFixed(e):n?.length?u.toFixed(n.length):u,this.#u(),i&&this.#a("change",u)}#l(t){let e=setInterval((()=>{this.#n(t,this.precision),this.#u()}),100);this.addEventListener("mouseup",(function(){clearInterval(e),e=null}))}#u(){!1===this.min&&!1===this.max||(void 0!==this.min&&this.#e.value<this.min?this.#e.value=this.min:void 0!==this.max&&this.#e.value>this.max&&(this.#e.value=this.max),this.#i.classList.toggle("disabled",this.#e.value==this.min),this.#s.classList.toggle("disabled",this.#e.value==this.max))}#h(){isNaN(Number(this.#e.value))?this.#e.value=this.value:this.value=Number(this.#e.value)}#a(t,e=this.value){handleCustomEvent.call(this,t,{value:e})}get value(){return Number(this.getAttribute("value"))||0}set value(t){t=this.precision?Number(t).toFixed(this.precision):Number(t),this.setAttribute("value",t),this.#e.value=t}get disabled(){return this.getAttrBoolean("disabled")}set disabled(t){this.toggleAttr("disabled",t),this.#e.disabled=t,this.#t.classList.toggle("disabled",t),this.style.cursor=t?"not-allowed":"pointer"}get readonly(){return this.getAttrBoolean("readonly")}set readonly(t){t&&(this.#e.readOnly=t)}get step(){return this.getAttrNumber("step")||1}set step(t){t&&this.setAttribute("step",t)}get stepStrictly(){return this.getAttrBoolean("step-strictly")}set stepStrictly(t){this.toggleAttr("step-strictly",t)}get min(){return this.getAttrNumber("min")||-1/0}set min(t){Number.isNaN(t)&&!Number.isFinite(t)&&this.setAttribute("min",t)}get max(){return this.getAttrNumber("max")||1/0}set max(t){t&&this.setAttribute("max",t)}get precision(){const t=this.getAttrNumber("precision");return t<0||!Number.isInteger(t)?0:t}set precision(t){t&&this.setAttribute("precision",t)}get sizeType(){return["medium","small","mini"]}get size(){const t=this.getAttribute("size");return this.sizeType.includes(t)?t:"medium"}set size(t){this.setAttribute("size",t),this.#t.classList.add(`ea-input-number--${t}`)}connectedCallback(){this.style.display="inline-block",this.disabled=this.disabled,this.readonly=this.readonly,this.size=this.size,this.value=this.value,this.min!==-1/0&&(this.value=this.min),this.#u(),this.#e.addEventListener("focus",(t=>{this.#t.classList.add("focus"),this.#a("focus")})),this.#e.addEventListener("blur",(t=>{if(this.#t.classList.remove("focus"),this.stepStrictly){const t=that.step,e=Number(that.#e.value),i=e%t;e<0&&0!==i?that.#e.value=e-i-t:e<0&&0===i||0===i?that.#e.value=e:this.#e.value=e-i+t}this.#u(),this.#a("blur")})),this.#i.addEventListener("click",(()=>{this.#h(),this.#n("minus",this.precision,"minus")})),this.#s.addEventListener("click",(()=>{this.#h(),this.#n("plus",this.precision,"plus")})),this.#i.addEventListener("mousedown",(()=>{this.#h(),this.#l("minus",this.precision)})),this.#s.addEventListener("mousedown",(()=>{this.#h(),this.#l("plus",this.precision)})),this.#e.addEventListener("input",(()=>{this.#h(),this.#u(),this.#a("change")}))}}window.customElements.get("ea-input-number")||window.customElements.define("ea-input-number",EaInputNumber);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const stylesheet='\n.ea-input-number_wrap {\n display: flex;\n align-items: center;\n border: 1px solid transparent;\n border-radius: 3px;\n transition: border 0.2s;\n}\n.ea-input-number_wrap .ea-input-number_sign {\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n border: 1px solid #dcdfe6;\n background-color: #f5f7fa;\n height: 2rem;\n width: 2rem;\n cursor: pointer;\n font-size: 1rem;\n line-height: 1;\n user-select: none;\n}\n.ea-input-number_wrap .ea-input-number_sign:first-child {\n border-top-left-radius: 3px;\n border-bottom-left-radius: 3px;\n border-right: 0;\n}\n.ea-input-number_wrap .ea-input-number_sign:last-child {\n border-top-right-radius: 3px;\n border-bottom-right-radius: 3px;\n border-left: 0;\n}\n.ea-input-number_wrap .ea-input-number_sign:hover {\n color: #409eff;\n}\n.ea-input-number_wrap .ea-input-number_sign.disabled {\n pointer-events: none;\n cursor: not-allowed;\n color: #c0c4cc;\n}\n.ea-input-number_wrap .ea-input-number_inner {\n box-sizing: border-box;\n box-shadow: none;\n border: 1px solid #dcdfe6;\n outline: 0;\n transition: border 0.2s;\n border-radius: 3px;\n padding: 0.5rem;\n line-height: 0.8;\n font-size: 0.8rem;\n scrollbar-width: none;\n width: 5rem;\n height: 2rem;\n border-radius: 0;\n text-align: center;\n}\n.ea-input-number_wrap .ea-input-number_inner:focus {\n border-color: #409eff;\n}\n.ea-input-number_wrap .ea-input-number_inner::placeholder {\n color: #c0c4cc;\n}\n.ea-input-number_wrap .ea-input-number_inner.invalid {\n border-color: #f56c6c;\n}\n.ea-input-number_wrap .ea-input-number_inner.disabled {\n background-color: #eeeeee;\n color: #c0c4cc;\n}\n.ea-input-number_wrap .ea-input-number_inner.ea-input_clear ::before {\n content: "e9c3";\n display: block;\n}\n.ea-input-number_wrap .ea-input-number_inner:focus {\n border-color: #dcdfe6;\n}\n.ea-input-number_wrap .ea-input-number_inner.disabled {\n pointer-events: none;\n cursor: not-allowed;\n color: #c0c4cc;\n background-color: #f5f7fa;\n}\n.ea-input-number_wrap.focus {\n border: 1px solid #409eff;\n}\n.ea-input-number_wrap.focus .ea-input-number_sign {\n border-color: transparent;\n}\n.ea-input-number_wrap.disabled {\n pointer-events: none;\n cursor: not-allowed;\n}\n.ea-input-number_wrap.disabled .ea-input-number_sign,\n.ea-input-number_wrap.disabled .ea-input-number_inner {\n color: #c0c4cc;\n border-color: #dcdfe6;\n}\n.ea-input-number_wrap.ea-input-number--medium .ea-input-number_sign {\n height: 1.75rem;\n width: 1.75rem;\n}\n.ea-input-number_wrap.ea-input-number--medium .ea-input-number_inner {\n height: 1.75rem;\n line-height: 1.75rem;\n}\n.ea-input-number_wrap.ea-input-number--small .ea-input-number_sign {\n height: 1.5rem;\n width: 1.5rem;\n}\n.ea-input-number_wrap.ea-input-number--small .ea-input-number_inner {\n height: 1.5rem;\n line-height: 1.5rem;\n}\n.ea-input-number_wrap.ea-input-number--mini .ea-input-number_sign {\n height: 1.25rem;\n width: 1.25rem;\n}\n.ea-input-number_wrap.ea-input-number--mini .ea-input-number_inner {\n height: 1.25rem;\n line-height: 1.25rem;\n}\n';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function handleCustomEvent(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))}
|