@xanui/ui 1.1.59 → 1.1.60
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/InputNumber/index.cjs +31 -34
- package/InputNumber/index.cjs.map +1 -1
- package/InputNumber/index.d.ts +1 -1
- package/InputNumber/index.js +32 -35
- package/InputNumber/index.js.map +1 -1
- package/package.json +1 -1
package/InputNumber/index.cjs
CHANGED
|
@@ -5,48 +5,45 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var index = require('../Input/index.cjs');
|
|
7
7
|
var UnfoldMore = require('@xanui/icons/UnfoldMore');
|
|
8
|
+
var core = require('@xanui/core');
|
|
8
9
|
|
|
9
10
|
const InputNumber = React.forwardRef((props, ref) => {
|
|
10
11
|
var _a;
|
|
11
|
-
|
|
12
|
-
const
|
|
12
|
+
const [_val, setVal] = React.useState((_a = props.value) !== null && _a !== void 0 ? _a : "");
|
|
13
|
+
const inputRef = React.useRef(null);
|
|
14
|
+
const mergeRef = core.useMergeRefs(inputRef, ref);
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
if (inputRef.current && (props === null || props === void 0 ? void 0 : props.onChange)) {
|
|
17
|
+
inputRef.current.value = _val.includes(".") ? parseFloat(_val) : parseInt(_val);
|
|
18
|
+
const syntheticEvent = {
|
|
19
|
+
target: inputRef.current,
|
|
20
|
+
currentTarget: inputRef.current,
|
|
21
|
+
};
|
|
22
|
+
props === null || props === void 0 ? void 0 : props.onChange(syntheticEvent);
|
|
23
|
+
}
|
|
24
|
+
}, [_val]);
|
|
25
|
+
const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));
|
|
13
26
|
const errorProps = {};
|
|
14
27
|
if (!isNumeric) {
|
|
15
28
|
errorProps.error = true;
|
|
16
29
|
errorProps.helperText = "Value must be numeric";
|
|
17
30
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// Handle input change with float support
|
|
35
|
-
const handleChange = (e) => {
|
|
36
|
-
var _a;
|
|
37
|
-
let val = e.target.value;
|
|
38
|
-
// Remove invalid characters except digits and dot
|
|
39
|
-
val = val.replace(/[^0-9.]/g, '');
|
|
40
|
-
// Only allow one dot
|
|
41
|
-
const parts = val.split('.');
|
|
42
|
-
if (parts.length > 2) {
|
|
43
|
-
val = parts[0] + '.' + parts.slice(1).join('');
|
|
44
|
-
}
|
|
45
|
-
// Keep trailing dot while typing
|
|
46
|
-
e.target.value = val;
|
|
47
|
-
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
48
|
-
};
|
|
49
|
-
return (jsxRuntime.jsx(index, Object.assign({}, props, errorProps, { ref: ref, endIcon: jsxRuntime.jsx(UnfoldMore, {}), onKeyDown: handleKeyDown, onChange: handleChange, value: (_a = props.value) !== null && _a !== void 0 ? _a : "" })));
|
|
31
|
+
return (jsxRuntime.jsx(index, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsxRuntime.jsx(UnfoldMore, {}), value: _val !== null && _val !== void 0 ? _val : "", onKeyDown: (e) => {
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
34
|
+
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
35
|
+
return;
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
const current = parseFloat(_val) || 0;
|
|
38
|
+
setVal(e.key === 'ArrowUp' ? current + 1 : current - 1);
|
|
39
|
+
}, onChange: (e) => {
|
|
40
|
+
let val = e.target.value.replace(/[^0-9.]/g, '');
|
|
41
|
+
const parts = val.split('.');
|
|
42
|
+
if (parts.length > 2) {
|
|
43
|
+
val = parts[0] + '.' + parts.slice(1).join('');
|
|
44
|
+
}
|
|
45
|
+
setVal(val === "." ? `0.` : val);
|
|
46
|
+
} })));
|
|
50
47
|
});
|
|
51
48
|
|
|
52
49
|
module.exports = InputNumber;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react'\nimport Input, { InputProps } from '../Input'\nimport UnfoldMore from '@xanui/icons/UnfoldMore'\n\nexport type InputNumberProps = Omit<InputProps, \"value\"> & {\n value?: number
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React, { useEffect, useRef, useState } from 'react'\nimport Input, { InputProps } from '../Input'\nimport UnfoldMore from '@xanui/icons/UnfoldMore'\nimport { useMergeRefs } from '@xanui/core'\n\nexport type InputNumberProps = Omit<InputProps, \"value\"> & {\n value?: number; // allow string so typing \".\" works\n}\n\nconst InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {\n const [_val, setVal] = useState<string>(props.value as any ?? \"\")\n const inputRef = useRef<any>(null)\n const mergeRef = useMergeRefs(inputRef, ref)\n useEffect(() => {\n if (inputRef.current && props?.onChange) {\n inputRef.current.value = _val.includes(\".\") ? parseFloat(_val) : parseInt(_val)\n const syntheticEvent = {\n target: inputRef.current,\n currentTarget: inputRef.current,\n } as unknown as React.ChangeEvent<HTMLInputElement>;\n props?.onChange(syntheticEvent)\n }\n }, [_val])\n\n const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));\n const errorProps: Partial<InputProps> = {};\n if (!isNumeric) {\n errorProps.error = true;\n errorProps.helperText = \"Value must be numeric\";\n }\n\n return (\n <Input\n {...props}\n {...errorProps}\n ref={mergeRef}\n endIcon={<UnfoldMore />}\n value={_val ?? \"\" as any}\n onKeyDown={(e: any) => {\n props.onKeyDown?.(e);\n\n if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;\n\n e.preventDefault();\n const current = parseFloat(_val as any) || 0;\n setVal(e.key === 'ArrowUp' ? current + 1 : current - 1 as any);\n }}\n onChange={(e) => {\n let val: any = e.target.value.replace(/[^0-9.]/g, '')\n const parts = val.split('.');\n if (parts.length > 2) {\n val = parts[0] + '.' + parts.slice(1).join('')\n }\n setVal(val === \".\" ? `0.` : val);\n }}\n />\n );\n});\n\nexport default InputNumber;\n"],"names":[],"mappings":";;;;;;;;;AAUA;;AACG;AACA;;;AAGG;;AAEG;;;;;;AAMN;AAEA;;;AAGG;AACA;;AAGH;;AAQS;;;;;AAMA;AACH;AAEG;;AAEA;AACG;;AAEH;;AAIZ;;"}
|
package/InputNumber/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { InputProps } from '../Input/index.js';
|
|
3
3
|
|
|
4
4
|
type InputNumberProps = Omit<InputProps, "value"> & {
|
|
5
|
-
value?: number
|
|
5
|
+
value?: number;
|
|
6
6
|
};
|
|
7
7
|
declare const InputNumber: React.ForwardRefExoticComponent<Omit<InputNumberProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
8
8
|
|
package/InputNumber/index.js
CHANGED
|
@@ -1,50 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
4
4
|
import Input from '../Input/index.js';
|
|
5
5
|
import UnfoldMore from '@xanui/icons/UnfoldMore';
|
|
6
|
+
import { useMergeRefs } from '@xanui/core';
|
|
6
7
|
|
|
7
8
|
const InputNumber = React.forwardRef((props, ref) => {
|
|
8
9
|
var _a;
|
|
9
|
-
|
|
10
|
-
const
|
|
10
|
+
const [_val, setVal] = useState((_a = props.value) !== null && _a !== void 0 ? _a : "");
|
|
11
|
+
const inputRef = useRef(null);
|
|
12
|
+
const mergeRef = useMergeRefs(inputRef, ref);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (inputRef.current && (props === null || props === void 0 ? void 0 : props.onChange)) {
|
|
15
|
+
inputRef.current.value = _val.includes(".") ? parseFloat(_val) : parseInt(_val);
|
|
16
|
+
const syntheticEvent = {
|
|
17
|
+
target: inputRef.current,
|
|
18
|
+
currentTarget: inputRef.current,
|
|
19
|
+
};
|
|
20
|
+
props === null || props === void 0 ? void 0 : props.onChange(syntheticEvent);
|
|
21
|
+
}
|
|
22
|
+
}, [_val]);
|
|
23
|
+
const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));
|
|
11
24
|
const errorProps = {};
|
|
12
25
|
if (!isNumeric) {
|
|
13
26
|
errorProps.error = true;
|
|
14
27
|
errorProps.helperText = "Value must be numeric";
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// Handle input change with float support
|
|
33
|
-
const handleChange = (e) => {
|
|
34
|
-
var _a;
|
|
35
|
-
let val = e.target.value;
|
|
36
|
-
// Remove invalid characters except digits and dot
|
|
37
|
-
val = val.replace(/[^0-9.]/g, '');
|
|
38
|
-
// Only allow one dot
|
|
39
|
-
const parts = val.split('.');
|
|
40
|
-
if (parts.length > 2) {
|
|
41
|
-
val = parts[0] + '.' + parts.slice(1).join('');
|
|
42
|
-
}
|
|
43
|
-
// Keep trailing dot while typing
|
|
44
|
-
e.target.value = val;
|
|
45
|
-
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
46
|
-
};
|
|
47
|
-
return (jsx(Input, Object.assign({}, props, errorProps, { ref: ref, endIcon: jsx(UnfoldMore, {}), onKeyDown: handleKeyDown, onChange: handleChange, value: (_a = props.value) !== null && _a !== void 0 ? _a : "" })));
|
|
29
|
+
return (jsx(Input, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsx(UnfoldMore, {}), value: _val !== null && _val !== void 0 ? _val : "", onKeyDown: (e) => {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
32
|
+
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
33
|
+
return;
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
const current = parseFloat(_val) || 0;
|
|
36
|
+
setVal(e.key === 'ArrowUp' ? current + 1 : current - 1);
|
|
37
|
+
}, onChange: (e) => {
|
|
38
|
+
let val = e.target.value.replace(/[^0-9.]/g, '');
|
|
39
|
+
const parts = val.split('.');
|
|
40
|
+
if (parts.length > 2) {
|
|
41
|
+
val = parts[0] + '.' + parts.slice(1).join('');
|
|
42
|
+
}
|
|
43
|
+
setVal(val === "." ? `0.` : val);
|
|
44
|
+
} })));
|
|
48
45
|
});
|
|
49
46
|
|
|
50
47
|
export { InputNumber as default };
|
package/InputNumber/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react'\nimport Input, { InputProps } from '../Input'\nimport UnfoldMore from '@xanui/icons/UnfoldMore'\n\nexport type InputNumberProps = Omit<InputProps, \"value\"> & {\n value?: number
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React, { useEffect, useRef, useState } from 'react'\nimport Input, { InputProps } from '../Input'\nimport UnfoldMore from '@xanui/icons/UnfoldMore'\nimport { useMergeRefs } from '@xanui/core'\n\nexport type InputNumberProps = Omit<InputProps, \"value\"> & {\n value?: number; // allow string so typing \".\" works\n}\n\nconst InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {\n const [_val, setVal] = useState<string>(props.value as any ?? \"\")\n const inputRef = useRef<any>(null)\n const mergeRef = useMergeRefs(inputRef, ref)\n useEffect(() => {\n if (inputRef.current && props?.onChange) {\n inputRef.current.value = _val.includes(\".\") ? parseFloat(_val) : parseInt(_val)\n const syntheticEvent = {\n target: inputRef.current,\n currentTarget: inputRef.current,\n } as unknown as React.ChangeEvent<HTMLInputElement>;\n props?.onChange(syntheticEvent)\n }\n }, [_val])\n\n const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));\n const errorProps: Partial<InputProps> = {};\n if (!isNumeric) {\n errorProps.error = true;\n errorProps.helperText = \"Value must be numeric\";\n }\n\n return (\n <Input\n {...props}\n {...errorProps}\n ref={mergeRef}\n endIcon={<UnfoldMore />}\n value={_val ?? \"\" as any}\n onKeyDown={(e: any) => {\n props.onKeyDown?.(e);\n\n if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;\n\n e.preventDefault();\n const current = parseFloat(_val as any) || 0;\n setVal(e.key === 'ArrowUp' ? current + 1 : current - 1 as any);\n }}\n onChange={(e) => {\n let val: any = e.target.value.replace(/[^0-9.]/g, '')\n const parts = val.split('.');\n if (parts.length > 2) {\n val = parts[0] + '.' + parts.slice(1).join('')\n }\n setVal(val === \".\" ? `0.` : val);\n }}\n />\n );\n});\n\nexport default InputNumber;\n"],"names":[],"mappings":";;;;;;;AAUA;;AACG;AACA;;;AAGG;;AAEG;;;;;;AAMN;AAEA;;;AAGG;AACA;;AAGH;;AAQS;;;;;AAMA;AACH;AAEG;;AAEA;AACG;;AAEH;;AAIZ;;"}
|