@fuf-stack/uniform 1.6.4 → 1.7.0
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/Checkboxes/index.cjs +13 -11
- package/dist/Checkboxes/index.cjs.map +1 -1
- package/dist/Checkboxes/index.d.cts +3 -2
- package/dist/Checkboxes/index.d.ts +3 -2
- package/dist/Checkboxes/index.js +12 -10
- package/dist/{Checkboxes-CR0Uu2g9.d.ts → Checkboxes-CDjOYw76.d.cts} +3 -0
- package/dist/{Checkboxes-CR0Uu2g9.d.cts → Checkboxes-wWzFP2sn.d.ts} +3 -0
- package/dist/FieldArray/index.cjs +13 -11
- package/dist/FieldArray/index.cjs.map +1 -1
- package/dist/FieldArray/index.d.cts +2 -2
- package/dist/FieldArray/index.d.ts +2 -2
- package/dist/FieldArray/index.js +12 -10
- package/dist/{FieldArray-EP4otr2x.d.cts → FieldArray-Cql1zcch.d.cts} +1 -1
- package/dist/{FieldArray-EP4otr2x.d.ts → FieldArray-Cql1zcch.d.ts} +1 -1
- package/dist/Form/index.cjs +13 -11
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.d.cts +3 -3
- package/dist/Form/index.d.ts +3 -3
- package/dist/Form/index.js +12 -10
- package/dist/{Form-Cu0lWRDN.d.cts → Form-BZZJPLsi.d.cts} +1 -1
- package/dist/{Form-C_11i6PA.d.ts → Form-zsUjI2yq.d.ts} +1 -1
- package/dist/FormContext-9Firwt4k.d.cts +14 -0
- package/dist/FormContext-9Firwt4k.d.ts +14 -0
- package/dist/Input/index.cjs +13 -11
- package/dist/Input/index.cjs.map +1 -1
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +12 -10
- package/dist/{Input-CCIEnvIp.d.ts → Input-BcdS2xBM.d.ts} +2 -2
- package/dist/{Input-D7HT_8jf.d.cts → Input-DMVTcinm.d.cts} +2 -2
- package/dist/RadioBoxes/index.cjs +13 -11
- package/dist/RadioBoxes/index.cjs.map +1 -1
- package/dist/RadioBoxes/index.js +12 -10
- package/dist/RadioTabs/index.cjs +13 -11
- package/dist/RadioTabs/index.cjs.map +1 -1
- package/dist/RadioTabs/index.js +12 -10
- package/dist/Radios/index.cjs +13 -11
- package/dist/Radios/index.cjs.map +1 -1
- package/dist/Radios/index.js +12 -10
- package/dist/Select/index.cjs +13 -11
- package/dist/Select/index.cjs.map +1 -1
- package/dist/Select/index.js +12 -10
- package/dist/SubmitButton/index.cjs +13 -11
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.js +12 -10
- package/dist/Switch/index.cjs +13 -11
- package/dist/Switch/index.cjs.map +1 -1
- package/dist/Switch/index.js +12 -10
- package/dist/TextArea/index.cjs +13 -11
- package/dist/TextArea/index.cjs.map +1 -1
- package/dist/TextArea/index.js +12 -10
- package/dist/{chunk-7NZVPVK3.cjs → chunk-2E4Q6OHC.cjs} +5 -9
- package/dist/chunk-2E4Q6OHC.cjs.map +1 -0
- package/dist/{chunk-HANR2BDX.cjs → chunk-4CWB5XBW.cjs} +5 -5
- package/dist/{chunk-HANR2BDX.cjs.map → chunk-4CWB5XBW.cjs.map} +1 -1
- package/dist/chunk-4F45XA7Y.cjs +26 -0
- package/dist/chunk-4F45XA7Y.cjs.map +1 -0
- package/dist/{chunk-42NCLEX4.cjs → chunk-4L3JXJ62.cjs} +35 -104
- package/dist/chunk-4L3JXJ62.cjs.map +1 -0
- package/dist/{chunk-RI45RSNN.js → chunk-4TQ53WAY.js} +2 -2
- package/dist/{chunk-4WYC2RBE.cjs → chunk-56TQOKG7.cjs} +6 -3
- package/dist/chunk-56TQOKG7.cjs.map +1 -0
- package/dist/{chunk-4Z7LIJHZ.cjs → chunk-6F5EZ6QN.cjs} +3 -3
- package/dist/{chunk-4Z7LIJHZ.cjs.map → chunk-6F5EZ6QN.cjs.map} +1 -1
- package/dist/chunk-6LQ2O6SC.cjs +115 -0
- package/dist/chunk-6LQ2O6SC.cjs.map +1 -0
- package/dist/{chunk-JMFDNTVC.cjs → chunk-7KEUEGRC.cjs} +9 -2
- package/dist/chunk-7KEUEGRC.cjs.map +1 -0
- package/dist/{chunk-HBVHOUAR.js → chunk-BUJNCVUR.js} +3 -3
- package/dist/{chunk-7KLFK2IT.js → chunk-CNTOODUQ.js} +6 -3
- package/dist/chunk-CNTOODUQ.js.map +1 -0
- package/dist/{chunk-VGJEMY55.cjs → chunk-EB3RNELT.cjs} +12 -7
- package/dist/chunk-EB3RNELT.cjs.map +1 -0
- package/dist/{chunk-D3JYMGTB.js → chunk-EGFB5WEK.js} +47 -37
- package/dist/chunk-EGFB5WEK.js.map +1 -0
- package/dist/{chunk-AAGOHXSZ.js → chunk-EUO4VWRX.js} +2 -2
- package/dist/{chunk-D3EZXJQH.cjs → chunk-EUTTXFWA.cjs} +3 -3
- package/dist/{chunk-D3EZXJQH.cjs.map → chunk-EUTTXFWA.cjs.map} +1 -1
- package/dist/{chunk-QAQ3UP7W.cjs → chunk-FFGFPXNE.cjs} +3 -3
- package/dist/{chunk-QAQ3UP7W.cjs.map → chunk-FFGFPXNE.cjs.map} +1 -1
- package/dist/{chunk-FZQDAI7E.js → chunk-FND5Z5BW.js} +11 -8
- package/dist/chunk-FND5Z5BW.js.map +1 -0
- package/dist/{chunk-CK362NWK.js → chunk-GKP3ONKO.js} +9 -2
- package/dist/chunk-GKP3ONKO.js.map +1 -0
- package/dist/{chunk-MOVNWZX5.cjs → chunk-IFBKJ5UZ.cjs} +13 -10
- package/dist/chunk-IFBKJ5UZ.cjs.map +1 -0
- package/dist/{chunk-IK5IWKUC.js → chunk-K33E67GR.js} +6 -6
- package/dist/{chunk-UFL53ALT.js → chunk-KGN5JQGG.js} +11 -6
- package/dist/chunk-KGN5JQGG.js.map +1 -0
- package/dist/{chunk-46FKQWMF.js → chunk-KQQAESO7.js} +3 -3
- package/dist/chunk-KWJMKX5J.cjs +1 -0
- package/dist/{chunk-LTKRK3OS.cjs.map → chunk-KWJMKX5J.cjs.map} +1 -1
- package/dist/{chunk-NZ54JBSR.js → chunk-LKR6D3RL.js} +36 -105
- package/dist/chunk-LKR6D3RL.js.map +1 -0
- package/dist/{chunk-65UJEB4P.js → chunk-N24A7PIL.js} +2 -2
- package/dist/{chunk-BZ5OMN4Y.cjs → chunk-NTOYCWCJ.cjs} +12 -26
- package/dist/chunk-NTOYCWCJ.cjs.map +1 -0
- package/dist/{chunk-4ATOAQOF.cjs → chunk-OJGPW4Z6.cjs} +3 -3
- package/dist/{chunk-4ATOAQOF.cjs.map → chunk-OJGPW4Z6.cjs.map} +1 -1
- package/dist/{chunk-SOQ6GCN3.cjs → chunk-OQUTHTOK.cjs} +48 -38
- package/dist/chunk-OQUTHTOK.cjs.map +1 -0
- package/dist/chunk-PY4GCAFN.js +26 -0
- package/dist/chunk-PY4GCAFN.js.map +1 -0
- package/dist/{chunk-V3NNJJHY.cjs → chunk-S3H432Z2.cjs} +3 -3
- package/dist/{chunk-V3NNJJHY.cjs.map → chunk-S3H432Z2.cjs.map} +1 -1
- package/dist/{chunk-TB5WXGWX.js → chunk-SWPFSD3Y.js} +9 -27
- package/dist/chunk-SWPFSD3Y.js.map +1 -0
- package/dist/{chunk-HX2JJ2ZK.cjs → chunk-TJY5FK4B.cjs} +8 -8
- package/dist/{chunk-HX2JJ2ZK.cjs.map → chunk-TJY5FK4B.cjs.map} +1 -1
- package/dist/chunk-U45RW4FC.js +115 -0
- package/dist/chunk-U45RW4FC.js.map +1 -0
- package/dist/{chunk-NM66XFQH.js → chunk-UEOED4GU.js} +2 -2
- package/dist/{chunk-A2LFA4A7.cjs → chunk-UT6VUGFP.cjs} +6 -6
- package/dist/{chunk-A2LFA4A7.cjs.map → chunk-UT6VUGFP.cjs.map} +1 -1
- package/dist/chunk-V3GDAELU.js +1 -0
- package/dist/{chunk-I5RBXUIV.js → chunk-VUW522KH.js} +2 -2
- package/dist/{chunk-4RIJJ5AV.js → chunk-WHV55VFM.js} +4 -8
- package/dist/chunk-WHV55VFM.js.map +1 -0
- package/dist/{chunk-NUGEM725.js → chunk-WWGKXYZB.js} +2 -2
- package/dist/{chunk-PC3VCEGM.cjs → chunk-ZEJ45LLM.cjs} +3 -3
- package/dist/{chunk-PC3VCEGM.cjs.map → chunk-ZEJ45LLM.cjs.map} +1 -1
- package/dist/{chunk-HEGORLRF.cjs → chunk-ZFZK6EM2.cjs} +10 -28
- package/dist/chunk-ZFZK6EM2.cjs.map +1 -0
- package/dist/{chunk-MODD3TFE.js → chunk-ZJDU5EPE.js} +12 -26
- package/dist/chunk-ZJDU5EPE.js.map +1 -0
- package/dist/hooks/index.cjs +17 -12
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +2 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +17 -12
- package/dist/hooks/useClientValidation/index.cjs +4 -3
- package/dist/hooks/useClientValidation/index.cjs.map +1 -1
- package/dist/hooks/useClientValidation/index.js +3 -2
- package/dist/hooks/useController/index.cjs +3 -2
- package/dist/hooks/useController/index.cjs.map +1 -1
- package/dist/hooks/useController/index.d.cts +1 -0
- package/dist/hooks/useController/index.d.ts +1 -0
- package/dist/hooks/useController/index.js +2 -1
- package/dist/hooks/useFormContext/index.cjs +3 -2
- package/dist/hooks/useFormContext/index.cjs.map +1 -1
- package/dist/hooks/useFormContext/index.d.cts +5 -1
- package/dist/hooks/useFormContext/index.d.ts +5 -1
- package/dist/hooks/useFormContext/index.js +2 -1
- package/dist/hooks/useInputValueDebounce/index.cjs +2 -3
- package/dist/hooks/useInputValueDebounce/index.cjs.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.d.cts +17 -52
- package/dist/hooks/useInputValueDebounce/index.d.ts +17 -52
- package/dist/hooks/useInputValueDebounce/index.js +1 -2
- package/dist/hooks/useInputValueTransform/index.cjs +2 -2
- package/dist/hooks/useInputValueTransform/index.d.cts +31 -13
- package/dist/hooks/useInputValueTransform/index.d.ts +31 -13
- package/dist/hooks/useInputValueTransform/index.js +1 -1
- package/dist/hooks/useUniformField/index.cjs +7 -5
- package/dist/hooks/useUniformField/index.cjs.map +1 -1
- package/dist/hooks/useUniformField/index.d.cts +16 -5
- package/dist/hooks/useUniformField/index.d.ts +16 -5
- package/dist/hooks/useUniformField/index.js +6 -4
- package/dist/hooks/useUniformFieldArray/index.cjs +8 -6
- package/dist/hooks/useUniformFieldArray/index.cjs.map +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.cts +2 -2
- package/dist/hooks/useUniformFieldArray/index.d.ts +2 -2
- package/dist/hooks/useUniformFieldArray/index.js +7 -5
- package/dist/hooks/useWatchUserChange/index.cjs +11 -0
- package/dist/hooks/useWatchUserChange/index.cjs.map +1 -0
- package/dist/hooks/useWatchUserChange/index.d.cts +73 -0
- package/dist/hooks/useWatchUserChange/index.d.ts +73 -0
- package/dist/hooks/useWatchUserChange/index.js +11 -0
- package/dist/hooks/useWatchUserChange/index.js.map +1 -0
- package/dist/index.cjs +26 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +29 -24
- package/package.json +9 -4
- package/dist/FormContext-LRho0tno.d.cts +0 -8
- package/dist/FormContext-LRho0tno.d.ts +0 -8
- package/dist/chunk-35V726MB.js +0 -1
- package/dist/chunk-42NCLEX4.cjs.map +0 -1
- package/dist/chunk-4RIJJ5AV.js.map +0 -1
- package/dist/chunk-4WYC2RBE.cjs.map +0 -1
- package/dist/chunk-7KLFK2IT.js.map +0 -1
- package/dist/chunk-7NZVPVK3.cjs.map +0 -1
- package/dist/chunk-BZ5OMN4Y.cjs.map +0 -1
- package/dist/chunk-CK362NWK.js.map +0 -1
- package/dist/chunk-D3JYMGTB.js.map +0 -1
- package/dist/chunk-FZQDAI7E.js.map +0 -1
- package/dist/chunk-HEGORLRF.cjs.map +0 -1
- package/dist/chunk-JMFDNTVC.cjs.map +0 -1
- package/dist/chunk-LTKRK3OS.cjs +0 -1
- package/dist/chunk-MODD3TFE.js.map +0 -1
- package/dist/chunk-MOVNWZX5.cjs.map +0 -1
- package/dist/chunk-NZ54JBSR.js.map +0 -1
- package/dist/chunk-SOQ6GCN3.cjs.map +0 -1
- package/dist/chunk-TB5WXGWX.js.map +0 -1
- package/dist/chunk-UFL53ALT.js.map +0 -1
- package/dist/chunk-VGJEMY55.cjs.map +0 -1
- /package/dist/{chunk-RI45RSNN.js.map → chunk-4TQ53WAY.js.map} +0 -0
- /package/dist/{chunk-HBVHOUAR.js.map → chunk-BUJNCVUR.js.map} +0 -0
- /package/dist/{chunk-AAGOHXSZ.js.map → chunk-EUO4VWRX.js.map} +0 -0
- /package/dist/{chunk-IK5IWKUC.js.map → chunk-K33E67GR.js.map} +0 -0
- /package/dist/{chunk-46FKQWMF.js.map → chunk-KQQAESO7.js.map} +0 -0
- /package/dist/{chunk-65UJEB4P.js.map → chunk-N24A7PIL.js.map} +0 -0
- /package/dist/{chunk-NM66XFQH.js.map → chunk-UEOED4GU.js.map} +0 -0
- /package/dist/{chunk-35V726MB.js.map → chunk-V3GDAELU.js.map} +0 -0
- /package/dist/{chunk-I5RBXUIV.js.map → chunk-VUW522KH.js.map} +0 -0
- /package/dist/{chunk-NUGEM725.js.map → chunk-WWGKXYZB.js.map} +0 -0
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
interface InputValueTransform {
|
|
2
|
-
/** Transforms the form value to display value (e.g., 1000 → "$1,000") */
|
|
3
|
-
toDisplayValue: (value:
|
|
4
|
-
/** Transforms the display value to form value (e.g., "$1,000" → 1000) */
|
|
5
|
-
toFormValue: (value:
|
|
1
|
+
interface InputValueTransform<TDisplay = unknown> {
|
|
2
|
+
/** Transforms the form value to display value (e.g., 1000 → "$1,000" or 'a' → ['a']) */
|
|
3
|
+
toDisplayValue: (value: unknown) => TDisplay;
|
|
4
|
+
/** Transforms the display value to form value (e.g., "$1,000" → 1000 or ['a'] → 'a') */
|
|
5
|
+
toFormValue: (value: TDisplay) => unknown;
|
|
6
6
|
}
|
|
7
|
-
interface UseInputValueTransformOptions {
|
|
7
|
+
interface UseInputValueTransformOptions<TDisplay = unknown> {
|
|
8
8
|
/** Input type for special number handling */
|
|
9
9
|
type?: 'text' | 'number' | 'password';
|
|
10
10
|
/** Value transformation functions */
|
|
11
|
-
transform?: InputValueTransform
|
|
11
|
+
transform?: InputValueTransform<TDisplay>;
|
|
12
12
|
}
|
|
13
|
-
interface UseInputValueTransformReturn {
|
|
13
|
+
interface UseInputValueTransformReturn<TDisplay = unknown> {
|
|
14
14
|
/** Converts any form value to display value */
|
|
15
|
-
toDisplayValue: (formValue:
|
|
15
|
+
toDisplayValue: (formValue: unknown) => TDisplay;
|
|
16
16
|
/** Converts any display value to form value */
|
|
17
|
-
toFormValue: (displayValue:
|
|
17
|
+
toFormValue: (displayValue: TDisplay) => unknown;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Custom hook providing utility functions for value transformations between display and form values.
|
|
@@ -24,9 +24,11 @@ interface UseInputValueTransformReturn {
|
|
|
24
24
|
* - Number inputs with special handling
|
|
25
25
|
* - Date formatting (MM/DD/YYYY display vs ISO date stored)
|
|
26
26
|
* - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)
|
|
27
|
+
* - Array/Object transformations (single value ↔ array, nested structures)
|
|
27
28
|
*
|
|
28
29
|
* **Key Features:**
|
|
29
30
|
* - Pure conversion functions (no state)
|
|
31
|
+
* - Generic support for any data type (strings, numbers, arrays, objects)
|
|
30
32
|
* - Special number input handling (empty string preservation)
|
|
31
33
|
* - Bidirectional value transformations
|
|
32
34
|
* - Memoized functions for performance
|
|
@@ -38,8 +40,8 @@ interface UseInputValueTransformReturn {
|
|
|
38
40
|
* ```tsx
|
|
39
41
|
* // Currency formatting
|
|
40
42
|
* const currencyTransform = {
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
+
* toDisplayValue: (val) => val ? `$${Number(val).toLocaleString()}` : '',
|
|
44
|
+
* toFormValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0
|
|
43
45
|
* };
|
|
44
46
|
*
|
|
45
47
|
* const { toDisplayValue, toFormValue } = useInputValueTransform({
|
|
@@ -63,6 +65,22 @@ interface UseInputValueTransformReturn {
|
|
|
63
65
|
*
|
|
64
66
|
* @example
|
|
65
67
|
* ```tsx
|
|
68
|
+
* // Array to single value (for single checkbox)
|
|
69
|
+
* const singleValueTransform = {
|
|
70
|
+
* toDisplayValue: (val: string[]) => val?.[0] || '',
|
|
71
|
+
* toFormValue: (val: string) => val ? [val] : []
|
|
72
|
+
* };
|
|
73
|
+
*
|
|
74
|
+
* const { toDisplayValue, toFormValue } = useInputValueTransform({
|
|
75
|
+
* transform: singleValueTransform
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* const displayVal = toDisplayValue(['option1']); // "option1"
|
|
79
|
+
* const formVal = toFormValue("option2"); // ["option2"]
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
66
84
|
* // Integration with debouncing
|
|
67
85
|
* const MyInput = ({ field, transform }) => {
|
|
68
86
|
* const transform = useInputValueTransform({ transform });
|
|
@@ -79,6 +97,6 @@ interface UseInputValueTransformReturn {
|
|
|
79
97
|
* };
|
|
80
98
|
* ```
|
|
81
99
|
*/
|
|
82
|
-
declare const useInputValueTransform: ({ type, transform, }: UseInputValueTransformOptions) => UseInputValueTransformReturn
|
|
100
|
+
declare const useInputValueTransform: <TDisplay = unknown>({ type, transform, }: UseInputValueTransformOptions<TDisplay>) => UseInputValueTransformReturn<TDisplay>;
|
|
83
101
|
|
|
84
102
|
export { type InputValueTransform, type UseInputValueTransformOptions, type UseInputValueTransformReturn, useInputValueTransform };
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOQUTHTOKcjs = require('../../chunk-OQUTHTOK.cjs');
|
|
4
|
+
require('../../chunk-OE5BOGGX.cjs');
|
|
4
5
|
require('../../chunk-NHEZXA4H.cjs');
|
|
5
|
-
require('../../chunk-
|
|
6
|
+
require('../../chunk-7KEUEGRC.cjs');
|
|
6
7
|
require('../../chunk-PCTYJUY7.cjs');
|
|
7
|
-
require('../../chunk-
|
|
8
|
-
require('../../chunk-
|
|
8
|
+
require('../../chunk-56TQOKG7.cjs');
|
|
9
|
+
require('../../chunk-6LQ2O6SC.cjs');
|
|
10
|
+
require('../../chunk-4L3JXJ62.cjs');
|
|
9
11
|
require('../../chunk-Z353BLWI.cjs');
|
|
10
12
|
require('../../chunk-555JRYCS.cjs');
|
|
11
13
|
|
|
12
14
|
|
|
13
|
-
exports.useUniformField =
|
|
15
|
+
exports.useUniformField = _chunkOQUTHTOKcjs.useUniformField;
|
|
14
16
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformField/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,4DAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformField/index.cjs"}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformField/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,4DAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformField/index.cjs"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { FieldValues, Path, FieldError } from 'react-hook-form';
|
|
3
|
+
import { InputValueTransform } from '../useInputValueTransform/index.cjs';
|
|
3
4
|
import { useController } from '../useController/index.cjs';
|
|
4
5
|
import { useFormContext } from '../useFormContext/index.cjs';
|
|
5
6
|
import { useInput } from '@heroui/input';
|
|
6
7
|
import '@fuf-stack/veto';
|
|
7
|
-
import '../../FormContext-
|
|
8
|
+
import '../../FormContext-9Firwt4k.cjs';
|
|
8
9
|
|
|
9
|
-
interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues> {
|
|
10
|
+
interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues, TDisplay = unknown> {
|
|
10
11
|
/** Form field name */
|
|
11
12
|
name: Path<TFieldValues> & string;
|
|
12
13
|
/** Disable the field */
|
|
@@ -15,6 +16,10 @@ interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues>
|
|
|
15
16
|
testId?: string;
|
|
16
17
|
/** Optional label content; pass false to suppress label entirely */
|
|
17
18
|
label?: ReactNode | false;
|
|
19
|
+
/** Input type for special number handling */
|
|
20
|
+
type?: 'text' | 'number' | 'password';
|
|
21
|
+
/** Optional value transformation between form and display values */
|
|
22
|
+
transform?: InputValueTransform<TDisplay>;
|
|
18
23
|
}
|
|
19
24
|
interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues> {
|
|
20
25
|
/** react-hook-form control instance for advanced integrations */
|
|
@@ -29,7 +34,7 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
29
34
|
error: FieldError[] | undefined;
|
|
30
35
|
/** Pre-built errorMessage node to plug into components */
|
|
31
36
|
errorMessage: ReactNode | null;
|
|
32
|
-
/** RHF controller field with
|
|
37
|
+
/** RHF controller field with transformed value/onChange (use this for simple components) */
|
|
33
38
|
field: ReturnType<typeof useController<TFieldValues>>['field'];
|
|
34
39
|
/** Helper to spread standardized error message props to underlying components */
|
|
35
40
|
getErrorMessageProps: ReturnType<typeof useInput>['getErrorMessageProps'];
|
|
@@ -45,7 +50,7 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
45
50
|
label: ReactNode | null;
|
|
46
51
|
/** onBlur handler from controller */
|
|
47
52
|
onBlur: ReturnType<typeof useController<TFieldValues>>['field']['onBlur'];
|
|
48
|
-
/** onChange handler from controller (with
|
|
53
|
+
/** onChange handler from controller (with transform applied) */
|
|
49
54
|
onChange: ReturnType<typeof useController<TFieldValues>>['field']['onChange'];
|
|
50
55
|
/** Ref to forward to underlying control */
|
|
51
56
|
ref: ReturnType<typeof useController<TFieldValues>>['field']['ref'];
|
|
@@ -62,6 +67,12 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
62
67
|
* Provides:
|
|
63
68
|
* - Enhanced form context (validation-aware state, `testId`, value transforms)
|
|
64
69
|
* - Controller field with nullish conversion handling
|
|
70
|
+
* - Value transformation via `transform` prop:
|
|
71
|
+
* • Allows disentangled display and form values (e.g., string ↔ object, boolean ↔ array)
|
|
72
|
+
* • Automatically applies `toDisplayValue` to field value for components
|
|
73
|
+
* • Automatically applies `toFormValue` to display value when onChange is called
|
|
74
|
+
* • Works with `type` prop for automatic number/string conversion
|
|
75
|
+
* • Examples: storing objects while displaying strings, storing booleans as arrays, enriching values with metadata
|
|
65
76
|
* - Debounced `invalid` state with smart timing:
|
|
66
77
|
* • `true` (field becomes invalid): applies immediately so errors show right away
|
|
67
78
|
* • `false` (field becomes valid): delayed 200ms to allow smooth exit animations
|
|
@@ -78,6 +89,6 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
78
89
|
* - Presentation helpers: `getLabelProps`, `getErrorMessageProps`,
|
|
79
90
|
* `getHelperWrapperProps` for consistent wiring to underlying UI components
|
|
80
91
|
*/
|
|
81
|
-
declare function useUniformField<TFieldValues extends FieldValues = FieldValues>(params: UseUniformFieldParams<TFieldValues>): UseUniformFieldReturn<TFieldValues>;
|
|
92
|
+
declare function useUniformField<TFieldValues extends FieldValues = FieldValues, TDisplay = unknown>(params: UseUniformFieldParams<TFieldValues, TDisplay>): UseUniformFieldReturn<TFieldValues>;
|
|
82
93
|
|
|
83
94
|
export { type UseUniformFieldParams, type UseUniformFieldReturn, useUniformField };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { FieldValues, Path, FieldError } from 'react-hook-form';
|
|
3
|
+
import { InputValueTransform } from '../useInputValueTransform/index.js';
|
|
3
4
|
import { useController } from '../useController/index.js';
|
|
4
5
|
import { useFormContext } from '../useFormContext/index.js';
|
|
5
6
|
import { useInput } from '@heroui/input';
|
|
6
7
|
import '@fuf-stack/veto';
|
|
7
|
-
import '../../FormContext-
|
|
8
|
+
import '../../FormContext-9Firwt4k.js';
|
|
8
9
|
|
|
9
|
-
interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues> {
|
|
10
|
+
interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues, TDisplay = unknown> {
|
|
10
11
|
/** Form field name */
|
|
11
12
|
name: Path<TFieldValues> & string;
|
|
12
13
|
/** Disable the field */
|
|
@@ -15,6 +16,10 @@ interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues>
|
|
|
15
16
|
testId?: string;
|
|
16
17
|
/** Optional label content; pass false to suppress label entirely */
|
|
17
18
|
label?: ReactNode | false;
|
|
19
|
+
/** Input type for special number handling */
|
|
20
|
+
type?: 'text' | 'number' | 'password';
|
|
21
|
+
/** Optional value transformation between form and display values */
|
|
22
|
+
transform?: InputValueTransform<TDisplay>;
|
|
18
23
|
}
|
|
19
24
|
interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues> {
|
|
20
25
|
/** react-hook-form control instance for advanced integrations */
|
|
@@ -29,7 +34,7 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
29
34
|
error: FieldError[] | undefined;
|
|
30
35
|
/** Pre-built errorMessage node to plug into components */
|
|
31
36
|
errorMessage: ReactNode | null;
|
|
32
|
-
/** RHF controller field with
|
|
37
|
+
/** RHF controller field with transformed value/onChange (use this for simple components) */
|
|
33
38
|
field: ReturnType<typeof useController<TFieldValues>>['field'];
|
|
34
39
|
/** Helper to spread standardized error message props to underlying components */
|
|
35
40
|
getErrorMessageProps: ReturnType<typeof useInput>['getErrorMessageProps'];
|
|
@@ -45,7 +50,7 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
45
50
|
label: ReactNode | null;
|
|
46
51
|
/** onBlur handler from controller */
|
|
47
52
|
onBlur: ReturnType<typeof useController<TFieldValues>>['field']['onBlur'];
|
|
48
|
-
/** onChange handler from controller (with
|
|
53
|
+
/** onChange handler from controller (with transform applied) */
|
|
49
54
|
onChange: ReturnType<typeof useController<TFieldValues>>['field']['onChange'];
|
|
50
55
|
/** Ref to forward to underlying control */
|
|
51
56
|
ref: ReturnType<typeof useController<TFieldValues>>['field']['ref'];
|
|
@@ -62,6 +67,12 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
62
67
|
* Provides:
|
|
63
68
|
* - Enhanced form context (validation-aware state, `testId`, value transforms)
|
|
64
69
|
* - Controller field with nullish conversion handling
|
|
70
|
+
* - Value transformation via `transform` prop:
|
|
71
|
+
* • Allows disentangled display and form values (e.g., string ↔ object, boolean ↔ array)
|
|
72
|
+
* • Automatically applies `toDisplayValue` to field value for components
|
|
73
|
+
* • Automatically applies `toFormValue` to display value when onChange is called
|
|
74
|
+
* • Works with `type` prop for automatic number/string conversion
|
|
75
|
+
* • Examples: storing objects while displaying strings, storing booleans as arrays, enriching values with metadata
|
|
65
76
|
* - Debounced `invalid` state with smart timing:
|
|
66
77
|
* • `true` (field becomes invalid): applies immediately so errors show right away
|
|
67
78
|
* • `false` (field becomes valid): delayed 200ms to allow smooth exit animations
|
|
@@ -78,6 +89,6 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
78
89
|
* - Presentation helpers: `getLabelProps`, `getErrorMessageProps`,
|
|
79
90
|
* `getHelperWrapperProps` for consistent wiring to underlying UI components
|
|
80
91
|
*/
|
|
81
|
-
declare function useUniformField<TFieldValues extends FieldValues = FieldValues>(params: UseUniformFieldParams<TFieldValues>): UseUniformFieldReturn<TFieldValues>;
|
|
92
|
+
declare function useUniformField<TFieldValues extends FieldValues = FieldValues, TDisplay = unknown>(params: UseUniformFieldParams<TFieldValues, TDisplay>): UseUniformFieldReturn<TFieldValues>;
|
|
82
93
|
|
|
83
94
|
export { type UseUniformFieldParams, type UseUniformFieldReturn, useUniformField };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useUniformField
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-EGFB5WEK.js";
|
|
4
|
+
import "../../chunk-NTDKZW4E.js";
|
|
4
5
|
import "../../chunk-ELYGQTXB.js";
|
|
5
|
-
import "../../chunk-
|
|
6
|
+
import "../../chunk-GKP3ONKO.js";
|
|
6
7
|
import "../../chunk-AHJJIANM.js";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-CNTOODUQ.js";
|
|
9
|
+
import "../../chunk-U45RW4FC.js";
|
|
10
|
+
import "../../chunk-LKR6D3RL.js";
|
|
9
11
|
import "../../chunk-76KOVUDN.js";
|
|
10
12
|
import "../../chunk-K2V4ULA2.js";
|
|
11
13
|
export {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var _chunkIFBKJ5UZcjs = require('../../chunk-IFBKJ5UZ.cjs');
|
|
4
|
+
require('../../chunk-OQUTHTOK.cjs');
|
|
5
|
+
require('../../chunk-OE5BOGGX.cjs');
|
|
5
6
|
require('../../chunk-NHEZXA4H.cjs');
|
|
6
|
-
require('../../chunk-
|
|
7
|
+
require('../../chunk-7KEUEGRC.cjs');
|
|
7
8
|
require('../../chunk-PCTYJUY7.cjs');
|
|
8
|
-
require('../../chunk-
|
|
9
|
-
require('../../chunk-
|
|
9
|
+
require('../../chunk-56TQOKG7.cjs');
|
|
10
|
+
require('../../chunk-6LQ2O6SC.cjs');
|
|
11
|
+
require('../../chunk-4L3JXJ62.cjs');
|
|
10
12
|
require('../../chunk-Z353BLWI.cjs');
|
|
11
13
|
require('../../chunk-555JRYCS.cjs');
|
|
12
14
|
|
|
13
15
|
|
|
14
|
-
exports.useUniformFieldArray =
|
|
16
|
+
exports.useUniformFieldArray = _chunkIFBKJ5UZcjs.useUniformFieldArray;
|
|
15
17
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformFieldArray/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,sEAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformFieldArray/index.cjs"}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformFieldArray/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,sEAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useUniformFieldArray/index.cjs"}
|
|
@@ -5,7 +5,7 @@ import { FieldValues, ArrayPath } from 'react-hook-form';
|
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import { useFormContext } from '../useFormContext/index.cjs';
|
|
7
7
|
import '@fuf-stack/veto';
|
|
8
|
-
import '../../FormContext-
|
|
8
|
+
import '../../FormContext-9Firwt4k.cjs';
|
|
9
9
|
|
|
10
10
|
interface UseUniformFieldArrayProps<TFieldValues extends FieldValues = FieldValues> {
|
|
11
11
|
/** Field name for the array */
|
|
@@ -43,7 +43,7 @@ declare const useUniformFieldArray: <TFieldValues extends FieldValues = FieldVal
|
|
|
43
43
|
error: react_hook_form.FieldError[] | undefined;
|
|
44
44
|
errorMessage: ReactNode | null;
|
|
45
45
|
field: Omit<react_hook_form.ControllerRenderProps<TFieldValues>, "value" | "onChange"> & {
|
|
46
|
-
onChange: (...
|
|
46
|
+
onChange: (...event: any[]) => void;
|
|
47
47
|
value: string;
|
|
48
48
|
};
|
|
49
49
|
getErrorMessageProps: ReturnType<typeof _heroui_input.useInput>["getErrorMessageProps"];
|
|
@@ -5,7 +5,7 @@ import { FieldValues, ArrayPath } from 'react-hook-form';
|
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import { useFormContext } from '../useFormContext/index.js';
|
|
7
7
|
import '@fuf-stack/veto';
|
|
8
|
-
import '../../FormContext-
|
|
8
|
+
import '../../FormContext-9Firwt4k.js';
|
|
9
9
|
|
|
10
10
|
interface UseUniformFieldArrayProps<TFieldValues extends FieldValues = FieldValues> {
|
|
11
11
|
/** Field name for the array */
|
|
@@ -43,7 +43,7 @@ declare const useUniformFieldArray: <TFieldValues extends FieldValues = FieldVal
|
|
|
43
43
|
error: react_hook_form.FieldError[] | undefined;
|
|
44
44
|
errorMessage: ReactNode | null;
|
|
45
45
|
field: Omit<react_hook_form.ControllerRenderProps<TFieldValues>, "value" | "onChange"> & {
|
|
46
|
-
onChange: (...
|
|
46
|
+
onChange: (...event: any[]) => void;
|
|
47
47
|
value: string;
|
|
48
48
|
};
|
|
49
49
|
getErrorMessageProps: ReturnType<typeof _heroui_input.useInput>["getErrorMessageProps"];
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useUniformFieldArray
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-FND5Z5BW.js";
|
|
4
|
+
import "../../chunk-EGFB5WEK.js";
|
|
5
|
+
import "../../chunk-NTDKZW4E.js";
|
|
5
6
|
import "../../chunk-ELYGQTXB.js";
|
|
6
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-GKP3ONKO.js";
|
|
7
8
|
import "../../chunk-AHJJIANM.js";
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
9
|
+
import "../../chunk-CNTOODUQ.js";
|
|
10
|
+
import "../../chunk-U45RW4FC.js";
|
|
11
|
+
import "../../chunk-LKR6D3RL.js";
|
|
10
12
|
import "../../chunk-76KOVUDN.js";
|
|
11
13
|
import "../../chunk-K2V4ULA2.js";
|
|
12
14
|
export {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk4F45XA7Ycjs = require('../../chunk-4F45XA7Y.cjs');
|
|
4
|
+
require('../../chunk-6LQ2O6SC.cjs');
|
|
5
|
+
require('../../chunk-4L3JXJ62.cjs');
|
|
6
|
+
require('../../chunk-Z353BLWI.cjs');
|
|
7
|
+
require('../../chunk-555JRYCS.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.useWatchUserChange = _chunk4F45XA7Ycjs.useWatchUserChange;
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useWatchUserChange/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,kEAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/hooks/useWatchUserChange/index.cjs"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FieldValues, Path, UseFormSetValue, UseFormResetField, UseFormReset } from 'react-hook-form';
|
|
2
|
+
|
|
3
|
+
interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {
|
|
4
|
+
/** Field name to watch for user changes */
|
|
5
|
+
watch: Path<TFieldValues>;
|
|
6
|
+
/**
|
|
7
|
+
* Callback when watched field is changed by user input.
|
|
8
|
+
* Receives the new value and form helpers (setValue, resetField, reset).
|
|
9
|
+
*/
|
|
10
|
+
onChange: (value: unknown, helpers: {
|
|
11
|
+
setValue: UseFormSetValue<TFieldValues>;
|
|
12
|
+
resetField: UseFormResetField<TFieldValues>;
|
|
13
|
+
reset: UseFormReset<TFieldValues>;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hook that watches for user changes on a specific form field.
|
|
18
|
+
*
|
|
19
|
+
* Only triggers on manual user input (typing, clicking, selecting),
|
|
20
|
+
* NOT on programmatic changes like form.reset() or form.setValue().
|
|
21
|
+
*
|
|
22
|
+
* This hook subscribes to field changes at the source (useController),
|
|
23
|
+
* ensuring immediate and accurate detection of user interactions.
|
|
24
|
+
*
|
|
25
|
+
* Use cases:
|
|
26
|
+
* - Reset dependent fields when parent field changes
|
|
27
|
+
* - Set mode-specific default values when a toggle changes
|
|
28
|
+
* - Clear form sections based on user selections
|
|
29
|
+
* - Trigger side effects only on user interaction
|
|
30
|
+
*
|
|
31
|
+
* Note: To watch multiple fields, call this hook multiple times.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // Reset city and address when user changes country
|
|
36
|
+
* useWatchUserChange({
|
|
37
|
+
* watch: 'country',
|
|
38
|
+
* onChange: (value, { resetField }) => {
|
|
39
|
+
* resetField('city');
|
|
40
|
+
* resetField('address');
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Set defaults when user changes payment method
|
|
45
|
+
* useWatchUserChange({
|
|
46
|
+
* watch: 'paymentMethod',
|
|
47
|
+
* onChange: (value, { setValue }) => {
|
|
48
|
+
* if (value === 'credit') {
|
|
49
|
+
* setValue('installments', 3);
|
|
50
|
+
* } else {
|
|
51
|
+
* setValue('installments', 1);
|
|
52
|
+
* }
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Watch multiple fields by calling the hook multiple times
|
|
57
|
+
* useWatchUserChange({
|
|
58
|
+
* watch: 'category',
|
|
59
|
+
* onChange: (value, { resetField }) => {
|
|
60
|
+
* resetField('productId');
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
* useWatchUserChange({
|
|
64
|
+
* watch: 'brand',
|
|
65
|
+
* onChange: (value, { resetField }) => {
|
|
66
|
+
* resetField('productId');
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare const useWatchUserChange: <TFieldValues extends FieldValues = FieldValues>({ watch: watchField, onChange, }: UseWatchUserChangeOptions<TFieldValues>) => void;
|
|
72
|
+
|
|
73
|
+
export { type UseWatchUserChangeOptions, useWatchUserChange };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FieldValues, Path, UseFormSetValue, UseFormResetField, UseFormReset } from 'react-hook-form';
|
|
2
|
+
|
|
3
|
+
interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {
|
|
4
|
+
/** Field name to watch for user changes */
|
|
5
|
+
watch: Path<TFieldValues>;
|
|
6
|
+
/**
|
|
7
|
+
* Callback when watched field is changed by user input.
|
|
8
|
+
* Receives the new value and form helpers (setValue, resetField, reset).
|
|
9
|
+
*/
|
|
10
|
+
onChange: (value: unknown, helpers: {
|
|
11
|
+
setValue: UseFormSetValue<TFieldValues>;
|
|
12
|
+
resetField: UseFormResetField<TFieldValues>;
|
|
13
|
+
reset: UseFormReset<TFieldValues>;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hook that watches for user changes on a specific form field.
|
|
18
|
+
*
|
|
19
|
+
* Only triggers on manual user input (typing, clicking, selecting),
|
|
20
|
+
* NOT on programmatic changes like form.reset() or form.setValue().
|
|
21
|
+
*
|
|
22
|
+
* This hook subscribes to field changes at the source (useController),
|
|
23
|
+
* ensuring immediate and accurate detection of user interactions.
|
|
24
|
+
*
|
|
25
|
+
* Use cases:
|
|
26
|
+
* - Reset dependent fields when parent field changes
|
|
27
|
+
* - Set mode-specific default values when a toggle changes
|
|
28
|
+
* - Clear form sections based on user selections
|
|
29
|
+
* - Trigger side effects only on user interaction
|
|
30
|
+
*
|
|
31
|
+
* Note: To watch multiple fields, call this hook multiple times.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // Reset city and address when user changes country
|
|
36
|
+
* useWatchUserChange({
|
|
37
|
+
* watch: 'country',
|
|
38
|
+
* onChange: (value, { resetField }) => {
|
|
39
|
+
* resetField('city');
|
|
40
|
+
* resetField('address');
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Set defaults when user changes payment method
|
|
45
|
+
* useWatchUserChange({
|
|
46
|
+
* watch: 'paymentMethod',
|
|
47
|
+
* onChange: (value, { setValue }) => {
|
|
48
|
+
* if (value === 'credit') {
|
|
49
|
+
* setValue('installments', 3);
|
|
50
|
+
* } else {
|
|
51
|
+
* setValue('installments', 1);
|
|
52
|
+
* }
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Watch multiple fields by calling the hook multiple times
|
|
57
|
+
* useWatchUserChange({
|
|
58
|
+
* watch: 'category',
|
|
59
|
+
* onChange: (value, { resetField }) => {
|
|
60
|
+
* resetField('productId');
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
* useWatchUserChange({
|
|
64
|
+
* watch: 'brand',
|
|
65
|
+
* onChange: (value, { resetField }) => {
|
|
66
|
+
* resetField('productId');
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare const useWatchUserChange: <TFieldValues extends FieldValues = FieldValues>({ watch: watchField, onChange, }: UseWatchUserChangeOptions<TFieldValues>) => void;
|
|
72
|
+
|
|
73
|
+
export { type UseWatchUserChangeOptions, useWatchUserChange };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useWatchUserChange
|
|
3
|
+
} from "../../chunk-PY4GCAFN.js";
|
|
4
|
+
import "../../chunk-U45RW4FC.js";
|
|
5
|
+
import "../../chunk-LKR6D3RL.js";
|
|
6
|
+
import "../../chunk-76KOVUDN.js";
|
|
7
|
+
import "../../chunk-K2V4ULA2.js";
|
|
8
|
+
export {
|
|
9
|
+
useWatchUserChange
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|