@fuf-stack/uniform 0.22.0 → 0.22.1
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/CheckboxGroup/index.cjs +2 -2
- package/dist/CheckboxGroup/index.js +2 -2
- package/dist/FieldArray/index.cjs +2 -2
- package/dist/FieldArray/index.js +2 -2
- package/dist/Form/index.cjs +2 -2
- package/dist/Form/index.js +2 -2
- package/dist/Input/index.cjs +4 -4
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +3 -3
- package/dist/{Input-DsBWaOSk.d.ts → Input-BpsVvxwO.d.ts} +2 -2
- package/dist/{Input-qD-RcDl4.d.cts → Input-Com9bFxL.d.cts} +2 -2
- package/dist/RadioBoxes/index.cjs +2 -2
- package/dist/RadioBoxes/index.js +2 -2
- package/dist/RadioGroup/index.cjs +2 -2
- package/dist/RadioGroup/index.js +2 -2
- package/dist/RadioTabs/index.cjs +2 -2
- package/dist/RadioTabs/index.js +2 -2
- package/dist/Select/index.cjs +2 -2
- package/dist/Select/index.js +2 -2
- package/dist/SubmitButton/index.cjs +2 -2
- package/dist/SubmitButton/index.js +2 -2
- package/dist/Switch/index.cjs +2 -2
- package/dist/Switch/index.js +2 -2
- package/dist/TextArea/index.cjs +4 -4
- package/dist/TextArea/index.js +3 -3
- package/dist/{chunk-SHB3Z5GN.cjs → chunk-AZT3TDWZ.cjs} +3 -3
- package/dist/{chunk-SHB3Z5GN.cjs.map → chunk-AZT3TDWZ.cjs.map} +1 -1
- package/dist/{chunk-XDHY7DXJ.js → chunk-NNKOK5EU.js} +2 -2
- package/dist/{chunk-I2PJDXWB.cjs → chunk-OWWUTKGY.cjs} +18 -41
- package/dist/chunk-OWWUTKGY.cjs.map +1 -0
- package/dist/chunk-P6HJOG7D.cjs +41 -0
- package/dist/chunk-P6HJOG7D.cjs.map +1 -0
- package/dist/chunk-Q2BOMFJ5.js +41 -0
- package/dist/chunk-Q2BOMFJ5.js.map +1 -0
- package/dist/{chunk-EPY6UDD3.js → chunk-QDFIRRB5.js} +4 -4
- package/dist/chunk-QDFIRRB5.js.map +1 -0
- package/dist/{chunk-2EYP66KF.cjs → chunk-SG6PWCRL.cjs} +5 -5
- package/dist/chunk-SG6PWCRL.cjs.map +1 -0
- package/dist/{chunk-KMDTMBYI.js → chunk-U5WBLGZV.js} +18 -41
- package/dist/chunk-U5WBLGZV.js.map +1 -0
- package/dist/hooks/index.cjs +3 -3
- package/dist/hooks/index.js +2 -2
- package/dist/hooks/useInputValueDebounce/index.cjs +3 -3
- package/dist/hooks/useInputValueDebounce/index.d.cts +6 -6
- package/dist/hooks/useInputValueDebounce/index.d.ts +6 -6
- package/dist/hooks/useInputValueDebounce/index.js +2 -2
- package/dist/hooks/useInputValueTransform/index.cjs +2 -2
- package/dist/hooks/useInputValueTransform/index.d.cts +28 -60
- package/dist/hooks/useInputValueTransform/index.d.ts +28 -60
- package/dist/hooks/useInputValueTransform/index.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-2EYP66KF.cjs.map +0 -1
- package/dist/chunk-EPY6UDD3.js.map +0 -1
- package/dist/chunk-G5UX55XC.js +0 -37
- package/dist/chunk-G5UX55XC.js.map +0 -1
- package/dist/chunk-I2PJDXWB.cjs.map +0 -1
- package/dist/chunk-KMDTMBYI.js.map +0 -1
- package/dist/chunk-TSB65253.cjs +0 -37
- package/dist/chunk-TSB65253.cjs.map +0 -1
- /package/dist/{chunk-XDHY7DXJ.js.map → chunk-NNKOK5EU.js.map} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/hooks/useInputValueTransform/useInputValueTransform.ts
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
var useInputValueTransform = ({
|
|
4
|
+
type,
|
|
5
|
+
transform
|
|
6
|
+
}) => {
|
|
7
|
+
const toDisplayValue = useCallback(
|
|
8
|
+
(formValue) => {
|
|
9
|
+
if (transform == null ? void 0 : transform.toDisplayValue) {
|
|
10
|
+
return transform.toDisplayValue(formValue != null ? formValue : "");
|
|
11
|
+
}
|
|
12
|
+
if (type === "number") {
|
|
13
|
+
if (formValue === "") return "";
|
|
14
|
+
const numValue = Number(formValue);
|
|
15
|
+
return Number.isNaN(numValue) ? formValue : numValue;
|
|
16
|
+
}
|
|
17
|
+
return formValue != null ? formValue : "";
|
|
18
|
+
},
|
|
19
|
+
[type, transform]
|
|
20
|
+
);
|
|
21
|
+
const toFormValue = useCallback(
|
|
22
|
+
(displayValue) => {
|
|
23
|
+
if (type === "number") {
|
|
24
|
+
if (displayValue === "") return "";
|
|
25
|
+
const numValue = Number(displayValue);
|
|
26
|
+
return Number.isNaN(numValue) ? displayValue : numValue;
|
|
27
|
+
}
|
|
28
|
+
return (transform == null ? void 0 : transform.toFormValue) ? transform.toFormValue(displayValue) : displayValue;
|
|
29
|
+
},
|
|
30
|
+
[type, transform]
|
|
31
|
+
);
|
|
32
|
+
return {
|
|
33
|
+
toDisplayValue,
|
|
34
|
+
toFormValue
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
useInputValueTransform
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-Q2BOMFJ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"sourcesContent":["import { useCallback } from 'react';\n\nexport interface InputValueTransform {\n /** Transforms the form value to display value (e.g., 1000 → \"$1,000\") */\n toDisplayValue: (value: string | number) => string | number;\n /** Transforms the display value to form value (e.g., \"$1,000\" → 1000) */\n toFormValue: (value: string) => string | number;\n}\n\nexport interface UseInputValueTransformOptions {\n /** Input type for special number handling */\n type?: 'text' | 'number' | 'password';\n /** Value transformation functions */\n transform?: InputValueTransform;\n}\n\nexport interface UseInputValueTransformReturn {\n /** Converts any form value to display value */\n toDisplayValue: (formValue: string | number) => string | number;\n /** Converts any display value to form value */\n toFormValue: (displayValue: string | number) => string | number;\n}\n\n/**\n * Custom hook providing utility functions for value transformations between display and form values.\n *\n * This hook provides pure conversion functions without any state management. It's useful for:\n * - Currency formatting ($1,000 display vs 1000 stored)\n * - Number inputs with special handling\n * - Date formatting (MM/DD/YYYY display vs ISO date stored)\n * - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)\n *\n * **Key Features:**\n * - Pure conversion functions (no state)\n * - Special number input handling (empty string preservation)\n * - Bidirectional value transformations\n * - Memoized functions for performance\n *\n * @param options Configuration for value transformation\n * @returns Pure conversion utility functions\n *\n * @example\n * ```tsx\n * // Currency formatting\n * const currencyTransform = {\n * displayValue: (val) => val ? `$${Number(val).toLocaleString()}` : '',\n * formValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: currencyTransform\n * });\n *\n * const displayVal = toDisplayValue(1000); // \"$1,000\"\n * const formVal = toFormValue(\"$1,500\"); // 1500\n * ```\n *\n * @example\n * ```tsx\n * // Number input (no transforms needed)\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * type: 'number'\n * });\n *\n * // Handles empty string → empty string (not NaN)\n * // Handles \"123\" → 123 (string to number conversion)\n * ```\n *\n * @example\n * ```tsx\n * // Integration with debouncing\n * const MyInput = ({ field, transform }) => {\n * const transform = useInputValueTransform({ transform });\n *\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * ...transform,\n * initialValue: field.value,\n * debounceDelay: 300,\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * });\n *\n * return <input value={value} onChange={onChange} onBlur={onBlur} />;\n * };\n * ```\n */\nexport const useInputValueTransform = ({\n type,\n transform,\n}: UseInputValueTransformOptions): UseInputValueTransformReturn => {\n /**\n * Converts any form value to display value\n */\n const toDisplayValue = useCallback(\n (formValue: string | number): string | number => {\n if (transform?.toDisplayValue) {\n return transform.toDisplayValue(formValue ?? '');\n }\n\n // For number type, convert valid strings to numbers for display\n if (type === 'number') {\n if (formValue === '') return '';\n const numValue = Number(formValue);\n return Number.isNaN(numValue) ? formValue : numValue;\n }\n\n return formValue ?? '';\n },\n [type, transform],\n );\n\n /**\n * Converts any display value to form value\n */\n const toFormValue = useCallback(\n (displayValue: string | number): string | number => {\n if (type === 'number') {\n if (displayValue === '') return '';\n const numValue = Number(displayValue);\n return Number.isNaN(numValue) ? displayValue : numValue;\n }\n\n return transform?.toFormValue\n ? transform.toFormValue(displayValue as string)\n : displayValue;\n },\n [type, transform],\n );\n\n return {\n toDisplayValue,\n toFormValue,\n };\n};\n"],"mappings":";AAAA,SAAS,mBAAmB;AAsFrB,IAAM,yBAAyB,CAAC;AAAA,EACrC;AAAA,EACA;AACF,MAAmE;AAIjE,QAAM,iBAAiB;AAAA,IACrB,CAAC,cAAgD;AAC/C,UAAI,uCAAW,gBAAgB;AAC7B,eAAO,UAAU,eAAe,gCAAa,EAAE;AAAA,MACjD;AAGA,UAAI,SAAS,UAAU;AACrB,YAAI,cAAc,GAAI,QAAO;AAC7B,cAAM,WAAW,OAAO,SAAS;AACjC,eAAO,OAAO,MAAM,QAAQ,IAAI,YAAY;AAAA,MAC9C;AAEA,aAAO,gCAAa;AAAA,IACtB;AAAA,IACA,CAAC,MAAM,SAAS;AAAA,EAClB;AAKA,QAAM,cAAc;AAAA,IAClB,CAAC,iBAAmD;AAClD,UAAI,SAAS,UAAU;AACrB,YAAI,iBAAiB,GAAI,QAAO;AAChC,cAAM,WAAW,OAAO,YAAY;AACpC,eAAO,OAAO,MAAM,QAAQ,IAAI,eAAe;AAAA,MACjD;AAEA,cAAO,uCAAW,eACd,UAAU,YAAY,YAAsB,IAC5C;AAAA,IACN;AAAA,IACA,CAAC,MAAM,SAAS;AAAA,EAClB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "./chunk-7QWLAPOT.js";
|
|
11
11
|
import {
|
|
12
12
|
useInputValueDebounce
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-U5WBLGZV.js";
|
|
14
14
|
|
|
15
15
|
// src/Input/Input.tsx
|
|
16
16
|
import { Input as HeroInput } from "@heroui/input";
|
|
@@ -27,7 +27,7 @@ var Input = ({
|
|
|
27
27
|
size = void 0,
|
|
28
28
|
startContent = void 0,
|
|
29
29
|
testId: _testId = void 0,
|
|
30
|
-
|
|
30
|
+
transform = void 0,
|
|
31
31
|
type = void 0
|
|
32
32
|
}) => {
|
|
33
33
|
const { control, debugMode, getFieldState } = useFormContext();
|
|
@@ -48,7 +48,7 @@ var Input = ({
|
|
|
48
48
|
debounceDelay,
|
|
49
49
|
onBlur: fieldOnBlur,
|
|
50
50
|
onChange: fieldOnChange,
|
|
51
|
-
|
|
51
|
+
transform,
|
|
52
52
|
type,
|
|
53
53
|
value: fieldValue
|
|
54
54
|
});
|
|
@@ -95,4 +95,4 @@ export {
|
|
|
95
95
|
Input_default,
|
|
96
96
|
Input_default2
|
|
97
97
|
};
|
|
98
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-QDFIRRB5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Input/Input.tsx","../src/Input/index.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks';\n\nimport { Input as HeroInput } from '@heroui/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useController, useFormContext, useInputValueDebounce } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface InputProps {\n /** CSS class name */\n className?: string;\n /** debounce delay in milliseconds for form state updates (default: 300ms) */\n debounceDelay?: number;\n /** input field is disabled */\n disabled?: boolean;\n /** added content to the end of the input Field. */\n endContent?: ReactNode;\n /** form field label (set to false to disable label) */\n label?: string | false;\n /** form field name */\n name: string;\n /** form field placeholder */\n placeholder?: string;\n /** size of the input */\n size?: 'sm' | 'md' | 'lg';\n /** content added to the start of the input field */\n startContent?: ReactNode;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** allows disentangled display and form values for a field */\n transform?: InputValueTransform;\n /** input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)\n */\nconst Input = ({\n className = undefined,\n debounceDelay = 300,\n disabled = false,\n endContent = undefined,\n label = undefined,\n name,\n placeholder = ' ',\n size = undefined,\n startContent = undefined,\n testId: _testId = undefined,\n transform = undefined,\n type = undefined,\n}: InputProps) => {\n const { control, debugMode, getFieldState } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const { field } = useController({\n control,\n disabled,\n name,\n });\n\n const {\n disabled: isDisabled,\n onChange: fieldOnChange,\n onBlur: fieldOnBlur,\n value: fieldValue,\n ref,\n } = field;\n\n // Use hook that provides debounced onChange and enhanced blur handling\n const { onChange, onBlur, value } = useInputValueDebounce({\n debounceDelay,\n onBlur: fieldOnBlur,\n onChange: fieldOnChange,\n transform,\n type,\n value: fieldValue,\n });\n\n const showTestIdCopyButton = debugMode === 'debug-testids';\n const showLabel = label || showTestIdCopyButton;\n\n return (\n <HeroInput\n className={cn(className)}\n classNames={{\n inputWrapper: 'bg-content1 group-data-[focus=true]:border-focus',\n }}\n data-testid={testId}\n endContent={endContent}\n errorMessage={\n error && <FieldValidationError error={error} testId={testId} />\n }\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n showLabel && (\n <>\n {label}\n {showTestIdCopyButton && <FieldCopyTestIdButton testId={testId} />}\n </>\n )\n }\n labelPlacement=\"outside\"\n name={name}\n onBlur={onBlur}\n onChange={onChange}\n placeholder={placeholder}\n radius=\"sm\"\n ref={ref}\n size={size}\n startContent={startContent}\n type={type}\n // @ts-expect-error can be number for input type number\n value={value}\n variant=\"bordered\"\n />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport { Input };\n\nexport default Input;\n"],"mappings":";;;;;;;;;;;;;;;AAGA,SAAS,SAAS,iBAAiB;AAEnC,SAAS,UAAU;AAyFF,SAOP,UAPO,KAOP,YAPO;AArDjB,IAAM,QAAQ,CAAC;AAAA,EACb,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,QAAQ;AAAA,EACR;AAAA,EACA,cAAc;AAAA,EACd,OAAO;AAAA,EACP,eAAe;AAAA,EACf,QAAQ,UAAU;AAAA,EAClB,YAAY;AAAA,EACZ,OAAO;AACT,MAAkB;AAChB,QAAM,EAAE,SAAS,WAAW,cAAc,IAAI,eAAe;AAC7D,QAAM,EAAE,OAAO,SAAS,UAAU,OAAO,IAAI,cAAc,MAAM,OAAO;AAExE,QAAM,EAAE,MAAM,IAAI,cAAc;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,OAAO;AAAA,IACP;AAAA,EACF,IAAI;AAGJ,QAAM,EAAE,UAAU,QAAQ,MAAM,IAAI,sBAAsB;AAAA,IACxD;AAAA,IACA,QAAQ;AAAA,IACR,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AAED,QAAM,uBAAuB,cAAc;AAC3C,QAAM,YAAY,SAAS;AAE3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,SAAS;AAAA,MACvB,YAAY;AAAA,QACV,cAAc;AAAA,MAChB;AAAA,MACA,eAAa;AAAA,MACb;AAAA,MACA,cACE,SAAS,oBAAC,gCAAqB,OAAc,QAAgB;AAAA,MAE/D;AAAA,MACA,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,OACE,aACE,iCACG;AAAA;AAAA,QACA,wBAAwB,oBAAC,iCAAsB,QAAgB;AAAA,SAClE;AAAA,MAGJ,gBAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,MACA,SAAQ;AAAA;AAAA,EACV;AAEJ;AAEA,IAAO,gBAAQ;;;ACtHf,IAAOA,iBAAQ;","names":["Input_default"]}
|
|
@@ -10,7 +10,7 @@ var _chunkGNYQC5IJcjs = require('./chunk-GNYQC5IJ.cjs');
|
|
|
10
10
|
var _chunkY6EAPURVcjs = require('./chunk-Y6EAPURV.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkOWWUTKGYcjs = require('./chunk-OWWUTKGY.cjs');
|
|
14
14
|
|
|
15
15
|
// src/Input/Input.tsx
|
|
16
16
|
var _input = require('@heroui/input');
|
|
@@ -27,7 +27,7 @@ var Input = ({
|
|
|
27
27
|
size = void 0,
|
|
28
28
|
startContent = void 0,
|
|
29
29
|
testId: _testId = void 0,
|
|
30
|
-
|
|
30
|
+
transform = void 0,
|
|
31
31
|
type = void 0
|
|
32
32
|
}) => {
|
|
33
33
|
const { control, debugMode, getFieldState } = _chunkY6EAPURVcjs.useFormContext.call(void 0, );
|
|
@@ -44,11 +44,11 @@ var Input = ({
|
|
|
44
44
|
value: fieldValue,
|
|
45
45
|
ref
|
|
46
46
|
} = field;
|
|
47
|
-
const { onChange, onBlur, value } =
|
|
47
|
+
const { onChange, onBlur, value } = _chunkOWWUTKGYcjs.useInputValueDebounce.call(void 0, {
|
|
48
48
|
debounceDelay,
|
|
49
49
|
onBlur: fieldOnBlur,
|
|
50
50
|
onChange: fieldOnChange,
|
|
51
|
-
|
|
51
|
+
transform,
|
|
52
52
|
type,
|
|
53
53
|
value: fieldValue
|
|
54
54
|
});
|
|
@@ -95,4 +95,4 @@ var Input_default2 = Input_default;
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
exports.Input_default = Input_default; exports.Input_default2 = Input_default2;
|
|
98
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-SG6PWCRL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-SG6PWCRL.cjs","../src/Input/Input.tsx","../src/Input/index.ts"],"names":["Input_default"],"mappings":"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","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-SG6PWCRL.cjs","sourcesContent":[null,"import type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks';\n\nimport { Input as HeroInput } from '@heroui/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useController, useFormContext, useInputValueDebounce } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface InputProps {\n /** CSS class name */\n className?: string;\n /** debounce delay in milliseconds for form state updates (default: 300ms) */\n debounceDelay?: number;\n /** input field is disabled */\n disabled?: boolean;\n /** added content to the end of the input Field. */\n endContent?: ReactNode;\n /** form field label (set to false to disable label) */\n label?: string | false;\n /** form field name */\n name: string;\n /** form field placeholder */\n placeholder?: string;\n /** size of the input */\n size?: 'sm' | 'md' | 'lg';\n /** content added to the start of the input field */\n startContent?: ReactNode;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** allows disentangled display and form values for a field */\n transform?: InputValueTransform;\n /** input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)\n */\nconst Input = ({\n className = undefined,\n debounceDelay = 300,\n disabled = false,\n endContent = undefined,\n label = undefined,\n name,\n placeholder = ' ',\n size = undefined,\n startContent = undefined,\n testId: _testId = undefined,\n transform = undefined,\n type = undefined,\n}: InputProps) => {\n const { control, debugMode, getFieldState } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const { field } = useController({\n control,\n disabled,\n name,\n });\n\n const {\n disabled: isDisabled,\n onChange: fieldOnChange,\n onBlur: fieldOnBlur,\n value: fieldValue,\n ref,\n } = field;\n\n // Use hook that provides debounced onChange and enhanced blur handling\n const { onChange, onBlur, value } = useInputValueDebounce({\n debounceDelay,\n onBlur: fieldOnBlur,\n onChange: fieldOnChange,\n transform,\n type,\n value: fieldValue,\n });\n\n const showTestIdCopyButton = debugMode === 'debug-testids';\n const showLabel = label || showTestIdCopyButton;\n\n return (\n <HeroInput\n className={cn(className)}\n classNames={{\n inputWrapper: 'bg-content1 group-data-[focus=true]:border-focus',\n }}\n data-testid={testId}\n endContent={endContent}\n errorMessage={\n error && <FieldValidationError error={error} testId={testId} />\n }\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n showLabel && (\n <>\n {label}\n {showTestIdCopyButton && <FieldCopyTestIdButton testId={testId} />}\n </>\n )\n }\n labelPlacement=\"outside\"\n name={name}\n onBlur={onBlur}\n onChange={onChange}\n placeholder={placeholder}\n radius=\"sm\"\n ref={ref}\n size={size}\n startContent={startContent}\n type={type}\n // @ts-expect-error can be number for input type number\n value={value}\n variant=\"bordered\"\n />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport { Input };\n\nexport default Input;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useInputValueTransform
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q2BOMFJ5.js";
|
|
4
4
|
import {
|
|
5
5
|
__spreadProps,
|
|
6
6
|
__spreadValues
|
|
@@ -12,50 +12,27 @@ var useInputValueDebounce = ({
|
|
|
12
12
|
debounceDelay = 300,
|
|
13
13
|
onBlur,
|
|
14
14
|
onChange,
|
|
15
|
-
|
|
15
|
+
transform,
|
|
16
16
|
type,
|
|
17
17
|
value
|
|
18
18
|
}) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
value
|
|
19
|
+
const { toDisplayValue, toFormValue } = useInputValueTransform({
|
|
20
|
+
transform,
|
|
21
|
+
type
|
|
23
22
|
});
|
|
24
|
-
const
|
|
25
|
-
(rawValue) => {
|
|
26
|
-
const stringValue = String(rawValue);
|
|
27
|
-
if (transformValue) {
|
|
28
|
-
return transformValue.formValue(stringValue);
|
|
29
|
-
}
|
|
30
|
-
if (type === "number" && stringValue !== "") {
|
|
31
|
-
const numValue = Number(stringValue);
|
|
32
|
-
return Number.isNaN(numValue) ? rawValue : numValue;
|
|
33
|
-
}
|
|
34
|
-
return rawValue;
|
|
35
|
-
},
|
|
36
|
-
[transformValue, type]
|
|
37
|
-
);
|
|
38
|
-
const displayValue = transformValue ? transform.displayValue : value;
|
|
39
|
-
const [currentDisplayValue, setCurrentDisplayValue] = useState(displayValue);
|
|
23
|
+
const [displayValue, setDisplayValue] = useState(() => toDisplayValue(value));
|
|
40
24
|
const timeoutRef = useRef(null);
|
|
41
25
|
useEffect(() => {
|
|
42
|
-
|
|
43
|
-
}, [
|
|
26
|
+
setDisplayValue(toDisplayValue(value));
|
|
27
|
+
}, [value, toDisplayValue]);
|
|
44
28
|
const handleChange = useCallback(
|
|
45
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
30
|
(...event) => {
|
|
47
|
-
var _a, _b, _c
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
displayVal = Number.isNaN(numValue) ? newValue : numValue;
|
|
53
|
-
}
|
|
54
|
-
setCurrentDisplayValue(displayVal);
|
|
55
|
-
if (transformValue && ((_d = event[0]) == null ? void 0 : _d.target)) {
|
|
56
|
-
transform.handleInputChange(event[0]);
|
|
57
|
-
}
|
|
58
|
-
const formValue = getFormValue(newValue);
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
const rawValue = (_c = (_b = (_a = event[0]) == null ? void 0 : _a.target) == null ? void 0 : _b.value) != null ? _c : event[0];
|
|
33
|
+
const newDisplayValue = transform ? rawValue : toDisplayValue(rawValue);
|
|
34
|
+
setDisplayValue(newDisplayValue);
|
|
35
|
+
const formValue = toFormValue(newDisplayValue);
|
|
59
36
|
if (timeoutRef.current) {
|
|
60
37
|
clearTimeout(timeoutRef.current);
|
|
61
38
|
}
|
|
@@ -78,25 +55,25 @@ var useInputValueDebounce = ({
|
|
|
78
55
|
timeoutRef.current = setTimeout(executeOnChange, debounceDelay);
|
|
79
56
|
}
|
|
80
57
|
},
|
|
81
|
-
[onChange, debounceDelay,
|
|
58
|
+
[onChange, debounceDelay, toDisplayValue, toFormValue, transform]
|
|
82
59
|
);
|
|
83
60
|
const handleBlur = useCallback(() => {
|
|
84
61
|
if (timeoutRef.current) {
|
|
85
62
|
clearTimeout(timeoutRef.current);
|
|
86
63
|
timeoutRef.current = null;
|
|
87
|
-
const formValue =
|
|
64
|
+
const formValue = toFormValue(displayValue);
|
|
88
65
|
onChange(formValue);
|
|
89
66
|
}
|
|
90
67
|
onBlur();
|
|
91
|
-
}, [
|
|
68
|
+
}, [onChange, onBlur, toFormValue, displayValue]);
|
|
92
69
|
return {
|
|
93
70
|
onChange: handleChange,
|
|
94
71
|
onBlur: handleBlur,
|
|
95
|
-
value:
|
|
72
|
+
value: displayValue
|
|
96
73
|
};
|
|
97
74
|
};
|
|
98
75
|
|
|
99
76
|
export {
|
|
100
77
|
useInputValueDebounce
|
|
101
78
|
};
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-U5WBLGZV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useInputValueDebounce/useInputValueDebounce.ts"],"sourcesContent":["import type { InputValueTransform } from '../useInputValueTransform/useInputValueTransform';\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useInputValueTransform } from '../useInputValueTransform/useInputValueTransform';\n\nexport interface UseInputValueDebounceOptions {\n /** Debounce delay in milliseconds (default: 300) */\n debounceDelay?: number;\n /** The onBlur function to call after flushing debounced value */\n onBlur: () => void;\n /** The onChange function to call with debounced value */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** Value transformation functions */\n transform?: InputValueTransform;\n /** Input type to handle number conversion (optional) */\n type?: 'text' | 'number' | 'password';\n /** The initial form value */\n value: string | number;\n}\n\nexport interface UseInputValueDebounceReturn {\n /** Enhanced onChange function with debouncing */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** Enhanced onBlur function that flushes current value immediately */\n onBlur: () => void;\n /** The field value that is displayed - updates immediately */\n value: string | number;\n}\n\n/**\n * Custom hook for debouncing input value changes with immediate blur support.\n *\n * Provides immediate visual feedback by updating the display value instantly,\n * while debouncing the actual form state changes. When the input loses focus,\n * any pending debounced changes are immediately flushed.\n *\n * **Key Features:**\n * - **Debouncing**: Delays form updates until user stops typing\n * - **Transform support**: Optional value transformation between display and form values\n * - **Number conversion**: Automatic conversion for number inputs\n * - **Immediate display updates**: UI stays responsive during debouncing\n * - **Blur flushing**: Immediately applies pending changes on blur\n *\n * @param options Configuration for debounced value handling\n * @param options.debounceDelay Delay in milliseconds (default: 300)\n * @param options.onBlur Function to call after flushing debounced value\n * @param options.onChange Function to call with debounced value\n * @param options.transform Optional transform functions for display ↔ form value conversion\n * @param options.type Input type for number conversion ('text' | 'number' | 'password')\n * @param options.value The initial form value\n * @returns Object containing enhanced onChange, onBlur, and immediate display value\n *\n * @example\n * Basic usage with debouncing:\n * ```tsx\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * debounceDelay: 300,\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * value: field.value,\n * });\n * ```\n *\n * @example\n * Number input with automatic conversion:\n * ```tsx\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * debounceDelay: 300,\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * type: 'number',\n * value: field.value, // Display: 123 (number), Form: 123 (number)\n * });\n * ```\n *\n * @example\n * Currency formatting with transforms:\n * ```tsx\n * const currencyTransform = {\n * displayValue: (val) => val ? `$${Number(val).toFixed(2)}` : '',\n * formValue: (val) => Number(val.replace(/[$,]/g, '')) || 0\n * };\n *\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * debounceDelay: 300,\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * transform: currencyTransform,\n * value: field.value, // Display: \"$100.00\", Form: 100\n * });\n * ```\n */\nexport const useInputValueDebounce = ({\n debounceDelay = 300,\n onBlur,\n onChange,\n transform,\n type,\n value,\n}: UseInputValueDebounceOptions): UseInputValueDebounceReturn => {\n // Get conversion utilities from transform hook\n const { toDisplayValue, toFormValue } = useInputValueTransform({\n transform,\n type,\n });\n\n // Track display value for synchronous updates\n const [displayValue, setDisplayValue] = useState(() => toDisplayValue(value));\n\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n\n // Sync with external value changes\n useEffect(() => {\n setDisplayValue(toDisplayValue(value));\n }, [value, toDisplayValue]);\n\n // Enhanced onChange handler with debouncing\n const handleChange = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (...event: any[]) => {\n // Extract the raw input value\n const rawValue = event[0]?.target?.value ?? event[0];\n\n // For transforms, user input is already in display format\n // For number types, convert strings to numbers for display\n const newDisplayValue = transform ? rawValue : toDisplayValue(rawValue);\n setDisplayValue(newDisplayValue);\n\n // Convert to form value using transform utilities\n const formValue = toFormValue(newDisplayValue);\n\n // Clear existing timeout\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n const executeOnChange = () => {\n // Preserve event structure if original was an event\n if (event[0]?.target) {\n const convertedEvent = {\n ...event[0],\n target: {\n ...event[0].target,\n value: formValue,\n },\n };\n onChange(convertedEvent, ...event.slice(1));\n } else {\n onChange(formValue);\n }\n };\n\n // Execute immediately or after delay\n if (debounceDelay <= 0) {\n executeOnChange();\n } else {\n timeoutRef.current = setTimeout(executeOnChange, debounceDelay);\n }\n },\n [onChange, debounceDelay, toDisplayValue, toFormValue, transform],\n );\n\n // Enhanced blur handler\n const handleBlur = useCallback(() => {\n // Flush pending changes\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n\n // Get form value from current display value\n const formValue = toFormValue(displayValue);\n onChange(formValue);\n }\n onBlur();\n }, [onChange, onBlur, toFormValue, displayValue]);\n\n return {\n onChange: handleChange,\n onBlur: handleBlur,\n value: displayValue,\n };\n};\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AA6FlD,IAAM,wBAAwB,CAAC;AAAA,EACpC,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAiE;AAE/D,QAAM,EAAE,gBAAgB,YAAY,IAAI,uBAAuB;AAAA,IAC7D;AAAA,IACA;AAAA,EACF,CAAC;AAGD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,MAAM,eAAe,KAAK,CAAC;AAE5E,QAAM,aAAa,OAA8B,IAAI;AAGrD,YAAU,MAAM;AACd,oBAAgB,eAAe,KAAK,CAAC;AAAA,EACvC,GAAG,CAAC,OAAO,cAAc,CAAC;AAG1B,QAAM,eAAe;AAAA;AAAA,IAEnB,IAAI,UAAiB;AA1HzB;AA4HM,YAAM,YAAW,uBAAM,CAAC,MAAP,mBAAU,WAAV,mBAAkB,UAAlB,YAA2B,MAAM,CAAC;AAInD,YAAM,kBAAkB,YAAY,WAAW,eAAe,QAAQ;AACtE,sBAAgB,eAAe;AAG/B,YAAM,YAAY,YAAY,eAAe;AAG7C,UAAI,WAAW,SAAS;AACtB,qBAAa,WAAW,OAAO;AAAA,MACjC;AAEA,YAAM,kBAAkB,MAAM;AA3IpC,YAAAA;AA6IQ,aAAIA,MAAA,MAAM,CAAC,MAAP,gBAAAA,IAAU,QAAQ;AACpB,gBAAM,iBAAiB,iCAClB,MAAM,CAAC,IADW;AAAA,YAErB,QAAQ,iCACH,MAAM,CAAC,EAAE,SADN;AAAA,cAEN,OAAO;AAAA,YACT;AAAA,UACF;AACA,mBAAS,gBAAgB,GAAG,MAAM,MAAM,CAAC,CAAC;AAAA,QAC5C,OAAO;AACL,mBAAS,SAAS;AAAA,QACpB;AAAA,MACF;AAGA,UAAI,iBAAiB,GAAG;AACtB,wBAAgB;AAAA,MAClB,OAAO;AACL,mBAAW,UAAU,WAAW,iBAAiB,aAAa;AAAA,MAChE;AAAA,IACF;AAAA,IACA,CAAC,UAAU,eAAe,gBAAgB,aAAa,SAAS;AAAA,EAClE;AAGA,QAAM,aAAa,YAAY,MAAM;AAEnC,QAAI,WAAW,SAAS;AACtB,mBAAa,WAAW,OAAO;AAC/B,iBAAW,UAAU;AAGrB,YAAM,YAAY,YAAY,YAAY;AAC1C,eAAS,SAAS;AAAA,IACpB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,UAAU,QAAQ,aAAa,YAAY,CAAC;AAEhD,SAAO;AAAA,IACL,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;","names":["_a"]}
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -9,10 +9,10 @@ var _chunkY6EAPURVcjs = require('../chunk-Y6EAPURV.cjs');
|
|
|
9
9
|
require('../chunk-L4YPB7MU.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkOWWUTKGYcjs = require('../chunk-OWWUTKGY.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkP6HJOG7Dcjs = require('../chunk-P6HJOG7D.cjs');
|
|
16
16
|
require('../chunk-555JRYCS.cjs');
|
|
17
17
|
|
|
18
18
|
|
|
@@ -23,5 +23,5 @@ require('../chunk-555JRYCS.cjs');
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
exports.checkFieldIsRequired = _chunkY6EAPURVcjs.checkFieldIsRequired; exports.useClientValidation = _chunkY6EAPURVcjs.useClientValidation; exports.useController = _chunkY6EAPURVcjs.useController; exports.useFieldArray = _chunkY6EAPURVcjs.useFieldArray; exports.useFormContext = _chunkY6EAPURVcjs.useFormContext; exports.useInput = _chunkY6EAPURVcjs.useInput; exports.useInputValueDebounce =
|
|
26
|
+
exports.checkFieldIsRequired = _chunkY6EAPURVcjs.checkFieldIsRequired; exports.useClientValidation = _chunkY6EAPURVcjs.useClientValidation; exports.useController = _chunkY6EAPURVcjs.useController; exports.useFieldArray = _chunkY6EAPURVcjs.useFieldArray; exports.useFormContext = _chunkY6EAPURVcjs.useFormContext; exports.useInput = _chunkY6EAPURVcjs.useInput; exports.useInputValueDebounce = _chunkOWWUTKGYcjs.useInputValueDebounce; exports.useInputValueTransform = _chunkP6HJOG7Dcjs.useInputValueTransform;
|
|
27
27
|
//# sourceMappingURL=index.cjs.map
|
package/dist/hooks/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
import "../chunk-57WY5GAE.js";
|
|
10
10
|
import {
|
|
11
11
|
useInputValueDebounce
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-U5WBLGZV.js";
|
|
13
13
|
import {
|
|
14
14
|
useInputValueTransform
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-Q2BOMFJ5.js";
|
|
16
16
|
import "../chunk-K2V4ULA2.js";
|
|
17
17
|
export {
|
|
18
18
|
checkFieldIsRequired,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var _chunkOWWUTKGYcjs = require('../../chunk-OWWUTKGY.cjs');
|
|
4
|
+
require('../../chunk-P6HJOG7D.cjs');
|
|
5
5
|
require('../../chunk-555JRYCS.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.useInputValueDebounce =
|
|
8
|
+
exports.useInputValueDebounce = _chunkOWWUTKGYcjs.useInputValueDebounce;
|
|
9
9
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -8,10 +8,10 @@ interface UseInputValueDebounceOptions {
|
|
|
8
8
|
/** The onChange function to call with debounced value */
|
|
9
9
|
onChange: (...event: any[]) => void;
|
|
10
10
|
/** Value transformation functions */
|
|
11
|
-
|
|
11
|
+
transform?: InputValueTransform;
|
|
12
12
|
/** Input type to handle number conversion (optional) */
|
|
13
13
|
type?: 'text' | 'number' | 'password';
|
|
14
|
-
/** The
|
|
14
|
+
/** The initial form value */
|
|
15
15
|
value: string | number;
|
|
16
16
|
}
|
|
17
17
|
interface UseInputValueDebounceReturn {
|
|
@@ -40,9 +40,9 @@ interface UseInputValueDebounceReturn {
|
|
|
40
40
|
* @param options.debounceDelay Delay in milliseconds (default: 300)
|
|
41
41
|
* @param options.onBlur Function to call after flushing debounced value
|
|
42
42
|
* @param options.onChange Function to call with debounced value
|
|
43
|
-
* @param options.
|
|
43
|
+
* @param options.transform Optional transform functions for display ↔ form value conversion
|
|
44
44
|
* @param options.type Input type for number conversion ('text' | 'number' | 'password')
|
|
45
|
-
* @param options.value The
|
|
45
|
+
* @param options.value The initial form value
|
|
46
46
|
* @returns Object containing enhanced onChange, onBlur, and immediate display value
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
@@ -80,11 +80,11 @@ interface UseInputValueDebounceReturn {
|
|
|
80
80
|
* debounceDelay: 300,
|
|
81
81
|
* onBlur: field.onBlur,
|
|
82
82
|
* onChange: field.onChange,
|
|
83
|
-
*
|
|
83
|
+
* transform: currencyTransform,
|
|
84
84
|
* value: field.value, // Display: "$100.00", Form: 100
|
|
85
85
|
* });
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
declare const useInputValueDebounce: ({ debounceDelay, onBlur, onChange,
|
|
88
|
+
declare const useInputValueDebounce: ({ debounceDelay, onBlur, onChange, transform, type, value, }: UseInputValueDebounceOptions) => UseInputValueDebounceReturn;
|
|
89
89
|
|
|
90
90
|
export { type UseInputValueDebounceOptions, type UseInputValueDebounceReturn, useInputValueDebounce };
|
|
@@ -8,10 +8,10 @@ interface UseInputValueDebounceOptions {
|
|
|
8
8
|
/** The onChange function to call with debounced value */
|
|
9
9
|
onChange: (...event: any[]) => void;
|
|
10
10
|
/** Value transformation functions */
|
|
11
|
-
|
|
11
|
+
transform?: InputValueTransform;
|
|
12
12
|
/** Input type to handle number conversion (optional) */
|
|
13
13
|
type?: 'text' | 'number' | 'password';
|
|
14
|
-
/** The
|
|
14
|
+
/** The initial form value */
|
|
15
15
|
value: string | number;
|
|
16
16
|
}
|
|
17
17
|
interface UseInputValueDebounceReturn {
|
|
@@ -40,9 +40,9 @@ interface UseInputValueDebounceReturn {
|
|
|
40
40
|
* @param options.debounceDelay Delay in milliseconds (default: 300)
|
|
41
41
|
* @param options.onBlur Function to call after flushing debounced value
|
|
42
42
|
* @param options.onChange Function to call with debounced value
|
|
43
|
-
* @param options.
|
|
43
|
+
* @param options.transform Optional transform functions for display ↔ form value conversion
|
|
44
44
|
* @param options.type Input type for number conversion ('text' | 'number' | 'password')
|
|
45
|
-
* @param options.value The
|
|
45
|
+
* @param options.value The initial form value
|
|
46
46
|
* @returns Object containing enhanced onChange, onBlur, and immediate display value
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
@@ -80,11 +80,11 @@ interface UseInputValueDebounceReturn {
|
|
|
80
80
|
* debounceDelay: 300,
|
|
81
81
|
* onBlur: field.onBlur,
|
|
82
82
|
* onChange: field.onChange,
|
|
83
|
-
*
|
|
83
|
+
* transform: currencyTransform,
|
|
84
84
|
* value: field.value, // Display: "$100.00", Form: 100
|
|
85
85
|
* });
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
declare const useInputValueDebounce: ({ debounceDelay, onBlur, onChange,
|
|
88
|
+
declare const useInputValueDebounce: ({ debounceDelay, onBlur, onChange, transform, type, value, }: UseInputValueDebounceOptions) => UseInputValueDebounceReturn;
|
|
89
89
|
|
|
90
90
|
export { type UseInputValueDebounceOptions, type UseInputValueDebounceReturn, useInputValueDebounce };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkP6HJOG7Dcjs = require('../../chunk-P6HJOG7D.cjs');
|
|
4
4
|
require('../../chunk-555JRYCS.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.useInputValueTransform =
|
|
7
|
+
exports.useInputValueTransform = _chunkP6HJOG7Dcjs.useInputValueTransform;
|
|
8
8
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
interface InputValueTransform {
|
|
2
2
|
/** Transforms the form value to display value (e.g., 1000 → "$1,000") */
|
|
3
|
-
|
|
3
|
+
toDisplayValue: (value: string | number) => string | number;
|
|
4
4
|
/** Transforms the display value to form value (e.g., "$1,000" → 1000) */
|
|
5
|
-
|
|
5
|
+
toFormValue: (value: string) => string | number;
|
|
6
6
|
}
|
|
7
7
|
interface UseInputValueTransformOptions {
|
|
8
|
-
/** The current form field value */
|
|
9
|
-
value: string | number;
|
|
10
8
|
/** Input type for special number handling */
|
|
11
9
|
type?: 'text' | 'number' | 'password';
|
|
12
10
|
/** Value transformation functions */
|
|
13
|
-
|
|
11
|
+
transform?: InputValueTransform;
|
|
14
12
|
}
|
|
15
13
|
interface UseInputValueTransformReturn {
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/** Gets the form value from current display value */
|
|
21
|
-
getFormValue: () => string | number;
|
|
14
|
+
/** Converts any form value to display value */
|
|
15
|
+
toDisplayValue: (formValue: string | number) => string | number;
|
|
16
|
+
/** Converts any display value to form value */
|
|
17
|
+
toFormValue: (displayValue: string | number) => string | number;
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
|
-
* Custom hook
|
|
20
|
+
* Custom hook providing utility functions for value transformations between display and form values.
|
|
25
21
|
*
|
|
26
|
-
* This hook
|
|
27
|
-
* stored in the form (form value). It's particularly useful for:
|
|
22
|
+
* This hook provides pure conversion functions without any state management. It's useful for:
|
|
28
23
|
* - Currency formatting ($1,000 display vs 1000 stored)
|
|
29
24
|
* - Number inputs with special handling
|
|
30
25
|
* - Date formatting (MM/DD/YYYY display vs ISO date stored)
|
|
31
26
|
* - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)
|
|
32
27
|
*
|
|
33
28
|
* **Key Features:**
|
|
34
|
-
* -
|
|
35
|
-
* - Automatic external value synchronization (form resets, setValue calls)
|
|
29
|
+
* - Pure conversion functions (no state)
|
|
36
30
|
* - Special number input handling (empty string preservation)
|
|
37
31
|
* - Bidirectional value transformations
|
|
32
|
+
* - Memoized functions for performance
|
|
38
33
|
*
|
|
39
34
|
* @param options Configuration for value transformation
|
|
40
|
-
* @returns
|
|
35
|
+
* @returns Pure conversion utility functions
|
|
41
36
|
*
|
|
42
37
|
* @example
|
|
43
38
|
* ```tsx
|
|
@@ -47,70 +42,43 @@ interface UseInputValueTransformReturn {
|
|
|
47
42
|
* formValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0
|
|
48
43
|
* };
|
|
49
44
|
*
|
|
50
|
-
* const {
|
|
51
|
-
*
|
|
52
|
-
* transformValue: currencyTransform
|
|
45
|
+
* const { toDisplayValue, toFormValue } = useInputValueTransform({
|
|
46
|
+
* transform: currencyTransform
|
|
53
47
|
* });
|
|
54
|
-
* // displayValue = "$1,000"
|
|
55
|
-
* // getFormValue() = 1000
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```tsx
|
|
60
|
-
* // Phone number formatting
|
|
61
|
-
* const phoneTransform = {
|
|
62
|
-
* displayValue: (val) => {
|
|
63
|
-
* const cleaned = val.toString().replace(/\D/g, '');
|
|
64
|
-
* const match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
|
|
65
|
-
* return match ? `(${match[1]}) ${match[2]}-${match[3]}` : val;
|
|
66
|
-
* },
|
|
67
|
-
* formValue: (val) => val.replace(/\D/g, '')
|
|
68
|
-
* };
|
|
69
48
|
*
|
|
70
|
-
* const
|
|
71
|
-
*
|
|
72
|
-
* transformValue: phoneTransform
|
|
73
|
-
* });
|
|
74
|
-
* // displayValue = "(555) 123-4567"
|
|
75
|
-
* // getFormValue() = "5551234567"
|
|
49
|
+
* const displayVal = toDisplayValue(1000); // "$1,000"
|
|
50
|
+
* const formVal = toFormValue("$1,500"); // 1500
|
|
76
51
|
* ```
|
|
77
52
|
*
|
|
78
53
|
* @example
|
|
79
54
|
* ```tsx
|
|
80
55
|
* // Number input (no transforms needed)
|
|
81
|
-
* const {
|
|
82
|
-
* value: 42,
|
|
56
|
+
* const { toDisplayValue, toFormValue } = useInputValueTransform({
|
|
83
57
|
* type: 'number'
|
|
84
58
|
* });
|
|
59
|
+
*
|
|
85
60
|
* // Handles empty string → empty string (not NaN)
|
|
86
61
|
* // Handles "123" → 123 (string to number conversion)
|
|
87
62
|
* ```
|
|
88
63
|
*
|
|
89
64
|
* @example
|
|
90
65
|
* ```tsx
|
|
91
|
-
* //
|
|
92
|
-
* const MyInput = ({ field,
|
|
93
|
-
* const
|
|
94
|
-
* value: field.value,
|
|
95
|
-
* transformValue
|
|
96
|
-
* });
|
|
66
|
+
* // Integration with debouncing
|
|
67
|
+
* const MyInput = ({ field, transform }) => {
|
|
68
|
+
* const transform = useInputValueTransform({ transform });
|
|
97
69
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
70
|
+
* const { onChange, onBlur, value } = useInputValueDebounce({
|
|
71
|
+
* ...transform,
|
|
72
|
+
* initialValue: field.value,
|
|
73
|
+
* debounceDelay: 300,
|
|
74
|
+
* onBlur: field.onBlur,
|
|
101
75
|
* onChange: field.onChange,
|
|
102
|
-
* debounceDelay: 300
|
|
103
76
|
* });
|
|
104
77
|
*
|
|
105
|
-
* return
|
|
106
|
-
* <input
|
|
107
|
-
* value={displayValue}
|
|
108
|
-
* onChange={handleInputChange}
|
|
109
|
-
* />
|
|
110
|
-
* );
|
|
78
|
+
* return <input value={value} onChange={onChange} onBlur={onBlur} />;
|
|
111
79
|
* };
|
|
112
80
|
* ```
|
|
113
81
|
*/
|
|
114
|
-
declare const useInputValueTransform: ({
|
|
82
|
+
declare const useInputValueTransform: ({ type, transform, }: UseInputValueTransformOptions) => UseInputValueTransformReturn;
|
|
115
83
|
|
|
116
84
|
export { type InputValueTransform, type UseInputValueTransformOptions, type UseInputValueTransformReturn, useInputValueTransform };
|