@fuf-stack/uniform 1.27.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 (149) hide show
  1. package/README.md +9 -0
  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 +1282 -500
  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-CRJBix9D.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +5 -3
  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 +11 -11
  29. package/dist/Form/index.d.mts.map +1 -1
  30. package/dist/Form/index.mjs +14 -11
  31. package/dist/Form/index.mjs.map +1 -1
  32. package/dist/FormContext-CHctWFAP.mjs +520 -0
  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 +640 -392
  39. package/dist/Input/index.d.mts.map +1 -1
  40. package/dist/Input/index.mjs +421 -76
  41. package/dist/Input/index.mjs.map +1 -1
  42. package/dist/RadioBoxes/index.d.mts +1583 -120
  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 +1353 -108
  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 +558 -3013
  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 +414 -1326
  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 +139 -43
  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-CK39i6HI.mjs → useController-BCFeZbBZ.mjs} +2 -2
  116. package/dist/{useController-CK39i6HI.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
  117. package/dist/{useFormContext-fYWtlnpE.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
  118. package/dist/{useFormContext-fYWtlnpE.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-CRJBix9D.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-gHSwOlcy.mjs +0 -278
  126. package/dist/FormContext-gHSwOlcy.mjs.map +0 -1
  127. package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
  128. package/dist/Switch/index.d.mts.map +0 -1
  129. package/dist/hooks/useInput/index.d.mts +0 -2
  130. package/dist/hooks/useInput/index.mjs +0 -7
  131. package/dist/hooks/useInput/index.mjs.map +0 -1
  132. package/dist/hooks/useUniformField/index.d.mts +0 -98
  133. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  134. package/dist/hooks/useUniformField/index.mjs +0 -137
  135. package/dist/hooks/useUniformField/index.mjs.map +0 -1
  136. package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
  137. package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
  138. package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
  139. package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
  140. package/dist/index-CAdGtKE_.d.mts +0 -1
  141. package/dist/index-CaxrMD1A.d.mts +0 -1
  142. package/dist/index-D5HVU2jP.d.mts +0 -1
  143. package/dist/useController-DcK2YHbw.d.mts +0 -32
  144. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  145. package/dist/useFormContext-B3QGVVaO.d.mts +0 -66
  146. package/dist/useFormContext-B3QGVVaO.d.mts.map +0 -1
  147. package/dist/useInput-C0aJaAGe.mjs +0 -2
  148. package/dist/useInput-ClpHDPdr.d.mts +0 -2
  149. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1,22 +1,206 @@
1
- import { flatArrayKey } from "../helpers/index.mjs";
2
- import { n as FieldValidationError } from "../FieldValidationError-ByRoIxaM.mjs";
3
- import { useUniformField } from "../hooks/useUniformField/index.mjs";
4
- import { useUniformFieldArray } from "../hooks/useUniformFieldArray/index.mjs";
5
- import { t as Grid_default } from "../Grid-CTs-Rb9G.mjs";
6
- import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
7
- import { useState } from "react";
1
+ import { flatArrayKey, isValueEmpty } from "../helpers/index.mjs";
2
+ import { n as FieldValidationError } from "../FieldValidationError-DgkCL3cC.mjs";
3
+ import { n as useFormContext$1 } from "../useFormContext-BPjJjNnM.mjs";
4
+ import { n as useUniformField, t as FieldLabel } from "../FieldLabel-DKzqkuY1.mjs";
5
+ import { useWatchFormReset } from "../hooks/useWatchFormReset/index.mjs";
6
+ import { t as Grid_default } from "../Grid-DfcZeuib.mjs";
7
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
8
8
  import { Button, Menu } from "@fuf-stack/pixels";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { tv } from "@fuf-stack/pixel-utils";
11
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
10
12
  import { AnimatePresence, motion, useReducedMotion } from "@fuf-stack/pixel-motion";
11
- import { useFormContext } from "react-hook-form";
13
+ import { useFieldArray } from "react-hook-form";
12
14
  import { FaCopy, FaGripVertical, FaPlus, FaTimes } from "react-icons/fa";
13
15
  import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
14
16
  import { CSS } from "@dnd-kit/utilities";
15
17
  import { VscInsert } from "react-icons/vsc";
16
18
  import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors } from "@dnd-kit/core";
17
19
  import { restrictToVerticalAxis, restrictToWindowEdges } from "@dnd-kit/modifiers";
20
+ //#region src/hooks/useUniformFieldArray/useUniformFieldArray.ts
21
+ /**
22
+ * Enhanced useFieldArray hook with initialization and animation logic.
23
+ * Based on React Hook Form's useFieldArray with additional features:
24
+ * - Automatic initialization when lastElementNotRemovable is set
25
+ * - Reset-only normalization for stale empty placeholder rows (via useWatchFormReset)
26
+ * - Animation control (disabled during initialization)
27
+ * - Temporary animation disable during reset normalization collapse
28
+ * - Support for flat arrays (arrays of primitives)
29
+ *
30
+ * Note: Automatic validation triggering on length change is disabled to prevent
31
+ * triggering form-wide validation. Array validation still runs on form submission.
32
+ *
33
+ * @see https://react-hook-form.com/docs/usefieldarray
34
+ */
35
+ const useUniformFieldArrayMethods = ({ name, flat = false, elementInitialValue: _elementInitialValue = null, lastElementNotRemovable = false }, uniformField) => {
36
+ const { control } = uniformField;
37
+ const { fields, append, remove, insert, move, replace } = useFieldArray({
38
+ control,
39
+ name
40
+ });
41
+ const { trigger, setValue, getValues } = useFormContext$1();
42
+ const needsInitialize = useMemo(() => {
43
+ return lastElementNotRemovable && fields.length === 0;
44
+ }, [lastElementNotRemovable, fields.length]);
45
+ const hasInitialized = useRef(!needsInitialize);
46
+ useEffect(() => {
47
+ if (needsInitialize) hasInitialized.current = false;
48
+ }, [needsInitialize]);
49
+ useEffect(() => {
50
+ if (hasInitialized.current) setTimeout(() => {
51
+ trigger(name);
52
+ }, 200);
53
+ }, [fields.length]);
54
+ const [disableAnimation, setDisableAnimation] = useState(true);
55
+ const prefersReducedMotion = useReducedMotion();
56
+ useEffect(() => {
57
+ if (hasInitialized.current) setDisableAnimation(!!prefersReducedMotion);
58
+ }, [prefersReducedMotion]);
59
+ const elementInitialValue = useMemo(() => {
60
+ return flat ? { [flatArrayKey]: _elementInitialValue ?? null } : _elementInitialValue ?? {};
61
+ }, [flat, _elementInitialValue]);
62
+ useWatchFormReset({ onReset: () => {
63
+ const currentValue = getValues(name);
64
+ const valueIsArray = Array.isArray(currentValue);
65
+ const arrayValue = valueIsArray ? currentValue : [];
66
+ const normalizedLength = lastElementNotRemovable ? 1 : 0;
67
+ const alreadyNormalized = valueIsArray && arrayValue.length === normalizedLength;
68
+ if (!(!valueIsArray || arrayValue.length === 0 || arrayValue.every((entry) => {
69
+ return isValueEmpty(entry);
70
+ }))) return;
71
+ if (alreadyNormalized) return;
72
+ setDisableAnimation(true);
73
+ replace(lastElementNotRemovable ? [elementInitialValue] : []);
74
+ if (!prefersReducedMotion) setTimeout(() => {
75
+ setDisableAnimation(false);
76
+ }, 1);
77
+ } });
78
+ useEffect(() => {
79
+ if (needsInitialize) {
80
+ setValue(name, [elementInitialValue], {
81
+ shouldDirty: false,
82
+ shouldTouch: false
83
+ });
84
+ hasInitialized.current = true;
85
+ if (!prefersReducedMotion && disableAnimation) setTimeout(() => {
86
+ setDisableAnimation(false);
87
+ }, 1);
88
+ }
89
+ }, [needsInitialize]);
90
+ const { testId } = uniformField.field;
91
+ const items = fields.map((row, index) => {
92
+ const elementName = flat ? `${name}.${index}.${flatArrayKey}` : `${name}.${index}`;
93
+ const elementTestId = `${testId}_${index}`;
94
+ return {
95
+ id: row.id,
96
+ renderProps: {
97
+ index,
98
+ length: fields.length,
99
+ methods: {
100
+ append: () => {
101
+ append(elementInitialValue);
102
+ },
103
+ duplicate: () => {
104
+ const currentValue = getValues(name)[index];
105
+ insert(index + 1, flat ? { [flatArrayKey]: currentValue } : currentValue);
106
+ },
107
+ insert: () => {
108
+ insert(index + 1, elementInitialValue);
109
+ },
110
+ remove: () => {
111
+ remove(index);
112
+ }
113
+ },
114
+ name: elementName,
115
+ testId: elementTestId
116
+ }
117
+ };
118
+ });
119
+ const appendItem = () => {
120
+ append(elementInitialValue);
121
+ };
122
+ const moveItem = (from, to) => {
123
+ move(from, to);
124
+ trigger(name);
125
+ };
126
+ return {
127
+ fields,
128
+ append,
129
+ appendItem,
130
+ items,
131
+ remove,
132
+ insert,
133
+ move,
134
+ moveItem,
135
+ disableAnimation,
136
+ elementInitialValue,
137
+ ...uniformField
138
+ };
139
+ };
140
+ const useUniformFieldArray = (params) => {
141
+ const field = useUniformField({
142
+ ...params,
143
+ name: params.name
144
+ });
145
+ return useUniformFieldArrayMethods(params, field);
146
+ };
147
+ //#endregion
148
+ //#region src/FieldArray/fieldArrayVariants.ts
149
+ const fieldArrayVariants = tv({
150
+ slots: {
151
+ /** class for the actions menu button */
152
+ actionsMenuButton: [
153
+ "flex items-center justify-center text-default-600",
154
+ "h-full rounded-none",
155
+ "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
156
+ ],
157
+ /** class for the append button */
158
+ appendButton: [
159
+ "w-full justify-start rounded-b-small rounded-t-none font-semibold",
160
+ "!h-[48px] !min-h-0",
161
+ "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
162
+ ],
163
+ /** base class for the field array wrapper */
164
+ base: ["overflow-hidden rounded-small border border-divider bg-content1", "divide-y divide-divider"],
165
+ /** class for the element fields grid */
166
+ elementFieldsGrid: ["w-full grow p-3"],
167
+ /** class for the label */
168
+ label: [
169
+ "pointer-events-auto! static! z-auto! block! w-full!",
170
+ "translate-x-0! translate-y-0! transform-none!",
171
+ "rounded-t-small p-3 font-semibold text-medium"
172
+ ],
173
+ /** class for the list */
174
+ list: ["overflow-hidden"],
175
+ /** class for the list item (performs motion animations) */
176
+ listItem: ["group relative flex flex-row", "first:-mt-px"],
177
+ /** class for the list item inner */
178
+ listItemInner: ["flex w-full flex-row items-stretch divide-divider bg-content1", "divide-x divide-solid border-b border-t border-divider"],
179
+ /** class for the list wrapper */
180
+ listWrapper: ["overflow-hidden"],
181
+ /** class for the remove button */
182
+ removeButton: [
183
+ "flex items-center justify-center",
184
+ "!h-full !min-h-0 !rounded-none px-3",
185
+ "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
186
+ ],
187
+ /** class for the sort drag handle */
188
+ sortDragHandle: [
189
+ "flex cursor-grab items-center justify-center px-2 text-default-600 transition-colors",
190
+ "hover:bg-default-100 active:cursor-grabbing group-data-[dragging=true]:bg-default-100",
191
+ "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
192
+ ]
193
+ },
194
+ variants: { hasLabel: { false: {
195
+ actionsMenuButton: "group-[:first-child]:!rounded-tr-small group-[:first-child]:group-data-[dragging=true]:!rounded-tr-none",
196
+ removeButton: "group-[:first-child]:!rounded-tr-small group-[:first-child]:group-data-[dragging=true]:!rounded-tr-none",
197
+ sortDragHandle: "group-[:first-child]:rounded-tl-small group-[:first-child]:group-data-[dragging=true]:rounded-tl-none"
198
+ } } }
199
+ });
200
+ //#endregion
18
201
  //#region src/FieldArray/subcomponents/ElementAppendButton.tsx
19
202
  const ElementAppendButton = ({ appendButtonText = "Add Element", className = void 0, onClick, testId = void 0 }) => {
203
+ const { cn } = useStyling();
20
204
  return /* @__PURE__ */ jsxs(Button, {
21
205
  className: cn(className),
22
206
  disableAnimation: true,
@@ -33,6 +217,7 @@ const ElementAppendButton = ({ appendButtonText = "Add Element", className = voi
33
217
  * Menu component for field array element actions (remove, duplicate, insert after)
34
218
  */
35
219
  const ElementActionsMenu = ({ className = void 0, duplicate = false, insertAfter = false, showRemove = true, methods, testId = void 0 }) => {
220
+ const { cn } = useStyling();
36
221
  const handleAction = (key) => {
37
222
  switch (key) {
38
223
  case "remove":
@@ -78,6 +263,7 @@ const ElementActionsMenu = ({ className = void 0, duplicate = false, insertAfter
78
263
  //#endregion
79
264
  //#region src/FieldArray/subcomponents/ElementRemoveButton.tsx
80
265
  const ElementRemoveButton = ({ className = void 0, disableAnimation = false, onClick, testId = void 0 }) => {
266
+ const { cn } = useStyling();
81
267
  const button = /* @__PURE__ */ jsx(Button, {
82
268
  ariaLabel: "remove element",
83
269
  className: cn(className),
@@ -114,12 +300,14 @@ const ElementRemoveButton = ({ className = void 0, disableAnimation = false, onC
114
300
  * Renders a vertical grip icon that can be used to reorder items.
115
301
  */
116
302
  const SortDragHandle = ({ className = void 0, id, testId = void 0 }) => {
303
+ const { cn } = useStyling();
117
304
  const { attributes, listeners } = useSortable({ id });
118
305
  return /* @__PURE__ */ jsx("div", {
119
306
  className: cn(className),
120
307
  "data-testid": testId,
121
308
  ...attributes,
122
309
  ...listeners,
310
+ "aria-label": "Reorder item",
123
311
  children: /* @__PURE__ */ jsx(FaGripVertical, {})
124
312
  });
125
313
  };
@@ -131,18 +319,53 @@ const SortDragHandle = ({ className = void 0, id, testId = void 0 }) => {
131
319
  * improve the user experience and provide a better visual feedback.
132
320
  */
133
321
  const FieldArrayElement = ({ children, className, disableAnimation = false, duplicate = false, elementMarginBottom: _elementMarginBottom = void 0, fields, id, index: _index, insertAfter = false, lastNotDeletable = true, methods, sortable = false, testId = void 0 }) => {
322
+ const { cn } = useStyling();
134
323
  const { setNodeRef, transform, transition, isDragging } = useSortable({ id });
324
+ const [isVisible, setIsVisible] = useState(true);
135
325
  const sortingStyle = sortable ? {
136
326
  transform: CSS.Translate.toString(transform),
137
327
  transition,
138
328
  zIndex: isDragging ? 50 : void 0
139
329
  } : void 0;
140
- const [isVisible, setIsVisible] = useState(true);
330
+ const listItemMotionVariants = {
331
+ hidden: {
332
+ opacity: 0,
333
+ height: 0,
334
+ marginBottom: 0
335
+ },
336
+ visible: {
337
+ opacity: 1,
338
+ height: "auto",
339
+ transition: {
340
+ duration: .2,
341
+ ease: "circOut"
342
+ },
343
+ marginBottom: "-1px"
344
+ },
345
+ exit: {
346
+ opacity: 0,
347
+ height: 0,
348
+ marginBottom: 0,
349
+ transition: {
350
+ opacity: {
351
+ duration: .1,
352
+ ease: "circOut"
353
+ },
354
+ height: {
355
+ delay: .1,
356
+ duration: .2,
357
+ ease: "circOut"
358
+ }
359
+ }
360
+ }
361
+ };
362
+ const handleRemove = () => {
363
+ if (disableAnimation) methods.remove();
364
+ else setIsVisible(false);
365
+ };
141
366
  return /* @__PURE__ */ jsx(AnimatePresence, {
142
367
  mode: "wait",
143
- onExitComplete: () => {
144
- methods.remove();
145
- },
368
+ onExitComplete: methods.remove,
146
369
  children: isVisible ? /* @__PURE__ */ jsx(motion.li, {
147
370
  ref: setNodeRef,
148
371
  animate: disableAnimation ? void 0 : "visible",
@@ -152,38 +375,7 @@ const FieldArrayElement = ({ children, className, disableAnimation = false, dupl
152
375
  exit: disableAnimation ? void 0 : "exit",
153
376
  initial: disableAnimation ? false : "hidden",
154
377
  style: sortingStyle,
155
- variants: disableAnimation ? void 0 : {
156
- hidden: {
157
- opacity: 0,
158
- height: 0,
159
- marginBottom: 0
160
- },
161
- visible: {
162
- opacity: 1,
163
- height: "auto",
164
- transition: {
165
- duration: .2,
166
- ease: "circOut"
167
- },
168
- marginBottom: "-1px"
169
- },
170
- exit: {
171
- opacity: 0,
172
- height: 0,
173
- marginBottom: 0,
174
- transition: {
175
- opacity: {
176
- duration: .1,
177
- ease: "circOut"
178
- },
179
- height: {
180
- delay: .1,
181
- duration: .2,
182
- ease: "circOut"
183
- }
184
- }
185
- }
186
- },
378
+ variants: disableAnimation ? void 0 : listItemMotionVariants,
187
379
  children: /* @__PURE__ */ jsxs("div", {
188
380
  className: cn(className.listItemInner),
189
381
  children: [
@@ -203,10 +395,7 @@ const FieldArrayElement = ({ children, className, disableAnimation = false, dupl
203
395
  insertAfter,
204
396
  methods: {
205
397
  ...methods,
206
- remove: () => {
207
- if (disableAnimation) methods.remove();
208
- else setIsVisible(false);
209
- }
398
+ remove: handleRemove
210
399
  },
211
400
  showRemove: !(lastNotDeletable && fields.length === 1),
212
401
  testId: `${testId}_actions_menu`
@@ -215,10 +404,7 @@ const FieldArrayElement = ({ children, className, disableAnimation = false, dupl
215
404
  children: lastNotDeletable && fields.length === 1 ? null : /* @__PURE__ */ jsx(ElementRemoveButton, {
216
405
  className: className.removeButton,
217
406
  disableAnimation,
218
- onClick: () => {
219
- if (disableAnimation) methods.remove();
220
- else setIsVisible(false);
221
- },
407
+ onClick: handleRemove,
222
408
  testId: `${testId}_remove_button`
223
409
  }, "remove-button")
224
410
  }) })
@@ -233,24 +419,32 @@ const FieldArrayElement = ({ children, className, disableAnimation = false, dupl
233
419
  * Renders the label for a FieldArray component.
234
420
  *
235
421
  * This component handles displaying the array label with proper accessibility
236
- * attributes using the label props from useUniformField.
422
+ * attributes using owned heading markup and field state.
237
423
  */
238
- const FieldArrayLabel = ({ className = void 0, label: _label, name }) => {
239
- const { error, getLabelProps, invalid, label } = useUniformField({
240
- name,
241
- label: _label
242
- });
243
- if (!_label) return null;
244
- const hasErrors = invalid && error?._errors;
245
- return /* @__PURE__ */ jsx("div", {
246
- ...getLabelProps(),
424
+ const FieldArrayLabel = ({ className = void 0, id = void 0, label, invalid, required }) => {
425
+ const { cn } = useStyling();
426
+ if (!label) return null;
427
+ const hasErrors = invalid;
428
+ return /* @__PURE__ */ jsx(FieldLabel, {
247
429
  "aria-level": 3,
248
- className: cn(getLabelProps()?.className, className, { "text-foreground!": !hasErrors }),
430
+ as: "div",
431
+ className: cn("block max-w-full overflow-hidden text-ellipsis subpixel-antialiased text-small", hasErrors ? "text-danger!" : void 0, className, { "text-foreground!": !hasErrors }),
432
+ id,
433
+ required,
434
+ requiredClassName: "ms-0.5 text-danger",
249
435
  role: "heading",
250
436
  children: label
251
437
  });
252
438
  };
253
439
  //#endregion
440
+ //#region src/FieldArray/subcomponents/fieldArrayValidationErrorVariants.ts
441
+ const fieldArrayValidationErrorVariants = tv({ slots: {
442
+ /** Container for array-level validation messages */
443
+ errorMessage: "text-danger text-tiny",
444
+ /** Padded footer containing array-level validation */
445
+ helperWrapper: ["relative flex-col gap-1.5", "block px-3 pb-2 pt-1"]
446
+ } });
447
+ //#endregion
254
448
  //#region src/FieldArray/subcomponents/FieldArrayValidationError.tsx
255
449
  /**
256
450
  * Renders array-level validation errors for FieldArray.
@@ -262,13 +456,15 @@ const FieldArrayLabel = ({ className = void 0, label: _label, name }) => {
262
456
  * The component wraps errors in the proper accessibility markup and animates
263
457
  * them in/out using Framer Motion when they appear or are resolved.
264
458
  */
265
- const FieldArrayValidationError = ({ name }) => {
266
- const { error, getErrorMessageProps, getHelperWrapperProps, invalid, testId } = useUniformField({ name });
459
+ const FieldArrayValidationError = ({ error, ids, invalid, testId }) => {
460
+ const styling = useStyling();
267
461
  const disableAnimation = useReducedMotion();
268
- const hasErrors = invalid && error?._errors;
462
+ const variants = styling.resolve(fieldArrayValidationErrorVariants);
463
+ const classNames = styling.variantsToClassNames(variants);
464
+ const objectErrors = error?._errors;
269
465
  return /* @__PURE__ */ jsx(AnimatePresence, {
270
466
  initial: !disableAnimation,
271
- children: hasErrors ? /* @__PURE__ */ jsx(motion.div, {
467
+ children: invalid && objectErrors ? /* @__PURE__ */ jsx(motion.div, {
272
468
  animate: disableAnimation ? void 0 : {
273
469
  opacity: 1,
274
470
  height: "auto"
@@ -287,14 +483,13 @@ const FieldArrayValidationError = ({ name }) => {
287
483
  ease: "circOut"
288
484
  },
289
485
  children: /* @__PURE__ */ jsx("div", {
290
- ...getHelperWrapperProps(),
291
- className: cn(getHelperWrapperProps()?.className, "block px-3 pb-2 pt-1"),
292
- children: /* @__PURE__ */ jsx("div", {
293
- ...getErrorMessageProps(),
294
- children: /* @__PURE__ */ jsx(FieldValidationError, {
295
- error: error._errors,
296
- testId
297
- })
486
+ className: classNames.helperWrapper,
487
+ "data-slot": "helper-wrapper",
488
+ children: /* @__PURE__ */ jsx(FieldValidationError, {
489
+ className: { wrapper: classNames.errorMessage },
490
+ error: objectErrors,
491
+ id: ids.error,
492
+ testId
298
493
  })
299
494
  })
300
495
  }, "field-array-errors") : null
@@ -310,8 +505,7 @@ const FieldArrayValidationError = ({ name }) => {
310
505
  * drag-and-drop reordering of form fields. It supports both pointer (mouse/touch)
311
506
  * and keyboard interactions for accessibility.
312
507
  */
313
- const SortContext = ({ children, fields, move, name, sortable }) => {
314
- const { trigger } = useFormContext();
508
+ const SortContext = ({ children, fields, move, sortable }) => {
315
509
  const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor));
316
510
  if (!sortable) return children;
317
511
  /**
@@ -320,14 +514,11 @@ const SortContext = ({ children, fields, move, name, sortable }) => {
320
514
  */
321
515
  const handleDragEnd = (event) => {
322
516
  const { active, over } = event;
323
- if (active.id !== over?.id) {
324
- move(fields.findIndex((field) => {
325
- return field.id === active.id;
326
- }), fields.findIndex((field) => {
327
- return field.id === over?.id;
328
- }));
329
- trigger(name);
330
- }
517
+ if (active.id !== over?.id) move(fields.findIndex((field) => {
518
+ return field.id === active.id;
519
+ }), fields.findIndex((field) => {
520
+ return field.id === over?.id;
521
+ }));
331
522
  };
332
523
  return /* @__PURE__ */ jsx(DndContext, {
333
524
  collisionDetection: closestCenter,
@@ -344,146 +535,104 @@ const SortContext = ({ children, fields, move, name, sortable }) => {
344
535
  });
345
536
  };
346
537
  //#endregion
347
- //#region src/FieldArray/FieldArray.tsx
348
- const fieldArrayVariants = tv({
349
- slots: {
350
- /** base class for the field array wrapper */
351
- base: ["overflow-hidden rounded-small border border-divider bg-content1", "divide-y divide-divider"],
352
- /** class for the actions menu button */
353
- actionsMenuButton: [
354
- "flex items-center justify-center text-default-600",
355
- "h-full rounded-none",
356
- "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
357
- ],
358
- /** class for the append button */
359
- appendButton: [
360
- "w-full justify-start rounded-b-small rounded-t-none font-semibold",
361
- "!h-[48px] !min-h-0",
362
- "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
363
- ],
364
- /** class for the element fields grid */
365
- elementFieldsGrid: ["w-full grow p-3"],
366
- /** class for the label */
367
- label: [
368
- "pointer-events-auto! static! z-auto! block! w-full!",
369
- "translate-x-0! translate-y-0! transform-none!",
370
- "rounded-t-small p-3 font-semibold text-medium"
371
- ],
372
- /** class for the list */
373
- list: ["overflow-hidden"],
374
- /** class for the list wrapper */
375
- listWrapper: ["overflow-hidden"],
376
- /** class for the list item (performs motion animations) */
377
- listItem: ["group relative flex flex-row", "first:-mt-px"],
378
- /** class for the list item inner */
379
- listItemInner: ["flex w-full flex-row items-stretch divide-divider bg-content1", "divide-x divide-solid border-b border-t border-divider"],
380
- /** class for the remove button */
381
- removeButton: [
382
- "flex items-center justify-center",
383
- "!h-full !min-h-0 !rounded-none px-3",
384
- "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
385
- ],
386
- /** class for the sort drag handle */
387
- sortDragHandle: [
388
- "flex cursor-grab items-center justify-center px-2 text-default-600 transition-colors",
389
- "hover:bg-default-100 active:cursor-grabbing group-data-[dragging=true]:bg-default-100",
390
- "outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"
391
- ]
392
- },
393
- variants: { hasLabel: { false: {
394
- actionsMenuButton: "group-[:first-child]:!rounded-tr-small group-[:first-child]:group-data-[dragging=true]:!rounded-tr-none",
395
- removeButton: "group-[:first-child]:!rounded-tr-small group-[:first-child]:group-data-[dragging=true]:!rounded-tr-none",
396
- sortDragHandle: "group-[:first-child]:rounded-tl-small group-[:first-child]:group-data-[dragging=true]:rounded-tl-none"
397
- } } }
398
- });
399
- /**
400
- * FieldArray component based in [RHF useFieldArray](https://react-hook-form.com/docs/usefieldarray)
401
- */
402
- const FieldArray = ({ appendButtonText = "Add Element", children, className: _className = void 0, duplicate = false, elementInitialValue: _elementInitialValue = null, elementMarginBottom = void 0, flat = false, insertAfter = false, lastElementNotRemovable = false, name, sortable = false, ...uniformFieldProps }) => {
403
- const { fields, append, remove, insert, move, disableAnimation, elementInitialValue, getValues, testId } = useUniformFieldArray({
404
- name,
405
- flat,
406
- elementInitialValue: _elementInitialValue,
407
- lastElementNotRemovable,
408
- ...uniformFieldProps
409
- });
410
- const variants = fieldArrayVariants({ hasLabel: !!uniformFieldProps.label });
411
- const className = variantsToClassNames(variants, _className, "base");
538
+ //#region src/FieldArray/subcomponents/FieldArrayControl.tsx
539
+ /** Array group presentation with row controls, sorting and validation messages */
540
+ const FieldArrayControl = ({ field, appendButtonText, children, className, disableAnimation, duplicate, elementMarginBottom, fields, items, insertAfter, lastElementNotRemovable, onAppend, onMove, sortable = false }) => {
541
+ const { error, ids, invalid, name, required, testId } = field;
542
+ const label = field.hasLabel ? field.label : void 0;
543
+ const styling = useStyling();
544
+ const labelId = useId();
545
+ const hasArrayErrors = !!(invalid && error?._errors);
546
+ const { cn } = styling;
547
+ const variants = styling.resolve(fieldArrayVariants, { hasLabel: !!label });
548
+ const classNames = styling.variantsToClassNames(variants, className, "base");
412
549
  return /* @__PURE__ */ jsxs("div", {
413
- className: className.base,
550
+ "aria-label": !label ? name : void 0,
551
+ "aria-labelledby": label ? labelId : void 0,
552
+ className: classNames.base,
553
+ "data-component": "field-array",
554
+ role: "group",
414
555
  children: [
415
556
  /* @__PURE__ */ jsx(FieldArrayLabel, {
416
- className: className.label,
417
- label: uniformFieldProps.label,
418
- name
557
+ className: classNames.label,
558
+ id: labelId,
559
+ invalid: hasArrayErrors,
560
+ label,
561
+ required
419
562
  }),
420
563
  fields.length ? /* @__PURE__ */ jsx("div", {
421
- className: cn(className.listWrapper),
564
+ className: cn(classNames.listWrapper),
422
565
  children: /* @__PURE__ */ jsx(SortContext, {
423
566
  fields,
424
- move,
425
- name,
567
+ move: onMove,
426
568
  sortable,
427
569
  children: /* @__PURE__ */ jsx("ul", {
428
- className: className.list,
570
+ className: classNames.list,
429
571
  "data-testid": testId,
430
- children: fields.map((field, index) => {
431
- const elementName = flat ? `${name}.${index}.${flatArrayKey}` : `${name}.${index}`;
432
- const elementTestId = `${testId}_${index}`;
433
- const elementMethods = {
434
- append: () => {
435
- append(elementInitialValue);
436
- },
437
- duplicate: () => {
438
- const currentValue = getValues(name)[index];
439
- const nextValue = flat ? { [flatArrayKey]: currentValue } : currentValue;
440
- insert(index + 1, nextValue);
441
- },
442
- insert: () => {
443
- insert(index + 1, elementInitialValue);
444
- },
445
- remove: () => {
446
- remove(index);
447
- }
448
- };
572
+ children: items.map(({ id, renderProps }) => {
449
573
  return /* @__PURE__ */ jsx(FieldArrayElement, {
450
- className,
574
+ className: classNames,
451
575
  disableAnimation,
452
576
  duplicate,
453
577
  elementMarginBottom,
454
578
  fields,
455
- id: field.id,
456
- index,
579
+ id,
580
+ index: renderProps.index,
457
581
  insertAfter,
458
582
  lastNotDeletable: lastElementNotRemovable,
459
- methods: elementMethods,
583
+ methods: renderProps.methods,
460
584
  sortable,
461
- testId: elementTestId,
462
- children: children({
463
- index,
464
- length: fields.length,
465
- methods: elementMethods,
466
- name: elementName,
467
- testId: elementTestId
468
- })
469
- }, field.id);
585
+ testId: renderProps.testId,
586
+ children: children(renderProps)
587
+ }, id);
470
588
  })
471
589
  })
472
590
  })
473
591
  }) : null,
474
- /* @__PURE__ */ jsx(FieldArrayValidationError, { name }),
592
+ /* @__PURE__ */ jsx(FieldArrayValidationError, {
593
+ error,
594
+ ids,
595
+ invalid,
596
+ testId
597
+ }),
475
598
  /* @__PURE__ */ jsx(ElementAppendButton, {
476
599
  appendButtonText,
477
- className: className.appendButton,
478
- onClick: () => {
479
- append(elementInitialValue);
480
- },
600
+ className: classNames.appendButton,
601
+ onClick: onAppend,
481
602
  testId: `${testId}_append_button`
482
603
  })
483
604
  ]
484
605
  });
485
606
  };
486
607
  //#endregion
608
+ //#region src/FieldArray/FieldArray.tsx
609
+ /** Form field group for adding, removing and reordering array entries */
610
+ const FieldArray = ({ appendButtonText = "Add Element", children, className: _className = void 0, duplicate = false, elementInitialValue: _elementInitialValue = null, elementMarginBottom = void 0, flat = false, insertAfter = false, lastElementNotRemovable = false, name, sortable = false, ...uniformFieldProps }) => {
611
+ const { field, fields, appendItem, items, moveItem, disableAnimation } = useUniformFieldArray({
612
+ ...uniformFieldProps,
613
+ elementInitialValue: _elementInitialValue,
614
+ flat,
615
+ lastElementNotRemovable,
616
+ name
617
+ });
618
+ return /* @__PURE__ */ jsx(FieldArrayControl, {
619
+ appendButtonText,
620
+ className: _className,
621
+ disableAnimation,
622
+ duplicate,
623
+ elementMarginBottom,
624
+ field,
625
+ fields,
626
+ insertAfter,
627
+ items,
628
+ lastElementNotRemovable,
629
+ onAppend: appendItem,
630
+ onMove: moveItem,
631
+ sortable,
632
+ children
633
+ });
634
+ };
635
+ //#endregion
487
636
  //#region src/FieldArray/index.ts
488
637
  var FieldArray_default = FieldArray;
489
638
  //#endregion