@semcore/input-number 17.2.1-prerelease.0 → 17.2.2-prerelease.0
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/CHANGELOG.md +10 -1
- package/lib/cjs/InputNumber.js +100 -62
- package/lib/cjs/InputNumber.js.map +1 -1
- package/lib/cjs/InputNumber.type.js +2 -0
- package/lib/cjs/InputNumber.type.js.map +1 -0
- package/lib/cjs/buttons.js.map +1 -1
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/InputNumber.js +101 -62
- package/lib/es6/InputNumber.js.map +1 -1
- package/lib/es6/InputNumber.type.js +2 -0
- package/lib/es6/InputNumber.type.js.map +1 -0
- package/lib/es6/buttons.js.map +1 -1
- package/lib/es6/index.js +1 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/esm/InputNumber.mjs +94 -63
- package/lib/esm/InputNumber.type.mjs +1 -0
- package/lib/esm/index.mjs +1 -0
- package/lib/types/InputNumber.d.ts +9 -0
- package/lib/types/InputNumber.type.d.ts +92 -0
- package/lib/types/buttons.d.ts +3 -0
- package/lib/types/index.d.ts +3 -63
- package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +59 -0
- package/package.json +6 -6
- package/vite.config.ts +1 -1
- package/lib/cjs/index.d.js +0 -2
- package/lib/cjs/index.d.js.map +0 -1
- package/lib/es6/index.d.js +0 -2
- package/lib/es6/index.d.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__intergalactic-dynamic-locales.js","names":["de","en","es","fr","it","ja","ko","nl","pl","pt","sv","tr","vi","zh","localizedMessages"],"sources":["../../../src/translations/__intergalactic-dynamic-locales.ts"],"sourcesContent":["import de from './de.json';\nimport en from './en.json';\nimport es from './es.json';\nimport fr from './fr.json';\nimport it from './it.json';\nimport ja from './ja.json';\nimport ko from './ko.json';\nimport nl from './nl.json';\nimport pl from './pl.json';\nimport pt from './pt.json';\nimport sv from './sv.json';\nimport tr from './tr.json';\nimport vi from './vi.json';\nimport zh from './zh.json';\n\nexport const localizedMessages = {\n de,\n en,\n es,\n fr,\n it,\n ja,\n ko,\n nl,\n pt,\n tr,\n vi,\n zh,\n pl,\n sv,\n};\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAE1B,OAAO,MAAMC,iBAAiB,GAAG;EAC/Bd,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFE,EAAE;EACFE,EAAE;EACFC,EAAE;EACFC,EAAE;EACFL,EAAE;EACFE;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"__intergalactic-dynamic-locales.js","names":["de","en","es","fr","it","ja","ko","nl","pl","pt","sv","tr","vi","zh","localizedMessages"],"sources":["../../../src/translations/__intergalactic-dynamic-locales.ts"],"sourcesContent":["import de from './de.json';\nimport en from './en.json';\nimport es from './es.json';\nimport fr from './fr.json';\nimport it from './it.json';\nimport ja from './ja.json';\nimport ko from './ko.json';\nimport nl from './nl.json';\nimport pl from './pl.json';\nimport pt from './pt.json';\nimport sv from './sv.json';\nimport tr from './tr.json';\nimport vi from './vi.json';\nimport zh from './zh.json';\n\nexport const localizedMessages = {\n de,\n en,\n es,\n fr,\n it,\n ja,\n ko,\n nl,\n pt,\n tr,\n vi,\n zh,\n pl,\n sv,\n};\n\nexport type LocalizedMessages = typeof localizedMessages;\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAC1B,OAAOC,EAAE,MAAM,WAAW;AAE1B,OAAO,MAAMC,iBAAiB,GAAG;EAC/Bd,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFC,EAAE;EACFE,EAAE;EACFE,EAAE;EACFC,EAAE;EACFC,EAAE;EACFL,EAAE;EACFE;AACF,CAAC","ignoreList":[]}
|
package/lib/esm/InputNumber.mjs
CHANGED
|
@@ -12,19 +12,19 @@ const style = (
|
|
|
12
12
|
/*__reshadow_css_start__*/
|
|
13
13
|
(sstyled.insert(
|
|
14
14
|
/*__inner_css_start__*/
|
|
15
|
-
".
|
|
15
|
+
".___SValue_1i69c_gg_:focus~.___SControls_1i69c_gg_{display:flex}.___SControls_1i69c_gg_{display:none;flex-flow:column;justify-content:center;height:100%;box-sizing:border-box}.___SControls_1i69c_gg_.__showControls_1i69c_gg_{display:flex}.___SDown_1i69c_gg_,.___SUp_1i69c_gg_{padding:0;width:16px;color:var(--intergalactic-icon-secondary-neutral,rgba(0,5,2,.385));box-sizing:border-box;display:inline-flex;justify-content:center;border:none;background:none;cursor:pointer}@media (color-gamut:p3){.___SDown_1i69c_gg_,.___SUp_1i69c_gg_{color:var(--intergalactic-icon-secondary-neutral,oklch(.104 .023 162.3/.385))}}.___SDown_1i69c_gg_:focus,.___SUp_1i69c_gg_:focus{outline:none}@media (hover:hover){.___SDown_1i69c_gg_:hover,.___SUp_1i69c_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active,#0005026e)}@media (color-gamut:p3){.___SDown_1i69c_gg_:hover,.___SUp_1i69c_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active,oklch(.1 .023 159.1/.433))}}}.___SUp_1i69c_gg_{padding-bottom:1px}.___SDown_1i69c_gg_{padding-top:1px}.___SValue_1i69c_gg_::-webkit-inner-spin-button,.___SValue_1i69c_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_1i69c_gg_._type_number_1i69c_gg_{-moz-appearance:textfield}.___SValue_1i69c_gg_.__disabled_1i69c_gg_~.___SControls_1i69c_gg_{opacity:var(--intergalactic-disabled-opacity,.4);cursor:default;pointer-events:none}.___SValueHidden_1i69c_gg_{position:absolute;top:0;width:1px;height:1px;padding:0;overflow:hidden}",
|
|
16
16
|
/*__inner_css_end__*/
|
|
17
|
-
"
|
|
17
|
+
"1i69c_gg_"
|
|
18
18
|
), /*__reshadow_css_end__*/
|
|
19
19
|
{
|
|
20
|
-
"__SValue": "
|
|
21
|
-
"__SControls": "
|
|
22
|
-
"_showControls": "
|
|
23
|
-
"__SUp": "
|
|
24
|
-
"__SDown": "
|
|
25
|
-
"_disabled": "
|
|
26
|
-
"__SValueHidden": "
|
|
27
|
-
"_type_number": "
|
|
20
|
+
"__SValue": "___SValue_1i69c_gg_",
|
|
21
|
+
"__SControls": "___SControls_1i69c_gg_",
|
|
22
|
+
"_showControls": "__showControls_1i69c_gg_",
|
|
23
|
+
"__SUp": "___SUp_1i69c_gg_",
|
|
24
|
+
"__SDown": "___SDown_1i69c_gg_",
|
|
25
|
+
"_disabled": "__disabled_1i69c_gg_",
|
|
26
|
+
"__SValueHidden": "___SValueHidden_1i69c_gg_",
|
|
27
|
+
"_type_number": "_type_number_1i69c_gg_"
|
|
28
28
|
})
|
|
29
29
|
);
|
|
30
30
|
function parseValueWithMinMax(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
|
|
@@ -43,7 +43,8 @@ class InputNumber extends Component {
|
|
|
43
43
|
}
|
|
44
44
|
getValueProps() {
|
|
45
45
|
const numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
|
|
46
|
-
style: "decimal"
|
|
46
|
+
style: "decimal",
|
|
47
|
+
maximumFractionDigits: 100
|
|
47
48
|
});
|
|
48
49
|
return {
|
|
49
50
|
inputRef: this.inputRef,
|
|
@@ -54,11 +55,9 @@ class InputNumber extends Component {
|
|
|
54
55
|
}
|
|
55
56
|
getControlsProps() {
|
|
56
57
|
const {
|
|
57
|
-
size,
|
|
58
58
|
getI18nText
|
|
59
59
|
} = this.asProps;
|
|
60
60
|
return {
|
|
61
|
-
size,
|
|
62
61
|
increment: this.increment,
|
|
63
62
|
decrement: this.decrement,
|
|
64
63
|
getI18nText
|
|
@@ -83,6 +82,9 @@ _defineProperty(InputNumber, "defaultProps", {
|
|
|
83
82
|
class Value extends Component {
|
|
84
83
|
constructor(...args) {
|
|
85
84
|
super(...args);
|
|
85
|
+
_defineProperty(this, "state", {
|
|
86
|
+
displayValue: ""
|
|
87
|
+
});
|
|
86
88
|
_defineProperty(this, "valueInputRef", /* @__PURE__ */ React.createRef());
|
|
87
89
|
_defineProperty(this, "cursorPosition", -1);
|
|
88
90
|
_defineProperty(this, "getFormattedValue", (value) => {
|
|
@@ -102,9 +104,9 @@ class Value extends Component {
|
|
|
102
104
|
let displayValue = "";
|
|
103
105
|
if (/\.[0-9]*0$/.test(stringNumber)) {
|
|
104
106
|
const [int, decimal] = stringNumber.split(this.separatorDecimal);
|
|
105
|
-
displayValue = numberFormatter.format(int) + this.separatorDecimal + decimal;
|
|
107
|
+
displayValue = numberFormatter.format(+int) + this.separatorDecimal + decimal;
|
|
106
108
|
} else if (stringNumber !== "") {
|
|
107
|
-
displayValue = numberFormatter.format(stringNumber);
|
|
109
|
+
displayValue = numberFormatter.format(+stringNumber);
|
|
108
110
|
}
|
|
109
111
|
return {
|
|
110
112
|
parsedValue: stringNumber,
|
|
@@ -114,21 +116,22 @@ class Value extends Component {
|
|
|
114
116
|
_defineProperty(this, "handleValidation", (event) => {
|
|
115
117
|
const {
|
|
116
118
|
value,
|
|
117
|
-
displayValue,
|
|
118
119
|
min,
|
|
119
120
|
max,
|
|
120
121
|
step
|
|
121
122
|
} = this.asProps;
|
|
123
|
+
const {
|
|
124
|
+
displayValue
|
|
125
|
+
} = this.state;
|
|
122
126
|
const {
|
|
123
127
|
parsedValue
|
|
124
128
|
} = this.valueParser(event.currentTarget.value, value, displayValue);
|
|
125
|
-
const roundCoefficient = step < 1 ? step.toString().split(".")[1].length : 1;
|
|
126
129
|
if (Number.isNaN(value) || Number.isNaN(Number.parseFloat(parsedValue))) {
|
|
127
130
|
event.currentTarget.value = "";
|
|
128
131
|
this.handlers.value("", event);
|
|
129
132
|
} else {
|
|
130
133
|
let numberValue = parseValueWithMinMax(Number.parseFloat(parsedValue), min, max);
|
|
131
|
-
const rounded = this.round(numberValue % step
|
|
134
|
+
const rounded = this.round(numberValue % step);
|
|
132
135
|
if (rounded !== 0) {
|
|
133
136
|
if (rounded >= step / 2) {
|
|
134
137
|
numberValue += step - rounded;
|
|
@@ -136,8 +139,7 @@ class Value extends Component {
|
|
|
136
139
|
numberValue -= rounded;
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
|
-
|
|
140
|
-
this.handlers.value(String(numberValueRounded), event);
|
|
142
|
+
this.handlers.value(this.getDisplayValue(numberValue), event);
|
|
141
143
|
}
|
|
142
144
|
});
|
|
143
145
|
_defineProperty(this, "onWheel", (event) => {
|
|
@@ -147,9 +149,9 @@ class Value extends Component {
|
|
|
147
149
|
if (event.target !== this.valueInputRef.current) return;
|
|
148
150
|
if (document.activeElement !== this.valueInputRef.current) return;
|
|
149
151
|
event.preventDefault();
|
|
150
|
-
if (event.
|
|
152
|
+
if (event.deltaY < 0) {
|
|
151
153
|
this.stepUp(event);
|
|
152
|
-
} else if (event.
|
|
154
|
+
} else if (event.deltaY > 0) {
|
|
153
155
|
this.stepDown(event);
|
|
154
156
|
}
|
|
155
157
|
});
|
|
@@ -160,7 +162,9 @@ class Value extends Component {
|
|
|
160
162
|
value: prevValue
|
|
161
163
|
} = this.asProps;
|
|
162
164
|
if (value === "." || value === "-") {
|
|
163
|
-
this.
|
|
165
|
+
this.setState({
|
|
166
|
+
displayValue: value
|
|
167
|
+
});
|
|
164
168
|
return false;
|
|
165
169
|
}
|
|
166
170
|
if (value.endsWith("-")) {
|
|
@@ -168,7 +172,9 @@ class Value extends Component {
|
|
|
168
172
|
}
|
|
169
173
|
if (value.endsWith(".")) {
|
|
170
174
|
if (value.length > prevValue.length) {
|
|
171
|
-
this.
|
|
175
|
+
this.setState({
|
|
176
|
+
displayValue: numberFormatter.format(value) + this.separatorDecimal
|
|
177
|
+
});
|
|
172
178
|
return false;
|
|
173
179
|
} else {
|
|
174
180
|
this.handlers.value(value.slice(0, -1), event);
|
|
@@ -177,7 +183,7 @@ class Value extends Component {
|
|
|
177
183
|
}
|
|
178
184
|
const digits = /^[0-9.-]+$/.test(value);
|
|
179
185
|
if (digits || value === "") {
|
|
180
|
-
this.handlers.value(value, event);
|
|
186
|
+
this.handlers.value(this.limitDecimals(value), event);
|
|
181
187
|
}
|
|
182
188
|
});
|
|
183
189
|
_defineProperty(this, "handleKeyUp", (event) => {
|
|
@@ -191,7 +197,7 @@ class Value extends Component {
|
|
|
191
197
|
const length = value.length;
|
|
192
198
|
const {
|
|
193
199
|
displayValue
|
|
194
|
-
} = this.
|
|
200
|
+
} = this.state;
|
|
195
201
|
if (event.key === "." || event.key === ",") {
|
|
196
202
|
if (value.indexOf(this.separatorDecimal) === -1 && event.key === ",") {
|
|
197
203
|
event.currentTarget.value = value + ".";
|
|
@@ -204,11 +210,13 @@ class Value extends Component {
|
|
|
204
210
|
if (event.key === "Backspace" && value.endsWith(this.separatorDecimal)) {
|
|
205
211
|
event.preventDefault();
|
|
206
212
|
event.stopPropagation();
|
|
207
|
-
this.
|
|
213
|
+
this.setState({
|
|
214
|
+
displayValue: displayValue?.slice(0, -1)
|
|
215
|
+
});
|
|
208
216
|
return false;
|
|
209
217
|
}
|
|
210
218
|
if (element.selectionStart !== length && (event.key === "Backspace" || event.key === this.separatorDecimal || ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(event.key))) {
|
|
211
|
-
const afterSelection = value.slice(element.selectionEnd);
|
|
219
|
+
const afterSelection = value.slice(element.selectionEnd ?? void 0);
|
|
212
220
|
requestAnimationFrame(() => {
|
|
213
221
|
const newValue = this.state.displayValue;
|
|
214
222
|
const index = newValue.lastIndexOf(afterSelection);
|
|
@@ -245,44 +253,42 @@ class Value extends Component {
|
|
|
245
253
|
}
|
|
246
254
|
});
|
|
247
255
|
_defineProperty(this, "moveSelectionLeft", (element, cursorIndex) => {
|
|
256
|
+
if (element.selectionStart === null) return;
|
|
248
257
|
const value = element.value;
|
|
249
258
|
const nextPosition = element.selectionStart - 1 >= 0 ? element.selectionStart - 1 : 0;
|
|
250
259
|
const cursorPosition = value[element.selectionStart - cursorIndex] === this.separatorThousands ? element.selectionStart - cursorIndex : nextPosition;
|
|
251
260
|
if (this.cursorPosition === -1) {
|
|
252
261
|
element.setSelectionRange(cursorPosition, cursorPosition);
|
|
253
262
|
} else {
|
|
254
|
-
if (element.selectionStart <= this.cursorPosition && element.selectionEnd === this.cursorPosition) {
|
|
263
|
+
if (this.cursorPosition && element.selectionStart <= this.cursorPosition && element.selectionEnd === this.cursorPosition) {
|
|
255
264
|
element.setSelectionRange(cursorPosition, element.selectionEnd);
|
|
256
|
-
} else {
|
|
265
|
+
} else if (element.selectionEnd !== null) {
|
|
257
266
|
element.setSelectionRange(element.selectionStart, value[element.selectionEnd - cursorIndex] === this.separatorThousands ? element.selectionEnd - cursorIndex : element.selectionEnd - 1);
|
|
258
267
|
}
|
|
259
268
|
}
|
|
260
269
|
});
|
|
261
270
|
_defineProperty(this, "moveSelectionRight", (element, cursorIndex) => {
|
|
271
|
+
if (element.selectionEnd === null) return;
|
|
262
272
|
const value = element.value;
|
|
263
273
|
const nextPosition = element.selectionEnd + 1;
|
|
264
274
|
const cursorPosition = value[element.selectionEnd] === this.separatorThousands ? element.selectionEnd + cursorIndex : nextPosition;
|
|
265
275
|
if (this.cursorPosition === -1) {
|
|
266
276
|
element.setSelectionRange(cursorPosition, cursorPosition);
|
|
267
277
|
} else {
|
|
268
|
-
if (element.selectionEnd >= this.cursorPosition && element.selectionStart === this.cursorPosition) {
|
|
278
|
+
if (this.cursorPosition && element.selectionEnd >= this.cursorPosition && element.selectionStart === this.cursorPosition) {
|
|
269
279
|
element.setSelectionRange(element.selectionStart, cursorPosition);
|
|
270
|
-
} else {
|
|
280
|
+
} else if (element.selectionStart !== null) {
|
|
271
281
|
element.setSelectionRange(value[element.selectionStart] === this.separatorThousands ? element.selectionStart + cursorIndex : element.selectionStart + 1, element.selectionEnd);
|
|
272
282
|
}
|
|
273
283
|
}
|
|
274
284
|
});
|
|
275
285
|
_defineProperty(this, "handleClick", (event) => {
|
|
276
|
-
const element = event.
|
|
286
|
+
const element = event.currentTarget;
|
|
277
287
|
const value = element.value;
|
|
278
|
-
if (value[element.selectionStart - 1] === this.separatorThousands) {
|
|
288
|
+
if (element.selectionStart !== null && value[element.selectionStart - 1] === this.separatorThousands) {
|
|
279
289
|
element.setSelectionRange(element.selectionStart - 1, element.selectionEnd - 1);
|
|
280
290
|
}
|
|
281
291
|
});
|
|
282
|
-
_defineProperty(this, "handleBlur", (event) => {
|
|
283
|
-
this.cursorPosition = -1;
|
|
284
|
-
this.handleValidation(event);
|
|
285
|
-
});
|
|
286
292
|
_defineProperty(this, "stepUp", (event) => {
|
|
287
293
|
const {
|
|
288
294
|
max = Number.MAX_SAFE_INTEGER,
|
|
@@ -296,10 +302,9 @@ class Value extends Component {
|
|
|
296
302
|
} else {
|
|
297
303
|
numberValue = Number.parseFloat(value);
|
|
298
304
|
}
|
|
299
|
-
if (
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
305
|
+
if (Number.isNaN(numberValue)) return;
|
|
306
|
+
const nextValue = Math.min(numberValue + step, max);
|
|
307
|
+
this.handlers.value(this.getDisplayValue(nextValue), event);
|
|
303
308
|
});
|
|
304
309
|
_defineProperty(this, "stepDown", (event) => {
|
|
305
310
|
const {
|
|
@@ -314,25 +319,27 @@ class Value extends Component {
|
|
|
314
319
|
} else {
|
|
315
320
|
numberValue = Number.parseFloat(value);
|
|
316
321
|
}
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
322
|
+
if (Number.isNaN(numberValue)) return;
|
|
323
|
+
const nextValue = Math.max(numberValue - step, min);
|
|
324
|
+
this.handlers.value(this.getDisplayValue(nextValue), event);
|
|
321
325
|
});
|
|
322
326
|
}
|
|
323
327
|
uncontrolledProps() {
|
|
324
328
|
return {
|
|
325
|
-
displayValue: null,
|
|
326
329
|
value: [null, (newValue) => {
|
|
327
330
|
const {
|
|
328
|
-
value: prevValue,
|
|
329
331
|
displayValue: prevDisplayValue
|
|
332
|
+
} = this.state;
|
|
333
|
+
const {
|
|
334
|
+
value: prevValue
|
|
330
335
|
} = this.asProps;
|
|
331
336
|
const {
|
|
332
337
|
parsedValue,
|
|
333
338
|
displayValue
|
|
334
|
-
} = this.valueParser(newValue, prevValue, prevDisplayValue);
|
|
335
|
-
this.
|
|
339
|
+
} = this.valueParser(newValue ?? "", prevValue, prevDisplayValue);
|
|
340
|
+
this.setState({
|
|
341
|
+
displayValue
|
|
342
|
+
});
|
|
336
343
|
return parsedValue;
|
|
337
344
|
}]
|
|
338
345
|
};
|
|
@@ -349,9 +356,30 @@ class Value extends Component {
|
|
|
349
356
|
} = this.props;
|
|
350
357
|
return numberFormatter.format(1111).replace(/\d/g, "");
|
|
351
358
|
}
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
359
|
+
get stepPrecision() {
|
|
360
|
+
const {
|
|
361
|
+
step
|
|
362
|
+
} = this.asProps;
|
|
363
|
+
const [_, decimals] = step?.toString().split(".") ?? [];
|
|
364
|
+
return decimals?.length ?? 0;
|
|
365
|
+
}
|
|
366
|
+
getDisplayValue(value) {
|
|
367
|
+
return value === 0 ? `${value}` : value.toFixed(this.stepPrecision);
|
|
368
|
+
}
|
|
369
|
+
limitDecimals(value) {
|
|
370
|
+
const {
|
|
371
|
+
stepPrecision
|
|
372
|
+
} = this;
|
|
373
|
+
if (stepPrecision === 0) return value;
|
|
374
|
+
const dotIndex = value.indexOf(".");
|
|
375
|
+
if (dotIndex === -1 || value.length - dotIndex - 1 <= stepPrecision) return value;
|
|
376
|
+
return value.slice(0, dotIndex + 1 + stepPrecision);
|
|
377
|
+
}
|
|
378
|
+
round(value) {
|
|
379
|
+
const {
|
|
380
|
+
stepPrecision
|
|
381
|
+
} = this;
|
|
382
|
+
return stepPrecision === 0 ? value : Number(value.toPrecision(stepPrecision));
|
|
355
383
|
}
|
|
356
384
|
// https://stackoverflow.com/questions/57358640/cancel-wheel-event-with-e-preventdefault-in-react-event-bubbling
|
|
357
385
|
componentDidMount() {
|
|
@@ -374,15 +402,19 @@ class Value extends Component {
|
|
|
374
402
|
const {
|
|
375
403
|
displayValue
|
|
376
404
|
} = this.valueParser(value, "", "");
|
|
377
|
-
this.
|
|
405
|
+
this.setState({
|
|
406
|
+
displayValue
|
|
407
|
+
});
|
|
378
408
|
}
|
|
379
409
|
}
|
|
380
|
-
componentDidUpdate(prevProps) {
|
|
410
|
+
componentDidUpdate(prevProps, prevState) {
|
|
381
411
|
if (prevProps.value !== this.props.value) {
|
|
382
412
|
const {
|
|
383
413
|
displayValue
|
|
384
|
-
} = this.valueParser(this.props.value, prevProps.value,
|
|
385
|
-
this.
|
|
414
|
+
} = this.valueParser(this.props.value ?? "", prevProps.value, prevState.displayValue);
|
|
415
|
+
this.setState({
|
|
416
|
+
displayValue
|
|
417
|
+
});
|
|
386
418
|
}
|
|
387
419
|
}
|
|
388
420
|
componentWillUnmount() {
|
|
@@ -397,9 +429,11 @@ class Value extends Component {
|
|
|
397
429
|
max,
|
|
398
430
|
step,
|
|
399
431
|
forwardRef,
|
|
400
|
-
inputRef
|
|
401
|
-
displayValue
|
|
432
|
+
inputRef
|
|
402
433
|
} = this.asProps;
|
|
434
|
+
const {
|
|
435
|
+
displayValue
|
|
436
|
+
} = this.state;
|
|
403
437
|
return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SValue, _ref5.cn("SValue", {
|
|
404
438
|
...assignProps({
|
|
405
439
|
"autoComplete": "off",
|
|
@@ -408,7 +442,7 @@ class Value extends Component {
|
|
|
408
442
|
"onKeyDown": this.handleKeyDown,
|
|
409
443
|
"onKeyUp": this.handleKeyUp,
|
|
410
444
|
"onClick": this.handleClick,
|
|
411
|
-
"use:ref": forkRef(this.valueInputRef, inputRef, forwardRef),
|
|
445
|
+
"use:ref": forkRef(this.valueInputRef, inputRef, forwardRef ?? null),
|
|
412
446
|
"use:value": displayValue,
|
|
413
447
|
"inputMode": Number.isInteger(step) ? "numeric" : "decimal",
|
|
414
448
|
"min": min,
|
|
@@ -430,7 +464,6 @@ function Controls(props) {
|
|
|
430
464
|
Children,
|
|
431
465
|
increment,
|
|
432
466
|
decrement,
|
|
433
|
-
size,
|
|
434
467
|
styles,
|
|
435
468
|
getI18nText
|
|
436
469
|
} = props;
|
|
@@ -445,13 +478,11 @@ function Controls(props) {
|
|
|
445
478
|
"onClick": increment,
|
|
446
479
|
"tabIndex": -1,
|
|
447
480
|
"type": "button",
|
|
448
|
-
"size": size,
|
|
449
481
|
"aria-label": getI18nText("increment")
|
|
450
482
|
}), /* @__PURE__ */ React.createElement(IncrementIcon, _ref6.cn("IncrementIcon", {}))), /* @__PURE__ */ React.createElement(SDown, _ref6.cn("SDown", {
|
|
451
483
|
"onClick": decrement,
|
|
452
484
|
"tabIndex": -1,
|
|
453
485
|
"type": "button",
|
|
454
|
-
"size": size,
|
|
455
486
|
"aria-label": getI18nText("decrement")
|
|
456
487
|
}), /* @__PURE__ */ React.createElement(DecrementIcon, _ref6.cn("DecrementIcon", {}))), /* @__PURE__ */ React.createElement(Children, _ref6.cn("Children", {})));
|
|
457
488
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/esm/index.mjs
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NSInputNumber } from './InputNumber.type';
|
|
2
|
+
export declare function parseValueWithMinMax(value: number, min?: number, max?: number): number;
|
|
3
|
+
/**
|
|
4
|
+
* InputNumber
|
|
5
|
+
*
|
|
6
|
+
* {@link https://developer.semrush.com/intergalactic/components/input-number/input-number-api/|API} | {@link https://developer.semrush.com/intergalactic/components/input-number/input-number-code/|Examples}
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: NSInputNumber.Component;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Intergalactic, PropGetterFn } from '@semcore/core';
|
|
2
|
+
import type { NSInput } from '@semcore/input';
|
|
3
|
+
import type React from 'react';
|
|
4
|
+
import type { LocalizedMessages } from './translations/__intergalactic-dynamic-locales';
|
|
5
|
+
declare namespace NSInputNumber {
|
|
6
|
+
type Value = string;
|
|
7
|
+
type Size = 'm' | 'l';
|
|
8
|
+
type Props = NSInput.Props & {
|
|
9
|
+
/** Input size
|
|
10
|
+
* @default m
|
|
11
|
+
* */
|
|
12
|
+
size?: NSInputNumber.Size;
|
|
13
|
+
/**
|
|
14
|
+
* Locale value
|
|
15
|
+
*/
|
|
16
|
+
locale?: string;
|
|
17
|
+
};
|
|
18
|
+
type DefaultProps = {
|
|
19
|
+
size: 'm';
|
|
20
|
+
i18n: LocalizedMessages;
|
|
21
|
+
locale: 'en';
|
|
22
|
+
};
|
|
23
|
+
type Ctx = {
|
|
24
|
+
getValueProps: PropGetterFn;
|
|
25
|
+
getControlsProps: PropGetterFn;
|
|
26
|
+
getAddonProps: PropGetterFn;
|
|
27
|
+
};
|
|
28
|
+
namespace Value {
|
|
29
|
+
type Props = NSInput.Value.Props & {
|
|
30
|
+
/** Minimum value
|
|
31
|
+
* @default Number.MIN_SAFE_INTEGER
|
|
32
|
+
*/
|
|
33
|
+
min?: number;
|
|
34
|
+
/** Maximum value
|
|
35
|
+
* @default Number.MAX_SAFE_INTEGER
|
|
36
|
+
*/
|
|
37
|
+
max?: number;
|
|
38
|
+
/** Value change step
|
|
39
|
+
* @default 1
|
|
40
|
+
*/
|
|
41
|
+
step?: number;
|
|
42
|
+
/** Numeric value */
|
|
43
|
+
value?: NSInputNumber.Value;
|
|
44
|
+
/** Called when the input value changes, it returns its current value in numeric format */
|
|
45
|
+
onChange?: (value: NSInputNumber.Value, event?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
46
|
+
};
|
|
47
|
+
type DefaultProps = {
|
|
48
|
+
defaultValue: '';
|
|
49
|
+
step: 1;
|
|
50
|
+
};
|
|
51
|
+
type State = {
|
|
52
|
+
displayValue: NSInputNumber.Value;
|
|
53
|
+
};
|
|
54
|
+
type Handlers = {
|
|
55
|
+
value: [
|
|
56
|
+
null,
|
|
57
|
+
(value: Props['value'], event: React.SyntheticEvent | WheelEvent) => void
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
type Component = Intergalactic.Component<'input', Props>;
|
|
61
|
+
}
|
|
62
|
+
namespace Controls {
|
|
63
|
+
type Props = NSInput.Addon.Props & {
|
|
64
|
+
/** Always displays controls (steppers)
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
showControls?: boolean;
|
|
68
|
+
};
|
|
69
|
+
type Component = Intergalactic.Component<'div', Props>;
|
|
70
|
+
}
|
|
71
|
+
namespace Addon {
|
|
72
|
+
type Component = Intergalactic.Component<'div', NSInput.Addon.Props>;
|
|
73
|
+
}
|
|
74
|
+
type Component = Intergalactic.Component<'div', Props, Ctx> & {
|
|
75
|
+
Value: Value.Component;
|
|
76
|
+
Controls: Controls.Component;
|
|
77
|
+
Addon: Addon.Component;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** @deprecated It will be removed in v18. */
|
|
81
|
+
export type InputNumberValue = NSInputNumber.Value;
|
|
82
|
+
/** @deprecated It will be removed in v18. */
|
|
83
|
+
export type InputNumberSize = NSInputNumber.Size;
|
|
84
|
+
/** @deprecated It will be removed in v18. */
|
|
85
|
+
export type InputNumberProps = NSInputNumber.Props;
|
|
86
|
+
/** @deprecated It will be removed in v18. */
|
|
87
|
+
export type InputNumberValueProps = NSInputNumber.Value.Props;
|
|
88
|
+
/** @deprecated It will be removed in v18. */
|
|
89
|
+
export type InputNumberControlsProps = NSInputNumber.Controls.Props;
|
|
90
|
+
/** @deprecated It will be removed in v18. */
|
|
91
|
+
export type InputNumberCtx = NSInputNumber.Ctx;
|
|
92
|
+
export type { NSInputNumber };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type InputNumberValue = string;
|
|
6
|
-
export type InputNumberSize = 'm' | 'l';
|
|
7
|
-
|
|
8
|
-
export type InputNumberProps = InputProps & {
|
|
9
|
-
/** Input size
|
|
10
|
-
* @default m
|
|
11
|
-
* */
|
|
12
|
-
size?: InputNumberSize;
|
|
13
|
-
/**
|
|
14
|
-
* Locale value
|
|
15
|
-
*/
|
|
16
|
-
locale?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type InputNumberValueProps = InputValueProps & {
|
|
20
|
-
/** Minimum value
|
|
21
|
-
* @default Number.MIN_SAFE_INTEGER
|
|
22
|
-
*/
|
|
23
|
-
min?: number;
|
|
24
|
-
/** Maximum value
|
|
25
|
-
* @default Number.MAX_SAFE_INTEGER
|
|
26
|
-
*/
|
|
27
|
-
max?: number;
|
|
28
|
-
/** Value change step
|
|
29
|
-
* @default 1
|
|
30
|
-
*/
|
|
31
|
-
step?: number;
|
|
32
|
-
/** Numeric value */
|
|
33
|
-
value?: InputNumberValue;
|
|
34
|
-
/** Called when the input value changes, it returns its current value in numeric format */
|
|
35
|
-
onChange?: (value: InputNumberValue, event?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type InputNumberControlsProps = InputAddonProps & {
|
|
39
|
-
/** Always displays controls (steppers)
|
|
40
|
-
* @default false
|
|
41
|
-
*/
|
|
42
|
-
showControls?: boolean;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type InputNumberCtx = {
|
|
46
|
-
getValueProps: PropGetterFn;
|
|
47
|
-
getControlsProps: PropGetterFn;
|
|
48
|
-
getAddonProps: PropGetterFn;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
declare const InputNumber: Intergalactic.Component<'div', InputNumberProps, InputNumberCtx> & {
|
|
52
|
-
Value: Intergalactic.Component<'input', InputNumberValueProps>;
|
|
53
|
-
Controls: Intergalactic.Component<'div', InputNumberControlsProps>;
|
|
54
|
-
Addon: Intergalactic.Component<'div', InputAddonProps>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export default InputNumber;
|
|
58
|
-
|
|
59
|
-
declare const IncrementIcon: React.FC;
|
|
60
|
-
declare const DecrementIcon: React.FC;
|
|
61
|
-
declare const parseValueWithMinMax: (value: number, min?: number, max?: number) => number;
|
|
62
|
-
|
|
63
|
-
export { IncrementIcon, DecrementIcon, parseValueWithMinMax };
|
|
1
|
+
export { default, parseValueWithMinMax } from './InputNumber';
|
|
2
|
+
export { IncrementIcon, DecrementIcon } from './buttons';
|
|
3
|
+
export * from './InputNumber.type';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const localizedMessages: {
|
|
2
|
+
de: {
|
|
3
|
+
increment: string;
|
|
4
|
+
decrement: string;
|
|
5
|
+
};
|
|
6
|
+
en: {
|
|
7
|
+
increment: string;
|
|
8
|
+
decrement: string;
|
|
9
|
+
};
|
|
10
|
+
es: {
|
|
11
|
+
increment: string;
|
|
12
|
+
decrement: string;
|
|
13
|
+
};
|
|
14
|
+
fr: {
|
|
15
|
+
increment: string;
|
|
16
|
+
decrement: string;
|
|
17
|
+
};
|
|
18
|
+
it: {
|
|
19
|
+
increment: string;
|
|
20
|
+
decrement: string;
|
|
21
|
+
};
|
|
22
|
+
ja: {
|
|
23
|
+
increment: string;
|
|
24
|
+
decrement: string;
|
|
25
|
+
};
|
|
26
|
+
ko: {
|
|
27
|
+
increment: string;
|
|
28
|
+
decrement: string;
|
|
29
|
+
};
|
|
30
|
+
nl: {
|
|
31
|
+
increment: string;
|
|
32
|
+
decrement: string;
|
|
33
|
+
};
|
|
34
|
+
pt: {
|
|
35
|
+
increment: string;
|
|
36
|
+
decrement: string;
|
|
37
|
+
};
|
|
38
|
+
tr: {
|
|
39
|
+
increment: string;
|
|
40
|
+
decrement: string;
|
|
41
|
+
};
|
|
42
|
+
vi: {
|
|
43
|
+
increment: string;
|
|
44
|
+
decrement: string;
|
|
45
|
+
};
|
|
46
|
+
zh: {
|
|
47
|
+
increment: string;
|
|
48
|
+
decrement: string;
|
|
49
|
+
};
|
|
50
|
+
pl: {
|
|
51
|
+
increment: string;
|
|
52
|
+
decrement: string;
|
|
53
|
+
};
|
|
54
|
+
sv: {
|
|
55
|
+
increment: string;
|
|
56
|
+
decrement: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type LocalizedMessages = typeof localizedMessages;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/input-number",
|
|
3
3
|
"description": "Semrush InputNumber Component",
|
|
4
|
-
"version": "17.2.
|
|
4
|
+
"version": "17.2.2-prerelease.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"require": "./lib/cjs/index.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@semcore/input": "^17.2.
|
|
17
|
+
"@semcore/input": "^17.2.2-prerelease.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@semcore/base-components": "^17.2.1"
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"directory": "semcore/input-number"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@semcore/
|
|
29
|
-
"@semcore/
|
|
30
|
-
"@semcore/
|
|
28
|
+
"@semcore/base-components": "17.2.1",
|
|
29
|
+
"@semcore/testing-utils": "1.0.0",
|
|
30
|
+
"@semcore/core": "17.2.1"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "pnpm semcore-builder
|
|
33
|
+
"build": "pnpm semcore-builder && pnpm vite build"
|
|
34
34
|
}
|
|
35
35
|
}
|