@clickpalm/react 1.3.7 → 1.3.8
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.js +26 -21
- package/dist/index.mjs +26 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1341,14 +1341,32 @@ var Input2 = (0, import_react5.forwardRef)(
|
|
|
1341
1341
|
return stringValue;
|
|
1342
1342
|
};
|
|
1343
1343
|
const [displayValue, setDisplayValue] = (0, import_react5.useState)(getDisplayValue(props.value));
|
|
1344
|
-
const [charCount, setCharCount] = (0, import_react5.useState)(
|
|
1344
|
+
const [charCount, setCharCount] = (0, import_react5.useState)(getDisplayValue(props.value).length);
|
|
1345
1345
|
const localInputRef = (0, import_react5.useRef)(null);
|
|
1346
1346
|
const inputRef = forwardedRef || localInputRef;
|
|
1347
1347
|
(0, import_react5.useEffect)(() => {
|
|
1348
1348
|
const newDisplayValue = getDisplayValue(props.value);
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1349
|
+
if (newDisplayValue !== displayValue) {
|
|
1350
|
+
setDisplayValue(newDisplayValue);
|
|
1351
|
+
setCharCount(newDisplayValue.length);
|
|
1352
|
+
}
|
|
1353
|
+
}, [props.value, prefix, displayValue]);
|
|
1354
|
+
const handleChange = (e) => {
|
|
1355
|
+
let currentDisplayValue = getDisplayValue(e.target.value);
|
|
1356
|
+
if (props.type === "number") {
|
|
1357
|
+
currentDisplayValue = currentDisplayValue.replace(/[^0-9]/g, "");
|
|
1358
|
+
}
|
|
1359
|
+
if (props.onChange) {
|
|
1360
|
+
const newEvent = {
|
|
1361
|
+
...e,
|
|
1362
|
+
target: {
|
|
1363
|
+
...e.target,
|
|
1364
|
+
value: currentDisplayValue
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
props.onChange(newEvent);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1352
1370
|
const handleContainerClick = () => {
|
|
1353
1371
|
inputRef?.current?.focus();
|
|
1354
1372
|
};
|
|
@@ -1376,24 +1394,11 @@ var Input2 = (0, import_react5.forwardRef)(
|
|
|
1376
1394
|
{
|
|
1377
1395
|
ref: inputRef,
|
|
1378
1396
|
...props,
|
|
1397
|
+
type: props.type === "number" ? "text" : props.type,
|
|
1398
|
+
inputMode: props.type === "number" ? "numeric" : props.inputMode,
|
|
1379
1399
|
value: displayValue,
|
|
1380
|
-
maxLength
|
|
1381
|
-
onChange:
|
|
1382
|
-
const currentDisplayValue = e.target.value;
|
|
1383
|
-
setDisplayValue(currentDisplayValue);
|
|
1384
|
-
setCharCount((prefix?.length || 0) + currentDisplayValue.length);
|
|
1385
|
-
if (props.onChange) {
|
|
1386
|
-
const valueWithPrefix = prefix ? prefix + currentDisplayValue : currentDisplayValue;
|
|
1387
|
-
const newEvent = {
|
|
1388
|
-
...e,
|
|
1389
|
-
target: {
|
|
1390
|
-
...e.target,
|
|
1391
|
-
value: valueWithPrefix
|
|
1392
|
-
}
|
|
1393
|
-
};
|
|
1394
|
-
props.onChange(newEvent);
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1400
|
+
maxLength,
|
|
1401
|
+
onChange: handleChange
|
|
1397
1402
|
}
|
|
1398
1403
|
),
|
|
1399
1404
|
!!suffix && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Suffix, { children: suffix })
|
package/dist/index.mjs
CHANGED
|
@@ -1271,14 +1271,32 @@ var Input2 = forwardRef3(
|
|
|
1271
1271
|
return stringValue;
|
|
1272
1272
|
};
|
|
1273
1273
|
const [displayValue, setDisplayValue] = useState2(getDisplayValue(props.value));
|
|
1274
|
-
const [charCount, setCharCount] = useState2(
|
|
1274
|
+
const [charCount, setCharCount] = useState2(getDisplayValue(props.value).length);
|
|
1275
1275
|
const localInputRef = useRef2(null);
|
|
1276
1276
|
const inputRef = forwardedRef || localInputRef;
|
|
1277
1277
|
useEffect2(() => {
|
|
1278
1278
|
const newDisplayValue = getDisplayValue(props.value);
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1279
|
+
if (newDisplayValue !== displayValue) {
|
|
1280
|
+
setDisplayValue(newDisplayValue);
|
|
1281
|
+
setCharCount(newDisplayValue.length);
|
|
1282
|
+
}
|
|
1283
|
+
}, [props.value, prefix, displayValue]);
|
|
1284
|
+
const handleChange = (e) => {
|
|
1285
|
+
let currentDisplayValue = getDisplayValue(e.target.value);
|
|
1286
|
+
if (props.type === "number") {
|
|
1287
|
+
currentDisplayValue = currentDisplayValue.replace(/[^0-9]/g, "");
|
|
1288
|
+
}
|
|
1289
|
+
if (props.onChange) {
|
|
1290
|
+
const newEvent = {
|
|
1291
|
+
...e,
|
|
1292
|
+
target: {
|
|
1293
|
+
...e.target,
|
|
1294
|
+
value: currentDisplayValue
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
props.onChange(newEvent);
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1282
1300
|
const handleContainerClick = () => {
|
|
1283
1301
|
inputRef?.current?.focus();
|
|
1284
1302
|
};
|
|
@@ -1306,24 +1324,11 @@ var Input2 = forwardRef3(
|
|
|
1306
1324
|
{
|
|
1307
1325
|
ref: inputRef,
|
|
1308
1326
|
...props,
|
|
1327
|
+
type: props.type === "number" ? "text" : props.type,
|
|
1328
|
+
inputMode: props.type === "number" ? "numeric" : props.inputMode,
|
|
1309
1329
|
value: displayValue,
|
|
1310
|
-
maxLength
|
|
1311
|
-
onChange:
|
|
1312
|
-
const currentDisplayValue = e.target.value;
|
|
1313
|
-
setDisplayValue(currentDisplayValue);
|
|
1314
|
-
setCharCount((prefix?.length || 0) + currentDisplayValue.length);
|
|
1315
|
-
if (props.onChange) {
|
|
1316
|
-
const valueWithPrefix = prefix ? prefix + currentDisplayValue : currentDisplayValue;
|
|
1317
|
-
const newEvent = {
|
|
1318
|
-
...e,
|
|
1319
|
-
target: {
|
|
1320
|
-
...e.target,
|
|
1321
|
-
value: valueWithPrefix
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
props.onChange(newEvent);
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1330
|
+
maxLength,
|
|
1331
|
+
onChange: handleChange
|
|
1327
1332
|
}
|
|
1328
1333
|
),
|
|
1329
1334
|
!!suffix && /* @__PURE__ */ jsx19(Suffix, { children: suffix })
|
package/package.json
CHANGED