@clickpalm/react 1.3.6 → 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 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)((prefix?.length || 0) + getDisplayValue(props.value).length);
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
- setDisplayValue(newDisplayValue);
1350
- setCharCount((prefix?.length || 0) + newDisplayValue.length);
1351
- }, [props.value, prefix]);
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: maxLength ? maxLength - (prefix?.length || 0) : void 0,
1381
- onChange: (e) => {
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 })
@@ -2564,7 +2569,10 @@ var CharCounter2 = styled(Span5, {
2564
2569
  var TextArea = (0, import_react13.forwardRef)(
2565
2570
  ({ label, id, htmlFor, errorMessage, maxLength, showCounter = false, ...props }, ref) => {
2566
2571
  const textAreaId = id || htmlFor || `textarea-${crypto.randomUUID()}`;
2567
- const [charCount, setCharCount] = (0, import_react13.useState)(0);
2572
+ const [charCount, setCharCount] = (0, import_react13.useState)(props.value?.toString().length || 0);
2573
+ (0, import_react13.useEffect)(() => {
2574
+ setCharCount(props.value?.toString().length || 0);
2575
+ }, [props.value]);
2568
2576
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(Wrapper4, { children: [
2569
2577
  label && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(StyledLabel2, { htmlFor: textAreaId, children: label }),
2570
2578
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
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((prefix?.length || 0) + getDisplayValue(props.value).length);
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
- setDisplayValue(newDisplayValue);
1280
- setCharCount((prefix?.length || 0) + newDisplayValue.length);
1281
- }, [props.value, prefix]);
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: maxLength ? maxLength - (prefix?.length || 0) : void 0,
1311
- onChange: (e) => {
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 })
@@ -2384,7 +2389,7 @@ var Tabs2 = ({ defaultValue, colorContent, children, value, onValueChange }) =>
2384
2389
  Tabs2.Item = TabsItem;
2385
2390
 
2386
2391
  // src/components/TextArea.tsx
2387
- import { forwardRef as forwardRef8, useState as useState7 } from "react";
2392
+ import { forwardRef as forwardRef8, useEffect as useEffect6, useState as useState7 } from "react";
2388
2393
  import { jsx as jsx30, jsxs as jsxs12 } from "react/jsx-runtime";
2389
2394
  var Wrapper4 = styled("div", {
2390
2395
  display: "flex",
@@ -2494,7 +2499,10 @@ var CharCounter2 = styled(Span5, {
2494
2499
  var TextArea = forwardRef8(
2495
2500
  ({ label, id, htmlFor, errorMessage, maxLength, showCounter = false, ...props }, ref) => {
2496
2501
  const textAreaId = id || htmlFor || `textarea-${crypto.randomUUID()}`;
2497
- const [charCount, setCharCount] = useState7(0);
2502
+ const [charCount, setCharCount] = useState7(props.value?.toString().length || 0);
2503
+ useEffect6(() => {
2504
+ setCharCount(props.value?.toString().length || 0);
2505
+ }, [props.value]);
2498
2506
  return /* @__PURE__ */ jsxs12(Wrapper4, { children: [
2499
2507
  label && /* @__PURE__ */ jsx30(StyledLabel2, { htmlFor: textAreaId, children: label }),
2500
2508
  /* @__PURE__ */ jsx30(
@@ -2578,7 +2586,7 @@ var TooltipArrow = styled(RadixTooltip.Arrow, {
2578
2586
  });
2579
2587
 
2580
2588
  // src/components/Tooltip/index.tsx
2581
- import { useState as useState8, useEffect as useEffect6 } from "react";
2589
+ import { useState as useState8, useEffect as useEffect7 } from "react";
2582
2590
  import { jsx as jsx31, jsxs as jsxs13 } from "react/jsx-runtime";
2583
2591
  var Tooltip = ({
2584
2592
  content,
@@ -2591,7 +2599,7 @@ var Tooltip = ({
2591
2599
  }) => {
2592
2600
  const [uncontrolledOpen, setUncontrolledOpen] = useState8(false);
2593
2601
  const [isTouchDevice, setIsTouchDevice] = useState8(false);
2594
- useEffect6(() => {
2602
+ useEffect7(() => {
2595
2603
  setIsTouchDevice("ontouchstart" in window || navigator.maxTouchPoints > 0);
2596
2604
  }, []);
2597
2605
  const open = controlledOpen ?? uncontrolledOpen;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Design System da Clikpalm",
4
4
  "author": "Enisson Shilo",
5
5
  "license": "MIT",
6
- "version": "1.3.6",
6
+ "version": "1.3.8",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/clickpalm/clickpalm-designsystem-lib.git"