@sia.soul/sia-react-ui 0.1.94 → 0.1.95
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/dist/index.cjs +27 -7
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11691,6 +11691,8 @@ var InputNumber = (0, import_react44.forwardRef)(function InputNumber2({
|
|
|
11691
11691
|
max,
|
|
11692
11692
|
step = 1,
|
|
11693
11693
|
precision,
|
|
11694
|
+
formatter,
|
|
11695
|
+
parser,
|
|
11694
11696
|
size: sizeProp,
|
|
11695
11697
|
status = "default",
|
|
11696
11698
|
prefix,
|
|
@@ -11711,10 +11713,14 @@ var InputNumber = (0, import_react44.forwardRef)(function InputNumber2({
|
|
|
11711
11713
|
const inputId = id ?? fallbackId;
|
|
11712
11714
|
const localRef = (0, import_react44.useRef)(null);
|
|
11713
11715
|
const [currentValue, setCurrentValue] = useControllableState({ value, defaultValue, onChange });
|
|
11714
|
-
const
|
|
11716
|
+
const displayValue = (next) => {
|
|
11717
|
+
const plain = formatValue(next, precision);
|
|
11718
|
+
return plain && formatter ? formatter(plain) : plain;
|
|
11719
|
+
};
|
|
11720
|
+
const [text, setText] = (0, import_react44.useState)(() => displayValue(currentValue));
|
|
11715
11721
|
(0, import_react44.useEffect)(() => {
|
|
11716
|
-
setText(
|
|
11717
|
-
}, [currentValue, precision]);
|
|
11722
|
+
setText(displayValue(currentValue));
|
|
11723
|
+
}, [currentValue, precision, formatter]);
|
|
11718
11724
|
function setRef(node) {
|
|
11719
11725
|
localRef.current = node;
|
|
11720
11726
|
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
@@ -11733,19 +11739,33 @@ var InputNumber = (0, import_react44.forwardRef)(function InputNumber2({
|
|
|
11733
11739
|
setCurrentValue(null);
|
|
11734
11740
|
return;
|
|
11735
11741
|
}
|
|
11736
|
-
|
|
11742
|
+
let parsed;
|
|
11743
|
+
try {
|
|
11744
|
+
const value2 = parser ? parser(rawText) : rawText;
|
|
11745
|
+
if (typeof value2 === "string" && value2.trim() === "") {
|
|
11746
|
+
setText("");
|
|
11747
|
+
setCurrentValue(null);
|
|
11748
|
+
return;
|
|
11749
|
+
}
|
|
11750
|
+
parsed = Number(value2);
|
|
11751
|
+
} catch {
|
|
11752
|
+
setText(displayValue(currentValue));
|
|
11753
|
+
return;
|
|
11754
|
+
}
|
|
11737
11755
|
if (!Number.isFinite(parsed)) {
|
|
11738
|
-
setText(
|
|
11756
|
+
setText(displayValue(currentValue));
|
|
11739
11757
|
return;
|
|
11740
11758
|
}
|
|
11741
11759
|
const nextValue = normalize(parsed);
|
|
11742
|
-
setText(
|
|
11760
|
+
setText(displayValue(nextValue));
|
|
11743
11761
|
setCurrentValue(nextValue);
|
|
11744
11762
|
}
|
|
11745
11763
|
function changeBy(direction) {
|
|
11746
11764
|
if (disabled || readOnly) return;
|
|
11747
11765
|
const baseValue = currentValue ?? 0;
|
|
11748
|
-
|
|
11766
|
+
const nextValue = normalize(baseValue + step * direction);
|
|
11767
|
+
setText(displayValue(nextValue));
|
|
11768
|
+
setCurrentValue(nextValue);
|
|
11749
11769
|
localRef.current?.focus();
|
|
11750
11770
|
}
|
|
11751
11771
|
function handleBlur(event) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1652,6 +1652,16 @@ interface InputNumberProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
|
|
|
1652
1652
|
step?: number;
|
|
1653
1653
|
/** 固定小数位数 */
|
|
1654
1654
|
precision?: number;
|
|
1655
|
+
/**
|
|
1656
|
+
* 将已提交的数值转换为显示文本,例如千分位或货币符号;输入过程中保留原始草稿,失焦、回车、步进及外部 value 更新后格式化。
|
|
1657
|
+
* 参数为应用 precision 后的十进制文本,空值为空字符串;应返回显示文本,并与 parser 配套。未指定时显示普通十进制文本。
|
|
1658
|
+
*/
|
|
1659
|
+
formatter?: (value: string) => string;
|
|
1660
|
+
/**
|
|
1661
|
+
* 失焦或回车时将输入文本解析为数字或数字字符串;无效值或抛出异常时恢复当前值,不触发 onChange。
|
|
1662
|
+
* 空输入或解析为空字符串提交 null;未指定时使用 Number 转换。步进使用数值计算,不经过 parser。
|
|
1663
|
+
*/
|
|
1664
|
+
parser?: (text: string) => number | string;
|
|
1655
1665
|
/** small / medium / large 高度为 22 / 30 / 38px;默认继承 Form,组件自身 size 优先 */
|
|
1656
1666
|
size?: ControlSize;
|
|
1657
1667
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1652,6 +1652,16 @@ interface InputNumberProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
|
|
|
1652
1652
|
step?: number;
|
|
1653
1653
|
/** 固定小数位数 */
|
|
1654
1654
|
precision?: number;
|
|
1655
|
+
/**
|
|
1656
|
+
* 将已提交的数值转换为显示文本,例如千分位或货币符号;输入过程中保留原始草稿,失焦、回车、步进及外部 value 更新后格式化。
|
|
1657
|
+
* 参数为应用 precision 后的十进制文本,空值为空字符串;应返回显示文本,并与 parser 配套。未指定时显示普通十进制文本。
|
|
1658
|
+
*/
|
|
1659
|
+
formatter?: (value: string) => string;
|
|
1660
|
+
/**
|
|
1661
|
+
* 失焦或回车时将输入文本解析为数字或数字字符串;无效值或抛出异常时恢复当前值,不触发 onChange。
|
|
1662
|
+
* 空输入或解析为空字符串提交 null;未指定时使用 Number 转换。步进使用数值计算,不经过 parser。
|
|
1663
|
+
*/
|
|
1664
|
+
parser?: (text: string) => number | string;
|
|
1655
1665
|
/** small / medium / large 高度为 22 / 30 / 38px;默认继承 Form,组件自身 size 优先 */
|
|
1656
1666
|
size?: ControlSize;
|
|
1657
1667
|
/**
|
package/dist/index.js
CHANGED
|
@@ -4199,6 +4199,8 @@ var InputNumber = forwardRef4(function InputNumber2({
|
|
|
4199
4199
|
max,
|
|
4200
4200
|
step = 1,
|
|
4201
4201
|
precision,
|
|
4202
|
+
formatter,
|
|
4203
|
+
parser,
|
|
4202
4204
|
size: sizeProp,
|
|
4203
4205
|
status = "default",
|
|
4204
4206
|
prefix,
|
|
@@ -4219,10 +4221,14 @@ var InputNumber = forwardRef4(function InputNumber2({
|
|
|
4219
4221
|
const inputId = id ?? fallbackId;
|
|
4220
4222
|
const localRef = useRef11(null);
|
|
4221
4223
|
const [currentValue, setCurrentValue] = useControllableState({ value, defaultValue, onChange });
|
|
4222
|
-
const
|
|
4224
|
+
const displayValue = (next) => {
|
|
4225
|
+
const plain = formatValue(next, precision);
|
|
4226
|
+
return plain && formatter ? formatter(plain) : plain;
|
|
4227
|
+
};
|
|
4228
|
+
const [text, setText] = useState13(() => displayValue(currentValue));
|
|
4223
4229
|
useEffect9(() => {
|
|
4224
|
-
setText(
|
|
4225
|
-
}, [currentValue, precision]);
|
|
4230
|
+
setText(displayValue(currentValue));
|
|
4231
|
+
}, [currentValue, precision, formatter]);
|
|
4226
4232
|
function setRef(node) {
|
|
4227
4233
|
localRef.current = node;
|
|
4228
4234
|
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
@@ -4241,19 +4247,33 @@ var InputNumber = forwardRef4(function InputNumber2({
|
|
|
4241
4247
|
setCurrentValue(null);
|
|
4242
4248
|
return;
|
|
4243
4249
|
}
|
|
4244
|
-
|
|
4250
|
+
let parsed;
|
|
4251
|
+
try {
|
|
4252
|
+
const value2 = parser ? parser(rawText) : rawText;
|
|
4253
|
+
if (typeof value2 === "string" && value2.trim() === "") {
|
|
4254
|
+
setText("");
|
|
4255
|
+
setCurrentValue(null);
|
|
4256
|
+
return;
|
|
4257
|
+
}
|
|
4258
|
+
parsed = Number(value2);
|
|
4259
|
+
} catch {
|
|
4260
|
+
setText(displayValue(currentValue));
|
|
4261
|
+
return;
|
|
4262
|
+
}
|
|
4245
4263
|
if (!Number.isFinite(parsed)) {
|
|
4246
|
-
setText(
|
|
4264
|
+
setText(displayValue(currentValue));
|
|
4247
4265
|
return;
|
|
4248
4266
|
}
|
|
4249
4267
|
const nextValue = normalize(parsed);
|
|
4250
|
-
setText(
|
|
4268
|
+
setText(displayValue(nextValue));
|
|
4251
4269
|
setCurrentValue(nextValue);
|
|
4252
4270
|
}
|
|
4253
4271
|
function changeBy(direction) {
|
|
4254
4272
|
if (disabled || readOnly) return;
|
|
4255
4273
|
const baseValue = currentValue ?? 0;
|
|
4256
|
-
|
|
4274
|
+
const nextValue = normalize(baseValue + step * direction);
|
|
4275
|
+
setText(displayValue(nextValue));
|
|
4276
|
+
setCurrentValue(nextValue);
|
|
4257
4277
|
localRef.current?.focus();
|
|
4258
4278
|
}
|
|
4259
4279
|
function handleBlur(event) {
|