@fuf-stack/uniform 1.28.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +6 -35
  2. package/dist/Checkboxes/index.d.mts +192 -263
  3. package/dist/Checkboxes/index.d.mts.map +1 -1
  4. package/dist/Checkboxes/index.mjs +294 -90
  5. package/dist/Checkboxes/index.mjs.map +1 -1
  6. package/dist/DatePicker/index.d.mts +1278 -496
  7. package/dist/DatePicker/index.d.mts.map +1 -1
  8. package/dist/DatePicker/index.mjs +403 -83
  9. package/dist/DatePicker/index.mjs.map +1 -1
  10. package/dist/FieldArray/index.d.mts +105 -98
  11. package/dist/FieldArray/index.d.mts.map +1 -1
  12. package/dist/FieldArray/index.mjs +344 -195
  13. package/dist/FieldArray/index.mjs.map +1 -1
  14. package/dist/FieldCard/index.d.mts +37 -35
  15. package/dist/FieldCard/index.d.mts.map +1 -1
  16. package/dist/FieldCard/index.mjs +187 -128
  17. package/dist/FieldCard/index.mjs.map +1 -1
  18. package/dist/{FieldCopyTestIdButton-9xTF-DBW.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +4 -2
  19. package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
  20. package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
  21. package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
  22. package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
  23. package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
  24. package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
  25. package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
  26. package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
  27. package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
  28. package/dist/Form/index.d.mts +12 -12
  29. package/dist/Form/index.d.mts.map +1 -1
  30. package/dist/Form/index.mjs +9 -7
  31. package/dist/Form/index.mjs.map +1 -1
  32. package/dist/{FormContext-CB7Glm02.mjs → FormContext-CHctWFAP.mjs} +51 -8
  33. package/dist/FormContext-CHctWFAP.mjs.map +1 -0
  34. package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
  35. package/dist/Grid/index.mjs +1 -2
  36. package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
  37. package/dist/Grid-DfcZeuib.mjs.map +1 -0
  38. package/dist/Input/index.d.mts +638 -394
  39. package/dist/Input/index.d.mts.map +1 -1
  40. package/dist/Input/index.mjs +414 -165
  41. package/dist/Input/index.mjs.map +1 -1
  42. package/dist/RadioBoxes/index.d.mts +1588 -125
  43. package/dist/RadioBoxes/index.d.mts.map +1 -1
  44. package/dist/RadioBoxes/index.mjs +159 -114
  45. package/dist/RadioBoxes/index.mjs.map +1 -1
  46. package/dist/RadioTabs/index.d.mts +300 -81
  47. package/dist/RadioTabs/index.d.mts.map +1 -1
  48. package/dist/RadioTabs/index.mjs +277 -86
  49. package/dist/RadioTabs/index.mjs.map +1 -1
  50. package/dist/Radios/index.d.mts +1354 -109
  51. package/dist/Radios/index.d.mts.map +1 -1
  52. package/dist/Radios/index.mjs +105 -54
  53. package/dist/Radios/index.mjs.map +1 -1
  54. package/dist/Select/index.d.mts +554 -3009
  55. package/dist/Select/index.d.mts.map +1 -1
  56. package/dist/Select/index.mjs +319 -177
  57. package/dist/Select/index.mjs.map +1 -1
  58. package/dist/Slider/index.d.mts +416 -1328
  59. package/dist/Slider/index.d.mts.map +1 -1
  60. package/dist/Slider/index.mjs +276 -94
  61. package/dist/Slider/index.mjs.map +1 -1
  62. package/dist/SubmitButton/index.d.mts.map +1 -1
  63. package/dist/SubmitButton/index.mjs +4 -1
  64. package/dist/SubmitButton/index.mjs.map +1 -1
  65. package/dist/Switch/index.d.mts +2 -1248
  66. package/dist/Switch/index.mjs +167 -68
  67. package/dist/Switch/index.mjs.map +1 -1
  68. package/dist/Switch-CvPO8IF9.d.mts +601 -0
  69. package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
  70. package/dist/SwitchBox/index.d.mts +135 -39
  71. package/dist/SwitchBox/index.d.mts.map +1 -1
  72. package/dist/SwitchBox/index.mjs +142 -87
  73. package/dist/SwitchBox/index.mjs.map +1 -1
  74. package/dist/TextArea/index.d.mts +295 -411
  75. package/dist/TextArea/index.d.mts.map +1 -1
  76. package/dist/TextArea/index.mjs +200 -48
  77. package/dist/TextArea/index.mjs.map +1 -1
  78. package/dist/Time/index.d.mts +1170 -601
  79. package/dist/Time/index.d.mts.map +1 -1
  80. package/dist/Time/index.mjs +162 -74
  81. package/dist/Time/index.mjs.map +1 -1
  82. package/dist/helpers/index.d.mts +1 -1
  83. package/dist/helpers/index.mjs +1 -1
  84. package/dist/helpers/index.mjs.map +1 -1
  85. package/dist/hooks/useClientValidation/index.mjs +1 -1
  86. package/dist/hooks/useController/index.d.mts +31 -3
  87. package/dist/hooks/useController/index.d.mts.map +1 -0
  88. package/dist/hooks/useController/index.mjs +1 -2
  89. package/dist/hooks/useFormContext/index.d.mts +65 -3
  90. package/dist/hooks/useFormContext/index.d.mts.map +1 -0
  91. package/dist/hooks/useFormContext/index.mjs +1 -2
  92. package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
  93. package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
  94. package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
  95. package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
  96. package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
  97. package/dist/hooks/useInputValueTransform/index.mjs +1 -2
  98. package/dist/hooks/useWatchFormReset/index.mjs +1 -1
  99. package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
  100. package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
  101. package/dist/hooks/useWatchUserChange/index.mjs +1 -1
  102. package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
  103. package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
  104. package/dist/index-BS8IoBOn.d.mts.map +1 -0
  105. package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
  106. package/dist/partials/FieldValidationError/index.d.mts +637 -3
  107. package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
  108. package/dist/partials/FieldValidationError/index.mjs +1 -2
  109. package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
  110. package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
  111. package/dist/switchVariants-BaQw2DA7.mjs +67 -0
  112. package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
  113. package/dist/timeVariants-B9HDfNYt.mjs +58 -0
  114. package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
  115. package/dist/{useController-BBSbeKbn.mjs → useController-BCFeZbBZ.mjs} +2 -2
  116. package/dist/{useController-BBSbeKbn.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
  117. package/dist/{useFormContext-DNb_B8LQ.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
  118. package/dist/{useFormContext-DNb_B8LQ.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
  119. package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
  120. package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
  121. package/package.json +17 -29
  122. package/dist/FieldCopyTestIdButton-9xTF-DBW.mjs.map +0 -1
  123. package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
  124. package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
  125. package/dist/FormContext-CB7Glm02.mjs.map +0 -1
  126. package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
  127. package/dist/Switch/index.d.mts.map +0 -1
  128. package/dist/hooks/useInput/index.d.mts +0 -2
  129. package/dist/hooks/useInput/index.mjs +0 -7
  130. package/dist/hooks/useInput/index.mjs.map +0 -1
  131. package/dist/hooks/useUniformField/index.d.mts +0 -100
  132. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  133. package/dist/hooks/useUniformField/index.mjs +0 -139
  134. package/dist/hooks/useUniformField/index.mjs.map +0 -1
  135. package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
  136. package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
  137. package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
  138. package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
  139. package/dist/index-CAdGtKE_.d.mts +0 -1
  140. package/dist/index-CaxrMD1A.d.mts +0 -1
  141. package/dist/index-CwJo1b4Z.d.mts +0 -1
  142. package/dist/useController-DcK2YHbw.d.mts +0 -32
  143. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  144. package/dist/useFormContext-BegmYvGA.d.mts +0 -66
  145. package/dist/useFormContext-BegmYvGA.d.mts.map +0 -1
  146. package/dist/useInput-C0aJaAGe.mjs +0 -2
  147. package/dist/useInput-ClpHDPdr.d.mts +0 -2
  148. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1,62 +1,12 @@
1
- import { n as FieldValidationError } from "../FieldValidationError-ByRoIxaM.mjs";
2
- import { n as useFormContext, t as checkFieldIsRequired } from "../useFormContext-DNb_B8LQ.mjs";
3
- import { useUniformField } from "../hooks/useUniformField/index.mjs";
4
- import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
1
+ import { n as FieldValidationError } from "../FieldValidationError-DgkCL3cC.mjs";
2
+ import { n as useFormContext, t as checkFieldIsRequired } from "../useFormContext-BPjJjNnM.mjs";
3
+ import { n as useUniformField, t as FieldLabel } from "../FieldLabel-DKzqkuY1.mjs";
5
4
  import { useDebounce } from "@fuf-stack/pixels";
6
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { tv } from "@fuf-stack/pixel-utils";
7
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
7
8
  import { AnimatePresence, motion, useReducedMotion } from "@fuf-stack/pixel-motion";
8
- //#region src/FieldCard/subcomponents/FieldCardValidationError.tsx
9
- /**
10
- * Renders validation errors in the footer of a FieldCard component.
11
- *
12
- * This component handles displaying field-level validation errors with proper
13
- * accessibility attributes and animates them in/out using Framer Motion.
14
- *
15
- * Note: Object-level errors (_errors) are always shown when they exist,
16
- * but the danger styling is controlled by the parent FieldCard based on
17
- * whether child fields have been touched.
18
- */
19
- const FieldCardValidationError = ({ className = void 0, error = void 0, errorTextClassName = void 0, name }) => {
20
- const { getErrorMessageProps, getHelperWrapperProps, testId } = useUniformField({ name });
21
- const disableAnimation = useReducedMotion();
22
- const hasErrors = !!error?._errors;
23
- return /* @__PURE__ */ jsx(AnimatePresence, {
24
- initial: !disableAnimation,
25
- children: hasErrors ? /* @__PURE__ */ jsx(motion.div, {
26
- animate: disableAnimation ? void 0 : {
27
- opacity: 1,
28
- height: "auto"
29
- },
30
- exit: disableAnimation ? void 0 : {
31
- opacity: 0,
32
- height: 0
33
- },
34
- initial: disableAnimation ? false : {
35
- height: 0,
36
- opacity: 0
37
- },
38
- style: { overflow: "hidden" },
39
- transition: {
40
- duration: .4,
41
- ease: "circOut"
42
- },
43
- children: /* @__PURE__ */ jsx("div", {
44
- ...getHelperWrapperProps(),
45
- className: cn(getHelperWrapperProps()?.className, className),
46
- children: /* @__PURE__ */ jsx("div", {
47
- ...getErrorMessageProps(),
48
- className: cn(getErrorMessageProps()?.className, errorTextClassName),
49
- children: /* @__PURE__ */ jsx(FieldValidationError, {
50
- error: error._errors,
51
- testId
52
- })
53
- })
54
- })
55
- }, "field-card-errors") : null
56
- });
57
- };
58
- //#endregion
59
- //#region src/FieldCard/FieldCard.tsx
9
+ //#region src/FieldCard/fieldCardValidation.ts
60
10
  /**
61
11
  * Recursively checks if any child field has an error (regardless of touched state).
62
12
  * Returns true if at least one child has an error.
@@ -106,17 +56,66 @@ const hasVisibleChildErrors = (errors, touched) => {
106
56
  return false;
107
57
  });
108
58
  };
59
+ /** Reads nested child touched state for a dotted field path */
60
+ const getNestedValue = (obj, path) => {
61
+ if (!obj) return;
62
+ const keys = path.split(".");
63
+ let current = obj;
64
+ keys.every((key) => {
65
+ if (current && typeof current === "object") {
66
+ current = current[key];
67
+ return true;
68
+ }
69
+ current = void 0;
70
+ return false;
71
+ });
72
+ return current;
73
+ };
74
+ //#endregion
75
+ //#region src/FieldCard/hooks/useFieldCardValidation.ts
76
+ /**
77
+ * Derives the card's required and invalid states from its nested fields
78
+ *
79
+ * A card groups independently registered inputs, so its own field state does
80
+ * not tell us whether a child is required or which child errors are visible
81
+ * Required state comes from registered descendants and their validation schema
82
+ *
83
+ * Child errors become visible after that child is touched or the form is submitted
84
+ * Object-level errors follow child interaction or submission when no child errors
85
+ * exist, so they do not reveal untouched child failures early
86
+ *
87
+ * Debounces invalid-state changes to prevent flickering during validation updates
88
+ */
89
+ const useFieldCardValidation = (field) => {
90
+ const { error, name } = field;
91
+ const { control, formState: { touchedFields, submitCount }, validation } = useFormContext();
92
+ const validationInstance = validation?.baseInstance ?? validation?.instance;
93
+ const registeredFields = Array.from(control._names?.mount ?? []);
94
+ const childFieldPrefix = `${name}.`;
95
+ const isRequired = validationInstance ? registeredFields.filter((f) => {
96
+ return f.startsWith(childFieldPrefix);
97
+ }).some((f) => {
98
+ return checkFieldIsRequired(validationInstance, f.split(".").filter((k) => {
99
+ return k !== "";
100
+ }));
101
+ }) : false;
102
+ const fieldTouched = getNestedValue(touchedFields, name);
103
+ const hasObjectErrors = !!error?._errors;
104
+ const errorRecord = error;
105
+ const hasChildErrors = hasAnyChildErrors(errorRecord);
106
+ const isAnyChildTouched = hasAnyChildTouched(fieldTouched);
107
+ const rawShowInvalid = hasChildErrors && (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0) || hasObjectErrors && !hasChildErrors && (isAnyChildTouched || submitCount > 0);
108
+ return {
109
+ invalid: useDebounce(rawShowInvalid, 200),
110
+ required: isRequired
111
+ };
112
+ };
113
+ //#endregion
114
+ //#region src/FieldCard/fieldCardVariants.ts
109
115
  const fieldCardVariants = tv({
110
116
  slots: {
111
117
  /** base class for the field card wrapper */
112
118
  base: ["overflow-hidden rounded-small border bg-content1", "transition-colors duration-150 motion-reduce:transition-none"],
113
- /** class for the label/header */
114
- label: [
115
- "pointer-events-auto! static! z-auto! block! w-full!",
116
- "translate-x-0! translate-y-0! transform-none!",
117
- "rounded-t-small border-b p-3 font-semibold text-medium",
118
- "transition-colors duration-150 motion-reduce:transition-none"
119
- ],
120
119
  /** class for the content */
121
120
  content: ["p-3", "grid gap-4"],
122
121
  /** class for the error footer wrapper */
@@ -126,100 +125,160 @@ const fieldCardVariants = tv({
126
125
  "transition-colors duration-150 motion-reduce:transition-none"
127
126
  ],
128
127
  /** class for the error text (empty base, color controlled by variant) */
129
- errorText: []
128
+ errorText: [],
129
+ /** class for the label/header */
130
+ label: [
131
+ "pointer-events-auto! static! z-auto! block! w-full!",
132
+ "translate-x-0! translate-y-0! transform-none!",
133
+ "rounded-t-small border-b p-3 font-semibold text-medium",
134
+ "transition-colors duration-150 motion-reduce:transition-none"
135
+ ]
130
136
  },
131
137
  variants: { invalid: {
132
- true: {
133
- base: "border-danger-200",
134
- label: "border-danger-200 text-danger",
135
- errorFooter: "border-danger-200",
136
- errorText: "!text-danger text-tiny"
137
- },
138
138
  false: {
139
139
  base: "border-divider",
140
- label: "border-divider text-foreground",
141
140
  errorFooter: "border-divider",
142
- errorText: "!text-foreground-500 text-tiny"
141
+ errorText: "!text-foreground-500 text-tiny",
142
+ label: "border-divider text-foreground"
143
+ },
144
+ true: {
145
+ base: "border-danger-200",
146
+ errorFooter: "border-danger-200",
147
+ errorText: "!text-danger text-tiny",
148
+ label: "border-danger-200 text-danger"
143
149
  }
144
150
  } },
145
151
  defaultVariants: { invalid: false }
146
152
  });
153
+ //#endregion
154
+ //#region src/FieldCard/subcomponents/fieldCardValidationErrorVariants.ts
155
+ const fieldCardValidationErrorVariants = tv({ slots: {
156
+ /** Container for card-level validation messages */
157
+ errorMessage: "text-danger text-tiny",
158
+ /** Footer containing card-level validation */
159
+ helperWrapper: "relative flex flex-col gap-1.5 p-0"
160
+ } });
161
+ //#endregion
162
+ //#region src/FieldCard/subcomponents/FieldCardValidationError.tsx
147
163
  /**
148
- * FieldCard component - A card-styled container with label header and error footer
164
+ * Renders validation errors in the footer of a FieldCard component.
149
165
  *
150
- * Displays form field content in a card layout with:
151
- * - Label/title in the header
152
- * - Content in the body
153
- * - Validation errors in the footer
154
- * - Danger outline when validation errors exist
166
+ * This component handles displaying field-level validation errors with proper
167
+ * accessibility attributes and animates them in/out using Framer Motion.
168
+ *
169
+ * Note: Object-level errors (_errors) are always shown when they exist,
170
+ * but the danger styling is controlled by the parent FieldCard based on
171
+ * whether child fields have been touched.
155
172
  */
156
- const FieldCard = ({ children, className: _className = void 0, name, ...uniformFieldProps }) => {
157
- const { error, getLabelProps, label } = useUniformField({
158
- name,
159
- ...uniformFieldProps
173
+ const FieldCardValidationError = ({ className = void 0, error = void 0, errorTextClassName = void 0, errorId, testId }) => {
174
+ const styling = useStyling();
175
+ const disableAnimation = useReducedMotion();
176
+ const variants = styling.resolve(fieldCardValidationErrorVariants);
177
+ const classNames = styling.variantsToClassNames(variants, {
178
+ errorMessage: errorTextClassName,
179
+ helperWrapper: className
160
180
  });
161
- const { control, formState: { touchedFields, submitCount }, validation } = useFormContext();
162
- const validationInstance = validation?.baseInstance ?? validation?.instance;
163
- const registeredFields = Array.from(control._names?.mount ?? []);
164
- const childFieldPrefix = `${name}.`;
165
- const isRequired = validationInstance ? registeredFields.filter((f) => {
166
- return f.startsWith(childFieldPrefix);
167
- }).some((f) => {
168
- return checkFieldIsRequired(validationInstance, f.split(".").filter((k) => {
169
- return k !== "";
170
- }));
171
- }) : false;
172
- const getNestedValue = (obj, path) => {
173
- if (!obj) return;
174
- const keys = path.split(".");
175
- let current = obj;
176
- keys.every((key) => {
177
- if (current && typeof current === "object") {
178
- current = current[key];
179
- return true;
180
- }
181
- current = void 0;
182
- return false;
183
- });
184
- return current;
185
- };
186
- const fieldTouched = getNestedValue(touchedFields, name);
181
+ const objectErrors = error?._errors;
182
+ return /* @__PURE__ */ jsx(AnimatePresence, {
183
+ initial: !disableAnimation,
184
+ children: !!objectErrors ? /* @__PURE__ */ jsx(motion.div, {
185
+ animate: disableAnimation ? void 0 : {
186
+ opacity: 1,
187
+ height: "auto"
188
+ },
189
+ exit: disableAnimation ? void 0 : {
190
+ opacity: 0,
191
+ height: 0
192
+ },
193
+ initial: disableAnimation ? false : {
194
+ height: 0,
195
+ opacity: 0
196
+ },
197
+ style: { overflow: "hidden" },
198
+ transition: {
199
+ duration: .4,
200
+ ease: "circOut"
201
+ },
202
+ children: /* @__PURE__ */ jsx("div", {
203
+ className: classNames.helperWrapper,
204
+ "data-slot": "helper-wrapper",
205
+ children: /* @__PURE__ */ jsx(FieldValidationError, {
206
+ className: { wrapper: classNames.errorMessage },
207
+ error: objectErrors,
208
+ id: errorId,
209
+ testId
210
+ })
211
+ })
212
+ }, "field-card-errors") : null
213
+ });
214
+ };
215
+ //#endregion
216
+ //#region src/FieldCard/subcomponents/FieldCardControl.tsx
217
+ /** Card presentation with an accessible heading, content and animated error footer */
218
+ const FieldCardControl = ({ field, children, className }) => {
219
+ const { ariaLabel, error, ids, invalid, label, required, testId } = field;
220
+ const styling = useStyling();
187
221
  const hasObjectErrors = !!error?._errors;
188
- const errorRecord = error;
189
- const hasChildErrors = hasAnyChildErrors(errorRecord);
190
- const isAnyChildTouched = hasAnyChildTouched(fieldTouched);
191
- const rawShowInvalid = hasChildErrors && (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0) || hasObjectErrors && !hasChildErrors && (isAnyChildTouched || submitCount > 0);
192
- const showInvalid = useDebounce(rawShowInvalid, 200);
193
- const variants = fieldCardVariants({ invalid: showInvalid });
194
- const className = variantsToClassNames(variants, _className, "base");
222
+ const variants = styling.resolve(fieldCardVariants, { invalid });
223
+ const classNames = styling.variantsToClassNames(variants, className, "base");
195
224
  return /* @__PURE__ */ jsxs("div", {
196
- className: className.base,
225
+ "aria-describedby": hasObjectErrors ? ids.error : void 0,
226
+ "aria-label": !label ? ariaLabel : void 0,
227
+ "aria-labelledby": label ? ids.label : void 0,
228
+ className: classNames.base,
229
+ "data-component": "field-card",
230
+ role: "group",
197
231
  children: [
198
- label ? /* @__PURE__ */ jsxs("div", {
199
- ...getLabelProps(),
232
+ label ? /* @__PURE__ */ jsx(FieldLabel, {
200
233
  "aria-level": 3,
201
- className: className.label,
234
+ as: "div",
235
+ className: classNames.label,
236
+ id: ids.label,
237
+ required,
202
238
  role: "heading",
203
- children: [label, isRequired ? /* @__PURE__ */ jsx("span", {
204
- "aria-hidden": "true",
205
- className: "ml-0.5 text-danger",
206
- children: "*"
207
- }) : null]
239
+ children: label
208
240
  }) : null,
209
241
  /* @__PURE__ */ jsx("div", {
210
- className: className.content,
242
+ className: classNames.content,
211
243
  children
212
244
  }),
213
245
  /* @__PURE__ */ jsx(FieldCardValidationError, {
214
- className: className.errorFooter,
246
+ className: classNames.errorFooter,
215
247
  error,
216
- errorTextClassName: className.errorText,
217
- name
248
+ errorId: ids.error,
249
+ errorTextClassName: classNames.errorText,
250
+ testId
218
251
  })
219
252
  ]
220
253
  });
221
254
  };
222
255
  //#endregion
256
+ //#region src/FieldCard/FieldCard.tsx
257
+ /**
258
+ * Groups related form fields in a card with a heading and validation footer
259
+ *
260
+ * Renders nested fields in the body and object-level validation messages in the
261
+ * footer. Individual fields retain their own validation messages
262
+ *
263
+ * The card's required indicator reflects its nested fields, and its danger
264
+ * outline follows child interaction and form submission
265
+ */
266
+ const FieldCard = ({ children, className: _className = void 0, name, ...uniformFieldProps }) => {
267
+ const { field } = useUniformField({
268
+ ...uniformFieldProps,
269
+ name
270
+ });
271
+ const validation = useFieldCardValidation(field);
272
+ return /* @__PURE__ */ jsx(FieldCardControl, {
273
+ className: _className,
274
+ field: {
275
+ ...field,
276
+ ...validation
277
+ },
278
+ children
279
+ });
280
+ };
281
+ //#endregion
223
282
  //#region src/FieldCard/index.ts
224
283
  var FieldCard_default = FieldCard;
225
284
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../../src/FieldCard/FieldCard.tsx","../../src/FieldCard/index.ts"],"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 animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\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 >\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';\nimport { useDebounce } from '@fuf-stack/pixels';\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(touchedFields, name);\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 rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // Debounce to prevent flickering during rapid state changes\n const showInvalid = useDebounce(rawShowInvalid, 200);\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","import FieldCard from './FieldCard';\n\nexport type { FieldCard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AAW,kBAAkB,EAAE,SAAS,YAAY,CAAC;CAC3D,MAAM,YAAY,qBAAqB,UAAU,YAAY,MAAM;CAEnE,OACE,qBAAC,OAAD;EAAK,WAAW,UAAU;EAA1B,UAAA;GAEG,QACC,qBAAC,OAAD;IACE,GAAI,cAAc;IAClB,cAAY;IAGZ,WAAW,UAAU;IACrB,MAAK;IANP,UAAA,CAQG,OAGA,aACC,oBAAC,QAAD;KAAM,eAAY;KAAO,WAAU;KAAqB,UAAA;IAElD,CAAA,IACJ,IACD;GACH,CAAA,IAAA;GAGJ,oBAAC,OAAD;IAAK,WAAW,UAAU;IAAU;GAAc,CAAA;GAGlD,oBAAC,0BAAD;IACE,WAAW,UAAU;IACd;IACP,oBAAoB,UAAU;IACxB;GACP,CAAA;EACE;;AAET;;;AChUA,IAAA,oBAAe"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/FieldCard/fieldCardValidation.ts","../../src/FieldCard/hooks/useFieldCardValidation.ts","../../src/FieldCard/fieldCardVariants.ts","../../src/FieldCard/subcomponents/fieldCardValidationErrorVariants.ts","../../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../../src/FieldCard/subcomponents/FieldCardControl.tsx","../../src/FieldCard/FieldCard.tsx","../../src/FieldCard/index.ts"],"sourcesContent":["/**\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\n/** Reads nested child touched state for a dotted field path */\nexport 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","import type { UniformField } from '../../hooks/useUniformField/types';\n\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport {\n checkFieldIsRequired,\n useFormContext,\n} from '../../hooks/useFormContext';\nimport {\n getNestedValue,\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from '../fieldCardValidation';\n\n/**\n * Derives the card's required and invalid states from its nested fields\n *\n * A card groups independently registered inputs, so its own field state does\n * not tell us whether a child is required or which child errors are visible\n * Required state comes from registered descendants and their validation schema\n *\n * Child errors become visible after that child is touched or the form is submitted\n * Object-level errors follow child interaction or submission when no child errors\n * exist, so they do not reveal untouched child failures early\n *\n * Debounces invalid-state changes to prevent flickering during validation updates\n */\nconst useFieldCardValidation = (\n field: Pick<UniformField, 'error' | 'name'>,\n) => {\n const { error, name } = field;\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // inspect registered children for required fields\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 // resolve touched state for nested children\n const fieldTouched = getNestedValue(touchedFields, name);\n\n // retain object-level errors alongside child 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 const hasChildErrors = hasAnyChildErrors(errorRecord);\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // reveal child errors after interaction or submission\n const rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // prevent flickering during rapid validation updates\n const showInvalid = useDebounce(rawShowInvalid, 200);\n\n return { invalid: showInvalid, required: isRequired };\n};\n\nexport default useFieldCardValidation;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\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 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 /** class for the label/header */\n label: [\n // keep the label in normal flow at full width\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 },\n variants: {\n invalid: {\n false: {\n base: 'border-divider',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n label: 'border-divider text-foreground',\n },\n true: {\n base: 'border-danger-200',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n label: 'border-danger-200 text-danger',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\nexport type ClassName = TVClassName<typeof fieldCardVariants>;\n","import { tv } from '@fuf-stack/pixel-utils';\n\nconst fieldCardValidationErrorVariants = tv({\n slots: {\n /** Container for card-level validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Footer containing card-level validation */\n helperWrapper: 'relative flex flex-col gap-1.5 p-0',\n },\n});\n\nexport default fieldCardValidationErrorVariants;\n","import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\nimport fieldCardValidationErrorVariants from './fieldCardValidationErrorVariants';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** Optional error association ID supplied by the owning group. */\n errorId: string;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** HTML data-testid attribute for e2e tests */\n testId: 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 errorId,\n testId,\n}: FieldCardValidationErrorProps) => {\n const styling = useStyling();\n const disableAnimation = useReducedMotion();\n\n // classNames from slots\n const variants = styling.resolve(fieldCardValidationErrorVariants);\n const classNames = styling.variantsToClassNames(variants, {\n errorMessage: errorTextClassName,\n helperWrapper: className,\n });\n\n // show object-level errors whenever they exist\n const objectErrors = (error as unknown as { _errors?: FieldError[] })\n ?._errors;\n const hasErrors = !!objectErrors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\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 >\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldValidationError\n className={{ wrapper: classNames.errorMessage }}\n error={objectErrors}\n id={errorId}\n testId={testId}\n />\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldCardProps } from '../FieldCard';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { fieldCardVariants } from '../fieldCardVariants';\nimport FieldCardValidationError from './FieldCardValidationError';\n\ninterface FieldCardControlProps extends Pick<\n FieldCardProps,\n 'children' | 'className'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField;\n}\n\n/** Card presentation with an accessible heading, content and animated error footer */\nconst FieldCardControl = ({\n field,\n children,\n className,\n}: FieldCardControlProps) => {\n const { ariaLabel, error, ids, invalid, label, required, testId } = field;\n\n const styling = useStyling();\n\n // @ts-expect-error - object-level errors include an _errors property\n const hasObjectErrors = !!error?._errors;\n\n // classNames from slots\n const variants = styling.resolve(fieldCardVariants, { invalid });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n return (\n <div\n aria-describedby={hasObjectErrors ? ids.error : undefined}\n aria-label={!label ? ariaLabel : undefined}\n aria-labelledby={label ? ids.label : undefined}\n className={classNames.base}\n data-component=\"field-card\"\n role=\"group\"\n >\n {/* card header with label */}\n {label ? (\n <FieldLabel\n aria-level={3}\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n role=\"heading\"\n >\n {label}\n </FieldLabel>\n ) : null}\n\n {/* card content */}\n <div className={classNames.content}>{children}</div>\n\n {/* card footer with object-level validation messages */}\n <FieldCardValidationError\n className={classNames.errorFooter}\n error={error}\n errorId={ids.error}\n errorTextClassName={classNames.errorText}\n testId={testId}\n />\n </div>\n );\n};\n\nexport default FieldCardControl;\n","import type { ReactNode } from 'react';\nimport type { ClassName } from './fieldCardVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport useFieldCardValidation from './hooks/useFieldCardValidation';\nimport FieldCardControl from './subcomponents/FieldCardControl';\n\nexport { fieldCardVariants } from './fieldCardVariants';\nexport {\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from './fieldCardValidation';\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Field label */\n label: ReactNode;\n /** Field name */\n name: string;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n}\n\n/**\n * Groups related form fields in a card with a heading and validation footer\n *\n * Renders nested fields in the body and object-level validation messages in the\n * footer. Individual fields retain their own validation messages\n *\n * The card's required indicator reflects its nested fields, and its danger\n * outline follows child interaction and form submission\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { field } = useUniformField({\n ...uniformFieldProps,\n name,\n });\n\n const validation = useFieldCardValidation(field);\n\n return (\n <FieldCardControl\n className={_className}\n field={{ ...field, ...validation }}\n >\n {children}\n </FieldCardControl>\n );\n};\n\nexport default FieldCard;\n","import FieldCard from './FieldCard';\n\nexport type { FieldCardProps } from './FieldCard';\n\nexport { fieldCardVariants } from './FieldCard';\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;AAIA,MAAa,qBACX,WACY;CACZ,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,KAAK,MAAM,CAAC,CACvB,QAAQ,QAAQ;EACf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,aAAa,OAAO;EAC1B,IAAI,eAAe,KAAA,GACjB,OAAO;EAGT,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO;EAGT,IAAI,OAAO,eAAe,YAAY,eAAe,MACnD,OAAO,kBAAkB,UAAqC;EAEhE,OAAO;CACT,CAAC;AACL;;;;;AAMA,MAAa,sBACX,YACY;CACZ,IAAI,CAAC,SACH,OAAO;CAGT,OAAO,OAAO,KAAK,OAAO,CAAC,CACxB,QAAQ,Q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IACtB,IAAI,IAAI;IACE;IACV,MAAK;IAEJ,UAAA;GACS,CAAA,IACV;GAGJ,oBAAC,OAAD;IAAK,WAAW,WAAW;IAAU;GAAc,CAAA;GAGnD,oBAAC,0BAAD;IACE,WAAW,WAAW;IACf;IACP,SAAS,IAAI;IACb,oBAAoB,WAAW;IACvB;GACT,CAAA;EACE;;AAET;;;;;;;;;;;;AClCA,MAAM,aAAa,EACjB,UACA,WAAW,aAAa,KAAA,GACxB,MACA,GAAG,wBACiB;CACpB,MAAM,EAAE,UAAU,gBAAgB;EAChC,GAAG;EACH;CACF,CAAC;CAED,MAAM,aAAa,uBAAuB,KAAK;CAE/C,OACE,oBAAC,kBAAD;EACE,WAAW;EACX,OAAO;GAAE,GAAG;GAAO,GAAG;EAAW;EAEhC;CACe,CAAA;AAEtB;;;ACnDA,IAAA,oBAAe"}
@@ -1,9 +1,10 @@
1
- import { cn } from "@fuf-stack/pixel-utils";
2
1
  import { Button } from "@fuf-stack/pixels";
3
2
  import { jsx } from "react/jsx-runtime";
4
3
  import { FaBullseye } from "react-icons/fa6";
4
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
5
5
  //#region src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx
6
6
  const FieldCopyTestIdButton = ({ className = void 0, testId }) => {
7
+ const { cn } = useStyling();
7
8
  const copyToClipboard = () => {
8
9
  navigator.clipboard.writeText(testId).catch((err) => {
9
10
  console.error("Error copying TestId to clipboard", err);
@@ -11,6 +12,7 @@ const FieldCopyTestIdButton = ({ className = void 0, testId }) => {
11
12
  };
12
13
  return /* @__PURE__ */ jsx(Button, {
13
14
  className: cn(className, "pointer-events-auto"),
15
+ dataComponent: "field-copy-test-id-button",
14
16
  icon: /* @__PURE__ */ jsx(FaBullseye, {}),
15
17
  onClick: copyToClipboard,
16
18
  size: "sm",
@@ -23,4 +25,4 @@ var FieldCopyTestIdButton_default = FieldCopyTestIdButton;
23
25
  //#endregion
24
26
  export { FieldCopyTestIdButton_default as t };
25
27
 
26
- //# sourceMappingURL=FieldCopyTestIdButton-9xTF-DBW.mjs.map
28
+ //# sourceMappingURL=FieldCopyTestIdButton-DV0tkdh2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldCopyTestIdButton-DV0tkdh2.mjs","names":[],"sources":["../src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx","../src/partials/FieldCopyTestIdButton/index.ts"],"sourcesContent":["import { FaBullseye } from 'react-icons/fa6';\n\nimport { Button } from '@fuf-stack/pixels';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nexport interface FieldCopyTestIdButtonProps {\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId: string;\n}\n\nconst FieldCopyTestIdButton = ({\n className = undefined,\n testId,\n}: FieldCopyTestIdButtonProps) => {\n const { cn } = useStyling();\n const copyToClipboard = () => {\n // This component runs in the browser; the Node compatibility rule cannot\n // distinguish the DOM Clipboard API from Node's global navigator.\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n navigator.clipboard.writeText(testId).catch((err) => {\n console.error('Error copying TestId to clipboard', err);\n });\n };\n\n return (\n <Button\n className={cn(className, 'pointer-events-auto')}\n dataComponent=\"field-copy-test-id-button\"\n icon={<FaBullseye />}\n onClick={copyToClipboard}\n size=\"sm\"\n variant=\"light\"\n />\n );\n};\nexport default FieldCopyTestIdButton;\n","import FieldCopyTestIdButton from './FieldCopyTestIdButton';\n\nexport type { FieldCopyTestIdButtonProps } from './FieldCopyTestIdButton';\n\nexport default FieldCopyTestIdButton;\n"],"mappings":";;;;;AAYA,MAAM,yBAAyB,EAC7B,YAAY,KAAA,GACZ,aACgC;CAChC,MAAM,EAAE,OAAO,WAAW;CAC1B,MAAM,wBAAwB;EAI5B,UAAU,UAAU,UAAU,MAAM,CAAC,CAAC,OAAO,QAAQ;GACnD,QAAQ,MAAM,qCAAqC,GAAG;EACxD,CAAC;CACH;CAEA,OACE,oBAAC,QAAD;EACE,WAAW,GAAG,WAAW,qBAAqB;EAC9C,eAAc;EACd,MAAM,oBAAC,YAAD,CAAa,CAAA;EACnB,SAAS;EACT,MAAK;EACL,SAAQ;CACT,CAAA;AAEL;;;AChCA,IAAA,gCAAe"}
@@ -0,0 +1,36 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ //#region src/helpers/fieldProps/fieldProps.ts
3
+ /** Shared styling attributes for field state, inactive flags are omitted */
4
+ const getFieldDataAttributes = ({ disabled, invalid, required }) => {
5
+ return {
6
+ "data-disabled": disabled ? true : void 0,
7
+ "data-invalid": invalid ? true : void 0,
8
+ "data-required": required ? true : void 0
9
+ };
10
+ };
11
+ /** ID and ARIA associations for the editable control or selection group */
12
+ const getFieldControlProps = ({ ariaLabel, customAriaLabel, description, hasErrors, hasLabel, ids, invalid, required }) => {
13
+ return {
14
+ id: ids.control,
15
+ "aria-label": customAriaLabel ?? (!hasLabel ? ariaLabel : void 0),
16
+ "aria-labelledby": !customAriaLabel && hasLabel ? ids.label : void 0,
17
+ "aria-describedby": [description ? ids.description : void 0, invalid && hasErrors ? ids.error : void 0].filter(Boolean).join(" ") || void 0,
18
+ "aria-invalid": invalid || void 0,
19
+ "aria-required": required || void 0
20
+ };
21
+ };
22
+ //#endregion
23
+ //#region src/partials/FieldDescription/FieldDescription.tsx
24
+ /** Help text associated with a field through its description ID */
25
+ const FieldDescription = ({ children, ...props }) => {
26
+ if (!children) return null;
27
+ return /* @__PURE__ */ jsx("div", {
28
+ "data-slot": "description",
29
+ ...props,
30
+ children
31
+ });
32
+ };
33
+ //#endregion
34
+ export { getFieldControlProps as n, getFieldDataAttributes as r, FieldDescription as t };
35
+
36
+ //# sourceMappingURL=FieldDescription-C4l0HKGL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldDescription-C4l0HKGL.mjs","names":[],"sources":["../src/helpers/fieldProps/fieldProps.ts","../src/partials/FieldDescription/FieldDescription.tsx"],"sourcesContent":["import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldControlProps } from '../../partials/types';\n\ninterface FieldDataState {\n /** Disables interaction with the field */\n disabled?: boolean;\n /** Marks visible validation failure */\n invalid?: boolean;\n /** Marks a required field */\n required?: boolean;\n}\n\n/** Shared styling attributes for field state, inactive flags are omitted */\nexport const getFieldDataAttributes = ({\n disabled,\n invalid,\n required,\n}: FieldDataState) => {\n return {\n 'data-disabled': disabled ? true : undefined,\n 'data-invalid': invalid ? true : undefined,\n 'data-required': required ? true : undefined,\n };\n};\n\n/** Field metadata needed to associate an editable control with its content */\ntype FieldControlState = Pick<\n UniformField,\n | 'ariaLabel'\n | 'customAriaLabel'\n | 'description'\n | 'hasErrors'\n | 'hasLabel'\n | 'ids'\n | 'invalid'\n | 'required'\n>;\n\n/** ID and ARIA associations for the editable control or selection group */\nexport const getFieldControlProps = ({\n ariaLabel,\n customAriaLabel,\n description,\n hasErrors,\n hasLabel,\n ids,\n invalid,\n required,\n}: FieldControlState): FieldControlProps => {\n return {\n id: ids.control,\n 'aria-label': customAriaLabel ?? (!hasLabel ? ariaLabel : undefined),\n 'aria-labelledby': !customAriaLabel && hasLabel ? ids.label : undefined,\n 'aria-describedby':\n [\n description ? ids.description : undefined,\n invalid && hasErrors ? ids.error : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n 'aria-invalid': invalid || undefined,\n 'aria-required': required || undefined,\n };\n};\n","import type { HTMLAttributes, ReactNode } from 'react';\n\ninterface FieldDescriptionProps extends HTMLAttributes<HTMLDivElement> {\n /** Help text */\n children: ReactNode;\n /** CSS class name */\n className?: string;\n}\n\n/** Help text associated with a field through its description ID */\nconst FieldDescription = ({ children, ...props }: FieldDescriptionProps) => {\n if (!children) {\n return null;\n }\n\n return (\n <div data-slot=\"description\" {...props}>\n {children}\n </div>\n );\n};\n\nexport default FieldDescription;\n"],"mappings":";;;AAaA,MAAa,0BAA0B,EACrC,UACA,SACA,eACoB;CACpB,OAAO;EACL,iBAAiB,WAAW,OAAO,KAAA;EACnC,gBAAgB,UAAU,OAAO,KAAA;EACjC,iBAAiB,WAAW,OAAO,KAAA;CACrC;AACF;;AAgBA,MAAa,wBAAwB,EACnC,WACA,iBACA,aACA,WACA,UACA,KACA,SACA,eAC0C;CAC1C,OAAO;EACL,IAAI,IAAI;EACR,cAAc,oBAAoB,CAAC,WAAW,YAAY,KAAA;EAC1D,mBAAmB,CAAC,mBAAmB,WAAW,IAAI,QAAQ,KAAA;EAC9D,oBACE,CACE,cAAc,IAAI,cAAc,KAAA,GAChC,WAAW,YAAY,IAAI,QAAQ,KAAA,CACrC,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;EAClB,gBAAgB,WAAW,KAAA;EAC3B,iBAAiB,YAAY,KAAA;CAC/B;AACF;;;;ACrDA,MAAM,oBAAoB,EAAE,UAAU,GAAG,YAAmC;CAC1E,IAAI,CAAC,UACH,OAAO;CAGT,OACE,oBAAC,OAAD;EAAK,aAAU;EAAc,GAAI;EAC9B;CACE,CAAA;AAET"}