@fuf-stack/uniform 1.16.1 → 1.17.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.d.cts +1 -1
- package/dist/Checkboxes/index.d.ts +1 -1
- package/dist/FieldArray/index.d.cts +1 -1
- package/dist/FieldArray/index.d.ts +1 -1
- package/dist/FieldCard/index.cjs +1 -1
- package/dist/FieldCard/index.d.cts +1 -1
- package/dist/FieldCard/index.d.ts +1 -1
- package/dist/FieldCard/index.js +1 -1
- package/dist/{FieldCard-BMmp6vcn.cjs → FieldCard-38ZBBWyE.cjs} +37 -6
- package/dist/FieldCard-38ZBBWyE.cjs.map +1 -0
- package/dist/{FieldCard-DAtdvKrE.js → FieldCard-7XiCb6jZ.js} +37 -6
- package/dist/FieldCard-7XiCb6jZ.js.map +1 -0
- package/dist/Form/index.d.cts +1 -1
- package/dist/Form/index.d.ts +1 -1
- package/dist/Grid/index.d.cts +1 -1
- package/dist/Grid/index.d.ts +1 -1
- package/dist/Input/index.d.cts +1 -1
- package/dist/Input/index.d.ts +1 -1
- package/dist/RadioBoxes/index.d.cts +1 -1
- package/dist/RadioBoxes/index.d.ts +1 -1
- package/dist/RadioTabs/index.d.cts +1 -1
- package/dist/RadioTabs/index.d.ts +1 -1
- package/dist/Radios/index.d.cts +1 -1
- package/dist/Radios/index.d.ts +1 -1
- package/dist/Select/index.d.cts +1 -1
- package/dist/Select/index.d.ts +1 -1
- package/dist/Slider/index.d.cts +1 -1
- package/dist/Slider/index.d.ts +1 -1
- package/dist/SubmitButton/index.d.cts +1 -1
- package/dist/SubmitButton/index.d.ts +1 -1
- package/dist/Switch/index.d.cts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/SwitchBox/index.d.cts +1 -1
- package/dist/SwitchBox/index.d.ts +1 -1
- package/dist/TextArea/index.d.cts +1 -1
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/helpers/index.d.cts +186 -2
- package/dist/helpers/index.d.cts.map +1 -0
- package/dist/helpers/index.d.ts +186 -2
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/hooks/useClientValidation/index.d.cts +1 -1
- package/dist/hooks/useClientValidation/index.d.ts +1 -1
- package/dist/hooks/useController/index.d.cts +1 -1
- package/dist/hooks/useController/index.d.ts +2 -1
- package/dist/hooks/useFormContext/index.d.cts +1 -1
- package/dist/hooks/useUniformField/index.d.cts +1 -1
- package/dist/hooks/useUniformField/index.d.ts +2 -2
- package/dist/hooks/useUniformFieldArray/index.d.cts +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.ts +3 -23
- package/dist/hooks/useWatchUserChange/index.d.cts +1 -1
- package/dist/hooks/useWatchUserChange/index.d.ts +1 -1
- package/dist/{index-dhcztpfB.d.cts → index-796vjEop.d.ts} +34 -34
- package/dist/index-796vjEop.d.ts.map +1 -0
- package/dist/{index-DJyRJr0I.d.ts → index-B62CWrcm.d.ts} +21 -21
- package/dist/index-B62CWrcm.d.ts.map +1 -0
- package/dist/{index-Nrdyx_72.d.cts → index-BD9y--o2.d.cts} +6 -6
- package/dist/{index-Nrdyx_72.d.cts.map → index-BD9y--o2.d.cts.map} +1 -1
- package/dist/{index-ByDAUZR8.d.cts → index-BFLKkqA3.d.ts} +3 -3
- package/dist/{index-DzGaqagC.d.ts.map → index-BFLKkqA3.d.ts.map} +1 -1
- package/dist/{index-uLhUKJjx.d.cts → index-BV_YDI6g.d.ts} +6 -6
- package/dist/{index-C-t8ET2t.d.ts.map → index-BV_YDI6g.d.ts.map} +1 -1
- package/dist/{index-DzGaqagC.d.ts → index-BW9EUWZE.d.cts} +3 -3
- package/dist/{index-ByDAUZR8.d.cts.map → index-BW9EUWZE.d.cts.map} +1 -1
- package/dist/{index-DmMenZfj.d.ts → index-B_1td56I.d.ts} +6 -6
- package/dist/{index-DmMenZfj.d.ts.map → index-B_1td56I.d.ts.map} +1 -1
- package/dist/{index-BXm2Nvuc.d.ts → index-BgXr1v45.d.cts} +34 -34
- package/dist/{index-dhcztpfB.d.cts.map → index-BgXr1v45.d.cts.map} +1 -1
- package/dist/{index-D4jPNNjM.d.ts → index-Bo79xzb4.d.cts} +5 -5
- package/dist/{index-CMQe-K8d.d.cts.map → index-Bo79xzb4.d.cts.map} +1 -1
- package/dist/{index-PdZaOKs9.d.cts → index-C3CvgmJw.d.ts} +4 -4
- package/dist/{index-CuACo6jI.d.ts.map → index-C3CvgmJw.d.ts.map} +1 -1
- package/dist/{index-CEB_3pH3.d.ts → index-C4-1V8jn.d.ts} +3 -3
- package/dist/{index-CEB_3pH3.d.ts.map → index-C4-1V8jn.d.ts.map} +1 -1
- package/dist/{index-BPupl-39.d.ts → index-CB00FCyi.d.ts} +21 -21
- package/dist/index-CB00FCyi.d.ts.map +1 -0
- package/dist/index-CFBmva_r.d.ts +1 -0
- package/dist/index-COwP53Gx.d.ts +278 -0
- package/dist/{index-D_VcH_gn.d.ts.map → index-COwP53Gx.d.ts.map} +1 -1
- package/dist/{index-C-t8ET2t.d.ts → index-CUy2EDqc.d.cts} +6 -6
- package/dist/{index-uLhUKJjx.d.cts.map → index-CUy2EDqc.d.cts.map} +1 -1
- package/dist/{index-ChtlWBjc.d.cts → index-CbAh0Kfo.d.cts} +3 -3
- package/dist/{index-ChtlWBjc.d.cts.map → index-CbAh0Kfo.d.cts.map} +1 -1
- package/dist/{index-WKgD5_vg.d.ts → index-Cj-PU3Ck.d.ts} +35 -35
- package/dist/{index-WKgD5_vg.d.ts.map → index-Cj-PU3Ck.d.ts.map} +1 -1
- package/dist/{index-CuACo6jI.d.ts → index-Cj5CLBt2.d.cts} +4 -4
- package/dist/{index-PdZaOKs9.d.cts.map → index-Cj5CLBt2.d.cts.map} +1 -1
- package/dist/{index-5SxIjw6Y.d.cts → index-CrxSEKKb.d.cts} +48 -48
- package/dist/index-CrxSEKKb.d.cts.map +1 -0
- package/dist/{index-BbWEFpRz.d.cts → index-D3RMbKbP.d.cts} +36 -36
- package/dist/{index-BbWEFpRz.d.cts.map → index-D3RMbKbP.d.cts.map} +1 -1
- package/dist/{index-BYag2YM-.d.cts → index-DAeb_8Q4.d.cts} +21 -21
- package/dist/{index-BYag2YM-.d.cts.map → index-DAeb_8Q4.d.cts.map} +1 -1
- package/dist/{index-BlK4-QN0.d.cts → index-DEJghucW.d.cts} +3 -3
- package/dist/{index-BlK4-QN0.d.cts.map → index-DEJghucW.d.cts.map} +1 -1
- package/dist/{index-CYfagyef.d.ts → index-DJbdReTK.d.ts} +3 -3
- package/dist/{index-CYfagyef.d.ts.map → index-DJbdReTK.d.ts.map} +1 -1
- package/dist/{index-C8e2kOHz.d.cts → index-DTURD6sl.d.cts} +6 -6
- package/dist/index-DTURD6sl.d.cts.map +1 -0
- package/dist/{index-B5oUKlIo.d.ts → index-DebErIUS.d.ts} +48 -48
- package/dist/index-DebErIUS.d.ts.map +1 -0
- package/dist/index-DfGCI-K_.d.cts +278 -0
- package/dist/index-DfGCI-K_.d.cts.map +1 -0
- package/dist/{index-CGnr_e53.d.ts → index-DjDR6FpI.d.ts} +36 -36
- package/dist/index-DjDR6FpI.d.ts.map +1 -0
- package/dist/{index-Db46CiKm.d.cts → index-DsyY9X04.d.cts} +3 -3
- package/dist/{index-Db46CiKm.d.cts.map → index-DsyY9X04.d.cts.map} +1 -1
- package/dist/{index-CK4iUXtY.d.cts → index-DxfiwbJb.d.cts} +6 -6
- package/dist/index-DxfiwbJb.d.cts.map +1 -0
- package/dist/{index-C6YO7fVN.d.ts → index-Dy0m4FQj.d.ts} +6 -6
- package/dist/index-Dy0m4FQj.d.ts.map +1 -0
- package/dist/{index-D4S6YQwi.d.cts → index-Y8XsRdxS.d.cts} +19 -19
- package/dist/{index-D4S6YQwi.d.cts.map → index-Y8XsRdxS.d.cts.map} +1 -1
- package/dist/{index-CMQe-K8d.d.cts → index-aHcGnXHf.d.ts} +4 -4
- package/dist/{index-D4jPNNjM.d.ts.map → index-aHcGnXHf.d.ts.map} +1 -1
- package/dist/{index-Ct6a8Dxz.d.ts → index-gWYaaO6O.d.ts} +4 -4
- package/dist/index-gWYaaO6O.d.ts.map +1 -0
- package/dist/index-lQ_hGQ08.d.cts +1 -0
- package/dist/{index-BtRhfPlX.d.cts → index-nVYabHcT.d.cts} +35 -35
- package/dist/{index-BtRhfPlX.d.cts.map → index-nVYabHcT.d.cts.map} +1 -1
- package/dist/{index-BL0DnIzh.d.ts → index-pE9osud2.d.ts} +3 -3
- package/dist/{index-BL0DnIzh.d.ts.map → index-pE9osud2.d.ts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +24 -24
- package/dist/index.d.ts +24 -23
- package/dist/index.js +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.d.cts +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.d.ts +1 -1
- package/dist/partials/FieldValidationError/index.d.cts +1 -1
- package/dist/partials/FieldValidationError/index.d.ts +1 -1
- package/dist/{useClientValidation-CeHOxxj1.d.ts → useClientValidation-Bg0q3Axc.d.ts} +3 -3
- package/dist/{useClientValidation-CeHOxxj1.d.ts.map → useClientValidation-Bg0q3Axc.d.ts.map} +1 -1
- package/dist/{useClientValidation-DG1xPiN5.d.cts → useClientValidation-BvPDQmf6.d.cts} +3 -3
- package/dist/{useClientValidation-DG1xPiN5.d.cts.map → useClientValidation-BvPDQmf6.d.cts.map} +1 -1
- package/dist/{useController-Co8wbo-Y.d.ts → useController-BJ2SBdky.d.ts} +1 -1
- package/dist/{useController-Co8wbo-Y.d.ts.map → useController-BJ2SBdky.d.ts.map} +1 -1
- package/dist/{useController-B-DhUPpA.d.cts → useController-C6Pg9T_3.d.cts} +1 -1
- package/dist/{useController-B-DhUPpA.d.cts.map → useController-C6Pg9T_3.d.cts.map} +1 -1
- package/dist/{useFormContext-B083Y-kw.d.cts → useFormContext-n3WYgGkW.d.cts} +17 -17
- package/dist/{useFormContext-B083Y-kw.d.cts.map → useFormContext-n3WYgGkW.d.cts.map} +1 -1
- package/dist/{useUniformField-B-hszxep.d.ts → useUniformField-CXSaAVTt.d.ts} +2 -2
- package/dist/{useUniformField-B-hszxep.d.ts.map → useUniformField-CXSaAVTt.d.ts.map} +1 -1
- package/dist/{useUniformField-BlqMUaQk.d.cts → useUniformField-ETnay_UI.d.cts} +3 -3
- package/dist/{useUniformField-BlqMUaQk.d.cts.map → useUniformField-ETnay_UI.d.cts.map} +1 -1
- package/dist/{useUniformFieldArray-BMMpIjre.d.cts → useUniformFieldArray-4pUdrWYT.d.cts} +14 -14
- package/dist/{useUniformFieldArray-BMMpIjre.d.cts.map → useUniformFieldArray-4pUdrWYT.d.cts.map} +1 -1
- package/dist/{useUniformFieldArray-KOP2kbMC.d.ts → useUniformFieldArray-COtgcAnp.d.ts} +3 -3
- package/dist/{useUniformFieldArray-KOP2kbMC.d.ts.map → useUniformFieldArray-COtgcAnp.d.ts.map} +1 -1
- package/dist/{useWatchUserChange-JMU-vN92.d.ts → useWatchUserChange-DX6gUHvM.d.ts} +1 -1
- package/dist/{useWatchUserChange-JMU-vN92.d.ts.map → useWatchUserChange-DX6gUHvM.d.ts.map} +1 -1
- package/dist/{useWatchUserChange-DahNCPDG.d.cts → useWatchUserChange-cI5-j6M4.d.cts} +1 -1
- package/dist/{useWatchUserChange-DahNCPDG.d.cts.map → useWatchUserChange-cI5-j6M4.d.cts.map} +1 -1
- package/package.json +2 -2
- package/dist/FieldCard-BMmp6vcn.cjs.map +0 -1
- package/dist/FieldCard-DAtdvKrE.js.map +0 -1
- package/dist/index-5SxIjw6Y.d.cts.map +0 -1
- package/dist/index-B5oUKlIo.d.ts.map +0 -1
- package/dist/index-BPjrrFuM.d.ts +0 -186
- package/dist/index-BPjrrFuM.d.ts.map +0 -1
- package/dist/index-BPupl-39.d.ts.map +0 -1
- package/dist/index-BTr_gid3.d.cts +0 -186
- package/dist/index-BTr_gid3.d.cts.map +0 -1
- package/dist/index-BXm2Nvuc.d.ts.map +0 -1
- package/dist/index-C6YO7fVN.d.ts.map +0 -1
- package/dist/index-C8e2kOHz.d.cts.map +0 -1
- package/dist/index-CGnr_e53.d.ts.map +0 -1
- package/dist/index-CK4iUXtY.d.cts.map +0 -1
- package/dist/index-Ct6a8Dxz.d.ts.map +0 -1
- package/dist/index-DJyRJr0I.d.ts.map +0 -1
- package/dist/index-D_VcH_gn.d.ts +0 -278
- package/dist/index-Dbn5MHgv.d.cts +0 -278
- package/dist/index-Dbn5MHgv.d.cts.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as Checkboxes, r as CheckboxesProps, t as CheckboxOption } from "../index-
|
|
1
|
+
import { n as Checkboxes, r as CheckboxesProps, t as CheckboxOption } from "../index-DTURD6sl.cjs";
|
|
2
2
|
export { CheckboxOption, Checkboxes, Checkboxes as default, CheckboxesProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as Checkboxes, r as CheckboxesProps, t as CheckboxOption } from "../index-
|
|
1
|
+
import { n as Checkboxes, r as CheckboxesProps, t as CheckboxOption } from "../index-Dy0m4FQj.js";
|
|
2
2
|
export { CheckboxOption, Checkboxes, Checkboxes as default, CheckboxesProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as FieldArrayProps, n as FieldArrayChildrenRenderFn, r as FieldArrayFeatures, t as FieldArray } from "../index-
|
|
1
|
+
import { i as FieldArrayProps, n as FieldArrayChildrenRenderFn, r as FieldArrayFeatures, t as FieldArray } from "../index-CUy2EDqc.cjs";
|
|
2
2
|
export { FieldArray, FieldArray as default, FieldArrayChildrenRenderFn, FieldArrayFeatures, FieldArrayProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as FieldArrayProps, n as FieldArrayChildrenRenderFn, r as FieldArrayFeatures, t as FieldArray } from "../index-
|
|
1
|
+
import { i as FieldArrayProps, n as FieldArrayChildrenRenderFn, r as FieldArrayFeatures, t as FieldArray } from "../index-BV_YDI6g.js";
|
|
2
2
|
export { FieldArray, FieldArray as default, FieldArrayChildrenRenderFn, FieldArrayFeatures, FieldArrayProps };
|
package/dist/FieldCard/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FieldCardProps, r as fieldCardVariants, t as FieldCard } from "../index-
|
|
1
|
+
import { n as FieldCardProps, r as fieldCardVariants, t as FieldCard } from "../index-DxfiwbJb.cjs";
|
|
2
2
|
export { FieldCard, FieldCardProps, fieldCardVariants };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FieldCardProps, r as fieldCardVariants, t as FieldCard } from "../index-
|
|
1
|
+
import { n as FieldCardProps, r as fieldCardVariants, t as FieldCard } from "../index-gWYaaO6O.js";
|
|
2
2
|
export { FieldCard, FieldCardProps, fieldCardVariants };
|
package/dist/FieldCard/index.js
CHANGED
|
@@ -61,6 +61,38 @@ var FieldCardValidationError_default = FieldCardValidationError;
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/FieldCard/FieldCard.tsx
|
|
63
63
|
/**
|
|
64
|
+
* Recursively checks if any child field has an error (regardless of touched state).
|
|
65
|
+
* Returns true if at least one child has an error.
|
|
66
|
+
*/
|
|
67
|
+
const hasAnyChildErrors = (errors) => {
|
|
68
|
+
if (!errors) return false;
|
|
69
|
+
return Object.keys(errors).filter((key) => {
|
|
70
|
+
return key !== "_errors";
|
|
71
|
+
}).some((key) => {
|
|
72
|
+
const errorValue = errors[key];
|
|
73
|
+
if (errorValue === void 0) return false;
|
|
74
|
+
if (Array.isArray(errorValue)) return true;
|
|
75
|
+
if (typeof errorValue === "object" && errorValue !== null) return hasAnyChildErrors(errorValue);
|
|
76
|
+
return false;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Recursively checks if any child field is touched.
|
|
81
|
+
* Returns true if at least one child is touched.
|
|
82
|
+
*/
|
|
83
|
+
const hasAnyChildTouched = (touched) => {
|
|
84
|
+
if (!touched) return false;
|
|
85
|
+
return Object.keys(touched).filter((key) => {
|
|
86
|
+
return key !== "_errors";
|
|
87
|
+
}).some((key) => {
|
|
88
|
+
const touchedValue = touched[key];
|
|
89
|
+
if (touchedValue === void 0) return false;
|
|
90
|
+
if (touchedValue === true) return true;
|
|
91
|
+
if (typeof touchedValue === "object" && touchedValue !== null) return hasAnyChildTouched(touchedValue);
|
|
92
|
+
return false;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
64
96
|
* Recursively checks if any child field with an error is also touched.
|
|
65
97
|
* Returns true if at least one touched child has an error.
|
|
66
98
|
*/
|
|
@@ -151,11 +183,10 @@ const FieldCard = ({ children, className: _className = void 0, name, ...uniformF
|
|
|
151
183
|
};
|
|
152
184
|
const fieldTouched = getNestedValue(touchedFields, name);
|
|
153
185
|
const hasObjectErrors = !!error?._errors;
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
const className = (0, _fuf_stack_pixel_utils.variantsToClassNames)(fieldCardVariants({ invalid: hasObjectErrors && (submitCount > 0 || !!hasAnyChildTouched) || hasVisibleChildren }), _className, "base");
|
|
186
|
+
const errorRecord = error;
|
|
187
|
+
const hasChildErrors = hasAnyChildErrors(errorRecord);
|
|
188
|
+
const isAnyChildTouched = hasAnyChildTouched(fieldTouched);
|
|
189
|
+
const className = (0, _fuf_stack_pixel_utils.variantsToClassNames)(fieldCardVariants({ invalid: hasChildErrors && (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0) || hasObjectErrors && !hasChildErrors && (isAnyChildTouched || submitCount > 0) }), _className, "base");
|
|
159
190
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
160
191
|
className: className.base,
|
|
161
192
|
children: [
|
|
@@ -198,4 +229,4 @@ Object.defineProperty(exports, 'fieldCardVariants', {
|
|
|
198
229
|
return fieldCardVariants;
|
|
199
230
|
}
|
|
200
231
|
});
|
|
201
|
-
//# sourceMappingURL=FieldCard-
|
|
232
|
+
//# sourceMappingURL=FieldCard-38ZBBWyE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldCard-38ZBBWyE.cjs","names":["useUniformField","AnimatePresence","motion","FieldValidationError","useUniformField","useFormContext","checkFieldIsRequired","FieldCardValidationError"],"sources":["../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../src/FieldCard/FieldCard.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../../hooks/useUniformField';\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name for the error footer wrapper */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** Field name */\n name: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n name,\n}: FieldCardValidationErrorProps) => {\n const { getErrorMessageProps, getHelperWrapperProps, testId } =\n useUniformField({\n name,\n });\n\n // disable all animation if user prefers reduced motion\n const disableAnimation = useReducedMotion();\n\n // Always show object-level errors (_errors) when they exist\n // @ts-expect-error - error._errors exists but not typed\n const hasErrors = !!error?._errors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n >\n <div\n {...getHelperWrapperProps()}\n className={cn(getHelperWrapperProps()?.className, className)}\n >\n <div\n {...getErrorMessageProps()}\n className={cn(\n getErrorMessageProps()?.className,\n errorTextClassName,\n )}\n >\n <FieldValidationError\n // @ts-expect-error - error._errors exists but not typed\n error={error._errors}\n testId={testId}\n />\n </div>\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { checkFieldIsRequired, useFormContext } from '../hooks/useFormContext';\nimport { useUniformField } from '../hooks/useUniformField';\nimport FieldCardValidationError from './subcomponents/FieldCardValidationError';\n\n/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the label/header */\n label: [\n // override HeroUI label positioning and display\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n },\n variants: {\n invalid: {\n true: {\n base: 'border-danger-200',\n label: 'border-danger-200 text-danger',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n },\n false: {\n base: 'border-divider',\n label: 'border-divider text-foreground',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\ntype ClassName = TVClassName<typeof fieldCardVariants>;\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Label content for the card header */\n label: ReactNode;\n /** Field name for validation */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * FieldCard component - A card-styled container with label header and error footer\n *\n * Displays form field content in a card layout with:\n * - Label/title in the header\n * - Content in the body\n * - Validation errors in the footer\n * - Danger outline when validation errors exist\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { error, getLabelProps, label } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // Check if any registered child field is required\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // Get touched state for this field's children by traversing the path\n const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n ): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n };\n\n const fieldTouched = getNestedValue(\n touchedFields as Record<string, unknown>,\n name,\n );\n\n // Check for object-level errors (_errors)\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n // Check if any child field has errors (regardless of touched state)\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n // Check if any child field is touched\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // Show invalid styling (danger border/header/error text) when:\n // 1. Any child field has an error AND (it's touched OR form was submitted), OR\n // 2. Object-level _errors exists AND no child errors AND (any child touched OR submitted)\n const showInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // className from slots\n const variants = fieldCardVariants({ invalid: showInvalid });\n const className = variantsToClassNames(variants, _className, 'base');\n\n return (\n <div className={className.base}>\n {/* card header with label */}\n {label ? (\n <div\n {...getLabelProps()}\n aria-level={3}\n // Override getLabelProps className to use our own invalid styling based on hasErrors,\n // not HeroUI's which is based on any child field being invalid\n className={className.label}\n role=\"heading\"\n >\n {label}\n {/* Manual asterisk: getLabelProps uses schema-required for the object itself,\n but FieldCard needs asterisk based on whether any CHILD field is required */}\n {isRequired ? (\n <span aria-hidden=\"true\" className=\"ml-0.5 text-danger\">\n *\n </span>\n ) : null}\n </div>\n ) : null}\n\n {/* card content */}\n <div className={className.content}>{children}</div>\n\n {/* card footer with validation errors - always show _errors, but danger styling controlled by showInvalid */}\n <FieldCardValidationError\n className={className.errorFooter}\n error={error}\n errorTextClassName={className.errorText}\n name={name}\n />\n </div>\n );\n};\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAM,4BAA4B,EAChC,YAAY,QACZ,QAAQ,QACR,qBAAqB,QACrB,WACmC;CACnC,MAAM,E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MAAM,aAAa,qBACf,iBACG,QAAQ,MAAM;AACb,SAAO,EAAE,WAAW,iBAAiB;GACrC,CACD,MAAM,MAAM;AACX,SAAOC,4CACL,oBACA,EAAE,MAAM,IAAI,CAAC,QAAQ,MAAM;AACzB,UAAO,MAAM;IACb,CACH;GACD,GACJ;CAGJ,MAAM,kBACJ,KACA,SACwC;AACxC,MAAI,CAAC,IACH;EAEF,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,UAAmB;AACvB,OAAK,OAAO,QAAQ;AAClB,OAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,cAAW,QAAoC;AAC/C,WAAO;;AAET,aAAU;AACV,UAAO;IACP;AACF,SAAO;;CAGT,MAAM,eAAe,eACnB,eACA,KACD;CAID,MAAM,kBAAkB,CAAC,CAAC,OAAO;CAEjC,MAAM,cAAc;CAGpB,MAAM,iBAAiB,kBAAkB,YAAY;CAErD,MAAM,oBAAoB,mBAAmB,aAAa;CAc1D,MAAM,6DADW,kBAAkB,EAAE,SAPlC,mBACE,sBAAsB,aAAa,aAAa,IAAI,cAAc,MACpE,mBACC,CAAC,mBACA,qBAAqB,cAAc,IAGmB,CAAC,EACX,YAAY,OAAO;AAEpE,QACE,4CAAC;EAAI,WAAW,UAAU;;GAEvB,QACC,4CAAC;IACC,GAAI,eAAe;IACnB,cAAY;IAGZ,WAAW,UAAU;IACrB,MAAK;eAEJ,OAGA,aACC,2CAAC;KAAK,eAAY;KAAO,WAAU;eAAqB;MAEjD,GACL;KACA,GACJ;GAGJ,2CAAC;IAAI,WAAW,UAAU;IAAU;KAAe;GAGnD,2CAACC;IACC,WAAW,UAAU;IACd;IACP,oBAAoB,UAAU;IACxB;KACN;;GACE;;AAIV,wBAAe"}
|
|
@@ -60,6 +60,38 @@ var FieldCardValidationError_default = FieldCardValidationError;
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/FieldCard/FieldCard.tsx
|
|
62
62
|
/**
|
|
63
|
+
* Recursively checks if any child field has an error (regardless of touched state).
|
|
64
|
+
* Returns true if at least one child has an error.
|
|
65
|
+
*/
|
|
66
|
+
const hasAnyChildErrors = (errors) => {
|
|
67
|
+
if (!errors) return false;
|
|
68
|
+
return Object.keys(errors).filter((key) => {
|
|
69
|
+
return key !== "_errors";
|
|
70
|
+
}).some((key) => {
|
|
71
|
+
const errorValue = errors[key];
|
|
72
|
+
if (errorValue === void 0) return false;
|
|
73
|
+
if (Array.isArray(errorValue)) return true;
|
|
74
|
+
if (typeof errorValue === "object" && errorValue !== null) return hasAnyChildErrors(errorValue);
|
|
75
|
+
return false;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Recursively checks if any child field is touched.
|
|
80
|
+
* Returns true if at least one child is touched.
|
|
81
|
+
*/
|
|
82
|
+
const hasAnyChildTouched = (touched) => {
|
|
83
|
+
if (!touched) return false;
|
|
84
|
+
return Object.keys(touched).filter((key) => {
|
|
85
|
+
return key !== "_errors";
|
|
86
|
+
}).some((key) => {
|
|
87
|
+
const touchedValue = touched[key];
|
|
88
|
+
if (touchedValue === void 0) return false;
|
|
89
|
+
if (touchedValue === true) return true;
|
|
90
|
+
if (typeof touchedValue === "object" && touchedValue !== null) return hasAnyChildTouched(touchedValue);
|
|
91
|
+
return false;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
63
95
|
* Recursively checks if any child field with an error is also touched.
|
|
64
96
|
* Returns true if at least one touched child has an error.
|
|
65
97
|
*/
|
|
@@ -150,11 +182,10 @@ const FieldCard = ({ children, className: _className = void 0, name, ...uniformF
|
|
|
150
182
|
};
|
|
151
183
|
const fieldTouched = getNestedValue(touchedFields, name);
|
|
152
184
|
const hasObjectErrors = !!error?._errors;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const className = variantsToClassNames(fieldCardVariants({ invalid: hasObjectErrors && (submitCount > 0 || !!hasAnyChildTouched) || hasVisibleChildren }), _className, "base");
|
|
185
|
+
const errorRecord = error;
|
|
186
|
+
const hasChildErrors = hasAnyChildErrors(errorRecord);
|
|
187
|
+
const isAnyChildTouched = hasAnyChildTouched(fieldTouched);
|
|
188
|
+
const className = variantsToClassNames(fieldCardVariants({ invalid: hasChildErrors && (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0) || hasObjectErrors && !hasChildErrors && (isAnyChildTouched || submitCount > 0) }), _className, "base");
|
|
158
189
|
return /* @__PURE__ */ jsxs("div", {
|
|
159
190
|
className: className.base,
|
|
160
191
|
children: [
|
|
@@ -186,4 +217,4 @@ var FieldCard_default = FieldCard;
|
|
|
186
217
|
|
|
187
218
|
//#endregion
|
|
188
219
|
export { fieldCardVariants as n, FieldCard_default as t };
|
|
189
|
-
//# sourceMappingURL=FieldCard-
|
|
220
|
+
//# sourceMappingURL=FieldCard-7XiCb6jZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldCard-7XiCb6jZ.js","names":["FieldValidationError","FieldCardValidationError"],"sources":["../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../src/FieldCard/FieldCard.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../../hooks/useUniformField';\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name for the error footer wrapper */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** Field name */\n name: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n name,\n}: FieldCardValidationErrorProps) => {\n const { getErrorMessageProps, getHelperWrapperProps, testId } =\n useUniformField({\n name,\n });\n\n // disable all animation if user prefers reduced motion\n const disableAnimation = useReducedMotion();\n\n // Always show object-level errors (_errors) when they exist\n // @ts-expect-error - error._errors exists but not typed\n const hasErrors = !!error?._errors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n >\n <div\n {...getHelperWrapperProps()}\n className={cn(getHelperWrapperProps()?.className, className)}\n >\n <div\n {...getErrorMessageProps()}\n className={cn(\n getErrorMessageProps()?.className,\n errorTextClassName,\n )}\n >\n <FieldValidationError\n // @ts-expect-error - error._errors exists but not typed\n error={error._errors}\n testId={testId}\n />\n </div>\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { checkFieldIsRequired, useFormContext } from '../hooks/useFormContext';\nimport { useUniformField } from '../hooks/useUniformField';\nimport FieldCardValidationError from './subcomponents/FieldCardValidationError';\n\n/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the label/header */\n label: [\n // override HeroUI label positioning and display\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n },\n variants: {\n invalid: {\n true: {\n base: 'border-danger-200',\n label: 'border-danger-200 text-danger',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n },\n false: {\n base: 'border-divider',\n label: 'border-divider text-foreground',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\ntype ClassName = TVClassName<typeof fieldCardVariants>;\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Label content for the card header */\n label: ReactNode;\n /** Field name for validation */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * FieldCard component - A card-styled container with label header and error footer\n *\n * Displays form field content in a card layout with:\n * - Label/title in the header\n * - Content in the body\n * - Validation errors in the footer\n * - Danger outline when validation errors exist\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { error, getLabelProps, label } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // Check if any registered child field is required\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // Get touched state for this field's children by traversing the path\n const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n ): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n };\n\n const fieldTouched = getNestedValue(\n touchedFields as Record<string, unknown>,\n name,\n );\n\n // Check for object-level errors (_errors)\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n // Check if any child field has errors (regardless of touched state)\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n // Check if any child field is touched\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // Show invalid styling (danger border/header/error text) when:\n // 1. Any child field has an error AND (it's touched OR form was submitted), OR\n // 2. Object-level _errors exists AND no child errors AND (any child touched OR submitted)\n const showInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // className from slots\n const variants = fieldCardVariants({ invalid: showInvalid });\n const className = variantsToClassNames(variants, _className, 'base');\n\n return (\n <div className={className.base}>\n {/* card header with label */}\n {label ? (\n <div\n {...getLabelProps()}\n aria-level={3}\n // Override getLabelProps className to use our own invalid styling based on hasErrors,\n // not HeroUI's which is based on any child field being invalid\n className={className.label}\n role=\"heading\"\n >\n {label}\n {/* Manual asterisk: getLabelProps uses schema-required for the object itself,\n but FieldCard needs asterisk based on whether any CHILD field is required */}\n {isRequired ? (\n <span aria-hidden=\"true\" className=\"ml-0.5 text-danger\">\n *\n </span>\n ) : null}\n </div>\n ) : null}\n\n {/* card content */}\n <div className={className.content}>{children}</div>\n\n {/* card footer with validation errors - always show _errors, but danger styling controlled by showInvalid */}\n <FieldCardValidationError\n className={className.errorFooter}\n error={error}\n errorTextClassName={className.errorText}\n name={name}\n />\n </div>\n );\n};\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAM,4BAA4B,EAChC,YAAY,QACZ,QAAQ,QACR,qBAAqB,QACrB,WACmC;CACnC,MAAM,EAAE,sBAAsB,uBAAuB,WACnD,gBAAgB,EACd,MACD,CAAC;CAGJ,MAAM,mBAAmB,kBAAkB;CAI3C,MAAM,YAAY,CAAC,CAAC,OAAO;AAE3B,QACE,oBAAC;EAAgB,SAAS,CAAC;YACxB,YACC,oBAAC,OAAO;GAEN,MAAM,mBAAmB,SAAY;IAAE,SAAS;IAAG,QAAQ;IAAG;GAC9D,SAAS,mBAAmB,QAAQ;IAAE,QAAQ;IAAG,SAAS;IAAG;GAC7D,OAAO,EAAE,UAAU,UAAU;GAC7B,YAAY;IAAE,UAAU;IAAK,MAAM;IAAW;GAC9C,SACE,mBAAmB,SAAY;IAAE,SAAS;IAAG,QAAQ;IAAQ;aAG/D,oBAAC;IACC,GAAI,uBAAuB;IAC3B,WAAW,GAAG,uBAAuB,EAAE,WAAW,UAAU;cAE5D,oBAAC;KACC,GAAI,sBAAsB;KAC1B,WAAW,GACT,sBAAsB,EAAE,WACxB,mBACD;eAED,oBAACA;MAEC,OAAO,MAAM;MACL;OACR;MACE;KACF;KA1BF,oBA2BO,GACX;GACY;;AAItB,uCAAe;;;;;;;;AC3Ef,MAAa,qBACX,WACY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,CAAC,mBACA,qBAAqB,cAAc,IAGmB,CAAC,EACX,YAAY,OAAO;AAEpE,QACE,qBAAC;EAAI,WAAW,UAAU;;GAEvB,QACC,qBAAC;IACC,GAAI,eAAe;IACnB,cAAY;IAGZ,WAAW,UAAU;IACrB,MAAK;eAEJ,OAGA,aACC,oBAAC;KAAK,eAAY;KAAO,WAAU;eAAqB;MAEjD,GACL;KACA,GACJ;GAGJ,oBAAC;IAAI,WAAW,UAAU;IAAU;KAAe;GAGnD,oBAACC;IACC,WAAW,UAAU;IACd;IACP,oBAAoB,UAAU;IACxB;KACN;;GACE;;AAIV,wBAAe"}
|
package/dist/Form/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FormProps, t as Form } from "../index-
|
|
1
|
+
import { n as FormProps, t as Form } from "../index-Bo79xzb4.cjs";
|
|
2
2
|
export { Form, Form as default, FormProps };
|
package/dist/Form/index.d.ts
CHANGED
package/dist/Grid/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as GridProps, t as Grid } from "../index-
|
|
1
|
+
import { n as GridProps, t as Grid } from "../index-BW9EUWZE.cjs";
|
|
2
2
|
export { Grid, Grid as default, GridProps };
|
package/dist/Grid/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as GridProps, t as Grid } from "../index-
|
|
1
|
+
import { n as GridProps, t as Grid } from "../index-BFLKkqA3.js";
|
|
2
2
|
export { Grid, Grid as default, GridProps };
|
package/dist/Input/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as InputProps, t as Input } from "../index-
|
|
1
|
+
import { n as InputProps, t as Input } from "../index-DAeb_8Q4.cjs";
|
|
2
2
|
export { Input, Input as default, InputProps };
|
package/dist/Input/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as InputProps, t as Input } from "../index-
|
|
1
|
+
import { n as InputProps, t as Input } from "../index-CB00FCyi.js";
|
|
2
2
|
export { Input, Input as default, InputProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadioBoxes, r as RadioBoxesProps, t as radioBoxVariants } from "../index-
|
|
1
|
+
import { n as RadioBoxes, r as RadioBoxesProps, t as radioBoxVariants } from "../index-nVYabHcT.cjs";
|
|
2
2
|
export { RadioBoxes, RadioBoxes as default, RadioBoxesProps, radioBoxVariants };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadioBoxes, r as RadioBoxesProps, t as radioBoxVariants } from "../index-
|
|
1
|
+
import { n as RadioBoxes, r as RadioBoxesProps, t as radioBoxVariants } from "../index-Cj-PU3Ck.js";
|
|
2
2
|
export { RadioBoxes, RadioBoxes as default, RadioBoxesProps, radioBoxVariants };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadioTabsProps, t as RadioTabs } from "../index-
|
|
1
|
+
import { n as RadioTabsProps, t as RadioTabs } from "../index-Cj5CLBt2.cjs";
|
|
2
2
|
export { RadioTabs, RadioTabs as default, RadioTabsProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadioTabsProps, t as RadioTabs } from "../index-
|
|
1
|
+
import { n as RadioTabsProps, t as RadioTabs } from "../index-C3CvgmJw.js";
|
|
2
2
|
export { RadioTabs, RadioTabs as default, RadioTabsProps };
|
package/dist/Radios/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadiosProps, t as Radios } from "../index-
|
|
1
|
+
import { n as RadiosProps, t as Radios } from "../index-BgXr1v45.cjs";
|
|
2
2
|
export { Radios, Radios as default, RadiosProps };
|
package/dist/Radios/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RadiosProps, t as Radios } from "../index-
|
|
1
|
+
import { n as RadiosProps, t as Radios } from "../index-796vjEop.js";
|
|
2
2
|
export { Radios, Radios as default, RadiosProps };
|
package/dist/Select/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SelectProps, t as Select } from "../index-
|
|
1
|
+
import { n as SelectProps, t as Select } from "../index-DfGCI-K_.cjs";
|
|
2
2
|
export { Select, Select as default, SelectProps };
|
package/dist/Select/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SelectProps, t as Select } from "../index-
|
|
1
|
+
import { n as SelectProps, t as Select } from "../index-COwP53Gx.js";
|
|
2
2
|
export { Select, Select as default, SelectProps };
|
package/dist/Slider/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SliderProps, t as Slider } from "../index-
|
|
1
|
+
import { n as SliderProps, t as Slider } from "../index-CrxSEKKb.cjs";
|
|
2
2
|
export { Slider, Slider as default, SliderProps };
|
package/dist/Slider/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SliderProps, t as Slider } from "../index-
|
|
1
|
+
import { n as SliderProps, t as Slider } from "../index-DebErIUS.js";
|
|
2
2
|
export { Slider, Slider as default, SliderProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SubmitButtonProps, t as SubmitButton } from "../index-
|
|
1
|
+
import { n as SubmitButtonProps, t as SubmitButton } from "../index-CbAh0Kfo.cjs";
|
|
2
2
|
export { SubmitButton, SubmitButton as default, SubmitButtonProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SubmitButtonProps, t as SubmitButton } from "../index-
|
|
1
|
+
import { n as SubmitButtonProps, t as SubmitButton } from "../index-pE9osud2.js";
|
|
2
2
|
export { SubmitButton, SubmitButton as default, SubmitButtonProps };
|
package/dist/Switch/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SwitchProps, t as Switch } from "../index-
|
|
1
|
+
import { n as SwitchProps, t as Switch } from "../index-D3RMbKbP.cjs";
|
|
2
2
|
export { Switch, Switch as default, SwitchProps };
|
package/dist/Switch/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SwitchProps, t as Switch } from "../index-
|
|
1
|
+
import { n as SwitchProps, t as Switch } from "../index-DjDR6FpI.js";
|
|
2
2
|
export { Switch, Switch as default, SwitchProps };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SwitchBoxProps, r as switchBoxVariants, t as SwitchBox } from "../index-
|
|
1
|
+
import { n as SwitchBoxProps, r as switchBoxVariants, t as SwitchBox } from "../index-BD9y--o2.cjs";
|
|
2
2
|
export { SwitchBox, SwitchBox as default, SwitchBoxProps, switchBoxVariants };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SwitchBoxProps, r as switchBoxVariants, t as SwitchBox } from "../index-
|
|
1
|
+
import { n as SwitchBoxProps, r as switchBoxVariants, t as SwitchBox } from "../index-B_1td56I.js";
|
|
2
2
|
export { SwitchBox, SwitchBox as default, SwitchBoxProps, switchBoxVariants };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as TextAreaProps, t as TextArea } from "../index-
|
|
1
|
+
import { n as TextAreaProps, t as TextArea } from "../index-Y8XsRdxS.cjs";
|
|
2
2
|
export { TextArea, TextArea as default, TextAreaProps };
|
package/dist/TextArea/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as TextAreaProps, t as TextArea } from "../index-
|
|
1
|
+
import { n as TextAreaProps, t as TextArea } from "../index-B62CWrcm.js";
|
|
2
2
|
export { TextArea, TextArea as default, TextAreaProps };
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,2 +1,186 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/helpers/createOptionValueConverter/createOptionValueConverter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a converter function that preserves the original type (string, number, or boolean)
|
|
4
|
+
* of option values when converting from string keys back to their original type.
|
|
5
|
+
*
|
|
6
|
+
* This is useful for radio/select components where the underlying UI library
|
|
7
|
+
* uses string keys internally, but we want to preserve number/boolean values in the form state.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Array of options with a value property that can be string, number, or boolean
|
|
10
|
+
* @returns An object with:
|
|
11
|
+
* - `convertToOriginalType`: Function to convert a string key back to its original type
|
|
12
|
+
* - `numberValueKeys`: Set of string representations of number values (for internal use)
|
|
13
|
+
* - `booleanValueKeys`: Map of string representations to boolean values (for internal use)
|
|
14
|
+
*/
|
|
15
|
+
declare const createOptionValueConverter: <T extends {
|
|
16
|
+
value: string | number | boolean;
|
|
17
|
+
}>(options: T[]) => {
|
|
18
|
+
booleanValueKeys: Map<string, boolean>;
|
|
19
|
+
convertToOriginalType: (key: string | number | boolean) => string | number | boolean;
|
|
20
|
+
numberValueKeys: Set<string>;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/helpers/nullishFields/nullishFields.d.ts
|
|
24
|
+
/** Key used to wrap flat array elements when converting to form format */
|
|
25
|
+
declare const flatArrayKey = "__FLAT__";
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a value is considered "empty" for validation display purposes.
|
|
28
|
+
*
|
|
29
|
+
* Used by useUniformField to determine when to show validation errors.
|
|
30
|
+
* Empty values don't trigger immediate error display (user must interact first).
|
|
31
|
+
*
|
|
32
|
+
* Handles:
|
|
33
|
+
* - Primitives: null, undefined, ''
|
|
34
|
+
* - Marker strings: __NULL__, __FALSE__, __ZERO__ (converted via fromNullishString)
|
|
35
|
+
* - Empty arrays: []
|
|
36
|
+
* - Objects with all empty values: {a: null, b: ''}
|
|
37
|
+
* - Flat array wrappers: {__FLAT__: null} or {__FLAT__: ''}
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to check (will be converted via fromNullishString first)
|
|
40
|
+
* @returns true if the value is empty
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* isValueEmpty(null) // true
|
|
44
|
+
* isValueEmpty('') // true
|
|
45
|
+
* isValueEmpty('__NULL__') // true (marker string)
|
|
46
|
+
* isValueEmpty([]) // true (empty array)
|
|
47
|
+
* isValueEmpty({a: null}) // true (object with all empty values)
|
|
48
|
+
* isValueEmpty({__FLAT__: null}) // true (flat array wrapper with empty value)
|
|
49
|
+
* isValueEmpty({__FLAT__: ''}) // true
|
|
50
|
+
* isValueEmpty('hello') // false
|
|
51
|
+
* isValueEmpty([1, 2]) // false
|
|
52
|
+
* isValueEmpty({a: 'value'}) // false
|
|
53
|
+
* isValueEmpty({__FLAT__: 'value'}) // false
|
|
54
|
+
*/
|
|
55
|
+
declare const isValueEmpty: (value: unknown) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Converts marker strings back to their original values when processing arrays
|
|
58
|
+
*/
|
|
59
|
+
declare const fromNullishString: (value: unknown) => unknown;
|
|
60
|
+
/**
|
|
61
|
+
* Converts null/falsy values to marker strings for JSON processing
|
|
62
|
+
*/
|
|
63
|
+
declare const toNullishString: (value: unknown) => unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Converts field values to a format suitable for forms by:
|
|
66
|
+
* - Wrapping arrays of primitives as objects using the flatArrayKey `__FLAT__`
|
|
67
|
+
* to satisfy RHF's requirement that array fields contain objects
|
|
68
|
+
* - Removing empty strings and null values from objects
|
|
69
|
+
*
|
|
70
|
+
* This conversion is required because React Hook Form does not support arrays with
|
|
71
|
+
* flat values (string, number, boolean, null). Array fields must contain objects.
|
|
72
|
+
* We work around this by wrapping primitive entries: `{ __FLAT__: <value> }`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const fields = {
|
|
76
|
+
* name: 'John',
|
|
77
|
+
* scores: [0, null, 75, false],
|
|
78
|
+
* scoresDetailed: [
|
|
79
|
+
* { score: 1 },
|
|
80
|
+
* { score: null },
|
|
81
|
+
* { score: 0 },
|
|
82
|
+
* { score: false },
|
|
83
|
+
* { score: '' },
|
|
84
|
+
* ],
|
|
85
|
+
* contact: {
|
|
86
|
+
* email: '',
|
|
87
|
+
* phone: null,
|
|
88
|
+
* address: '123 Main St'
|
|
89
|
+
* }
|
|
90
|
+
* };
|
|
91
|
+
*
|
|
92
|
+
* // Result:
|
|
93
|
+
* {
|
|
94
|
+
* name: 'John',
|
|
95
|
+
* scores: [
|
|
96
|
+
* { __FLAT__: 0 },
|
|
97
|
+
* { __FLAT__: null },
|
|
98
|
+
* { __FLAT__: 75 },
|
|
99
|
+
* { __FLAT__: false }
|
|
100
|
+
* ],
|
|
101
|
+
* // Arrays of objects are left as objects; empty/null properties are removed
|
|
102
|
+
* scoresDetailed: [
|
|
103
|
+
* { score: 1 },
|
|
104
|
+
* {}, // null score removed
|
|
105
|
+
* { score: 0 },
|
|
106
|
+
* { score: false },
|
|
107
|
+
* {}, // empty string removed
|
|
108
|
+
* ],
|
|
109
|
+
* contact: {
|
|
110
|
+
* address: '123 Main St'
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
*/
|
|
114
|
+
declare const toFormFormat: (fields: Record<string, unknown>) => Record<string, unknown>;
|
|
115
|
+
/**
|
|
116
|
+
* Converts form state to a format suitable for validation by:
|
|
117
|
+
* - Unwrapping flat array wrappers `{ __FLAT__: <value> }` back to primitives
|
|
118
|
+
* - Converting legacy string markers (__NULL__, __FALSE__, __ZERO__) back to their original values
|
|
119
|
+
* - Removing fields whose converted value is empty string or null
|
|
120
|
+
* - Removing empty arrays
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* const formState = {
|
|
124
|
+
* name: 'John',
|
|
125
|
+
* scores: [
|
|
126
|
+
* { __FLAT__: 75 },
|
|
127
|
+
* { __FLAT__: 0 },
|
|
128
|
+
* { __FLAT__: null },
|
|
129
|
+
* { __FLAT__: false }
|
|
130
|
+
* ],
|
|
131
|
+
* emptyArray: [],
|
|
132
|
+
* scoresDetailed: [
|
|
133
|
+
* { score: 1 },
|
|
134
|
+
* {},
|
|
135
|
+
* { score: 0 },
|
|
136
|
+
* { score: false },
|
|
137
|
+
* {},
|
|
138
|
+
* ],
|
|
139
|
+
* contact: {
|
|
140
|
+
* address: '123 Main St',
|
|
141
|
+
* fax: null
|
|
142
|
+
* }
|
|
143
|
+
* };
|
|
144
|
+
*
|
|
145
|
+
* // Result:
|
|
146
|
+
* {
|
|
147
|
+
* name: 'John',
|
|
148
|
+
* scores: [75, 0, null, false],
|
|
149
|
+
* // emptyArray is removed
|
|
150
|
+
* // Objects inside arrays remain objects; empty entries remain empty objects
|
|
151
|
+
* scoresDetailed: [
|
|
152
|
+
* { score: 1 },
|
|
153
|
+
* {},
|
|
154
|
+
* { score: 0 },
|
|
155
|
+
* { score: false },
|
|
156
|
+
* {},
|
|
157
|
+
* ],
|
|
158
|
+
* contact: {
|
|
159
|
+
* address: '123 Main St'
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
*/
|
|
163
|
+
declare const toValidationFormat: (formState: Record<string, unknown> | null | undefined) => Record<string, unknown> | null | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Converts a field name to a testId by removing flat array key segments and slugifying.
|
|
166
|
+
* Removes all occurrences of `flatArrayKey` from the field name and applies slugify transformation.
|
|
167
|
+
*
|
|
168
|
+
* This is used to generate stable testIds for form fields that don't include
|
|
169
|
+
* the internal `__FLAT__` marker used for flat arrays.
|
|
170
|
+
*
|
|
171
|
+
* @param name - The field name as a string (e.g., 'tags.0.__FLAT__') or array path (e.g., ['tags', '0', '__FLAT__'])
|
|
172
|
+
* @returns The slugified field name with all flat array key segments removed (e.g., 'tags_0')
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* nameToTestId('tags.0.__FLAT__') // => 'tags_0'
|
|
177
|
+
* nameToTestId('array.0.__FLAT__') // => 'array_0'
|
|
178
|
+
* nameToTestId('nested.array.0.__FLAT__.field') // => 'nested_array_0_field'
|
|
179
|
+
* nameToTestId('simple.field') // => 'simple_field'
|
|
180
|
+
* nameToTestId(['tags', '0', '__FLAT__']) // => 'tags_0'
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare const nameToTestId: (name: string | readonly string[]) => string;
|
|
184
|
+
//#endregion
|
|
185
|
+
export { createOptionValueConverter, flatArrayKey, fromNullishString, isValueEmpty, nameToTestId, toFormFormat, toNullishString, toValidationFormat };
|
|
186
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/helpers/createOptionValueConverter/createOptionValueConverter.ts","../../src/helpers/nullishFields/nullishFields.ts"],"sourcesContent":[],"mappings":";;AAeA;;;;;;;;ACZA;AAsCA;AA0BA;AAsCA;AA6Ea,cDvKA,0BC+LgC,EAAA,CAAA,UAAA;EAmDhC,KAAA,EAAA,MAAA,GAAA,MA6EZ,GAAA,OAAA;AAqBD,CAAA,CAAA,CAAA,OAAa,EDjVF,CCiVE,EAAA,EAAA,GAsBZ;;;;;;;;AD1WY,cCZA,YAAA,GD8DZ,UAAA;;;;;;;;AC9DD;AAsCA;AA0BA;AAsCA;AA6EA;AA2EA;AAkGA;;;;;;;;;;;;;;;;cA1Ta;;;;cA0BA;;;;cAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6EA,uBAAwB,4BAwBE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmD1B,gCACA,+CACV;;;;;;;;;;;;;;;;;;;;cAgGU"}
|