@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.
@@ -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
- // Check if current value is numeric
12
- const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));
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
- // Handle arrow up/down for increment/decrement
19
- const handleKeyDown = (e) => {
20
- var _a, _b;
21
- (_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
22
- if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
23
- return;
24
- e.preventDefault();
25
- const current = parseFloat(props.value) || 0;
26
- const newVal = e.key === 'ArrowUp' ? current + 1 : current - 1;
27
- if (ref && 'current' in ref && ref.current) {
28
- ref.current.value = String(newVal);
29
- }
30
- // Trigger onChange manually
31
- const syntheticEvent = Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value: String(newVal) }) });
32
- (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, syntheticEvent);
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 | string; // allow string so typing \".\" works\n}\n\nconst InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {\n // Check if current value is numeric\n const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));\n\n const errorProps: Partial<InputProps> = {};\n if (!isNumeric) {\n errorProps.error = true;\n errorProps.helperText = \"Value must be numeric\";\n }\n\n // Handle arrow up/down for increment/decrement\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n props.onKeyDown?.(e);\n\n if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;\n\n e.preventDefault();\n const current = parseFloat(props.value as any) || 0;\n const newVal = e.key === 'ArrowUp' ? current + 1 : current - 1;\n\n if (ref && 'current' in ref && ref.current) {\n ref.current.value = String(newVal);\n }\n\n // Trigger onChange manually\n const syntheticEvent = {\n ...e,\n target: {\n ...e.target,\n value: String(newVal),\n }\n } as unknown as React.ChangeEvent<HTMLInputElement>;\n\n props.onChange?.(syntheticEvent);\n };\n\n // Handle input change with float support\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n let val = e.target.value;\n\n // Remove invalid characters except digits and dot\n val = val.replace(/[^0-9.]/g, '');\n\n // Only allow one dot\n const parts = val.split('.');\n if (parts.length > 2) {\n val = parts[0] + '.' + parts.slice(1).join('');\n }\n\n // Keep trailing dot while typing\n e.target.value = val;\n\n props.onChange?.(e);\n };\n\n return (\n <Input\n {...props}\n {...errorProps}\n ref={ref}\n endIcon={<UnfoldMore />}\n onKeyDown={handleKeyDown as any}\n onChange={handleChange as any}\n value={props.value ?? \"\" as any}\n />\n );\n});\n\nexport default InputNumber;\n"],"names":[],"mappings":";;;;;;;;AASA;;;;;;AAMM;AACA;;;AAIH;;AACG;;;;;AAMA;;;;;AAOA;AAQA;AACH;;AAGA;;AACG;;;;;AAOA;AACG;;;AAIH;AAEA;AACH;AAEA;AAWH;;"}
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;;"}
@@ -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 | string;
5
+ value?: number;
6
6
  };
7
7
  declare const InputNumber: React.ForwardRefExoticComponent<Omit<InputNumberProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
8
8
 
@@ -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
- // Check if current value is numeric
10
- const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));
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
- // Handle arrow up/down for increment/decrement
17
- const handleKeyDown = (e) => {
18
- var _a, _b;
19
- (_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
20
- if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
21
- return;
22
- e.preventDefault();
23
- const current = parseFloat(props.value) || 0;
24
- const newVal = e.key === 'ArrowUp' ? current + 1 : current - 1;
25
- if (ref && 'current' in ref && ref.current) {
26
- ref.current.value = String(newVal);
27
- }
28
- // Trigger onChange manually
29
- const syntheticEvent = Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value: String(newVal) }) });
30
- (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, syntheticEvent);
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 };
@@ -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 | string; // allow string so typing \".\" works\n}\n\nconst InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {\n // Check if current value is numeric\n const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));\n\n const errorProps: Partial<InputProps> = {};\n if (!isNumeric) {\n errorProps.error = true;\n errorProps.helperText = \"Value must be numeric\";\n }\n\n // Handle arrow up/down for increment/decrement\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n props.onKeyDown?.(e);\n\n if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;\n\n e.preventDefault();\n const current = parseFloat(props.value as any) || 0;\n const newVal = e.key === 'ArrowUp' ? current + 1 : current - 1;\n\n if (ref && 'current' in ref && ref.current) {\n ref.current.value = String(newVal);\n }\n\n // Trigger onChange manually\n const syntheticEvent = {\n ...e,\n target: {\n ...e.target,\n value: String(newVal),\n }\n } as unknown as React.ChangeEvent<HTMLInputElement>;\n\n props.onChange?.(syntheticEvent);\n };\n\n // Handle input change with float support\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n let val = e.target.value;\n\n // Remove invalid characters except digits and dot\n val = val.replace(/[^0-9.]/g, '');\n\n // Only allow one dot\n const parts = val.split('.');\n if (parts.length > 2) {\n val = parts[0] + '.' + parts.slice(1).join('');\n }\n\n // Keep trailing dot while typing\n e.target.value = val;\n\n props.onChange?.(e);\n };\n\n return (\n <Input\n {...props}\n {...errorProps}\n ref={ref}\n endIcon={<UnfoldMore />}\n onKeyDown={handleKeyDown as any}\n onChange={handleChange as any}\n value={props.value ?? \"\" as any}\n />\n );\n});\n\nexport default InputNumber;\n"],"names":[],"mappings":";;;;;;AASA;;;;;;AAMM;AACA;;;AAIH;;AACG;;;;;AAMA;;;;;AAOA;AAQA;AACH;;AAGA;;AACG;;;;;AAOA;AACG;;;AAIH;AAEA;AACH;AAEA;AAWH;;"}
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;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xanui/ui",
3
- "version": "1.1.59",
3
+ "version": "1.1.60",
4
4
  "description": "Xanui - A React Component Library",
5
5
  "private": false,
6
6
  "dependencies": {