@reformer/ui 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alexandr Bukhtatyy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @reformer/ui
2
+
3
+ Headless UI components for `@reformer/core` - build accessible, fully customizable form interfaces.
4
+
5
+ ## Features
6
+
7
+ - **Headless** - No default styles, complete design freedom
8
+ - **Compound Components** - Declarative, composable API
9
+ - **Render Props** - Full control over rendering
10
+ - **TypeScript** - Fully typed with generics support
11
+ - **Tree-shakable** - Import only what you need
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @reformer/ui @reformer/core
17
+ ```
18
+
19
+ ## Components
20
+
21
+ ### FormArray
22
+
23
+ Manage dynamic form arrays with add/remove functionality.
24
+
25
+ ```tsx
26
+ import { FormArray } from '@reformer/ui/form-array';
27
+
28
+ <FormArray.Root control={form.items}>
29
+ <FormArray.Empty>
30
+ <p>No items yet</p>
31
+ </FormArray.Empty>
32
+
33
+ <FormArray.List>
34
+ {({ control, index, remove }) => (
35
+ <div>
36
+ <span>Item #{index + 1}</span>
37
+ <ItemForm control={control} />
38
+ <button onClick={remove}>Remove</button>
39
+ </div>
40
+ )}
41
+ </FormArray.List>
42
+
43
+ <FormArray.AddButton>Add Item</FormArray.AddButton>
44
+ </FormArray.Root>
45
+ ```
46
+
47
+ ### FormNavigation
48
+
49
+ Build multi-step form wizards with validation.
50
+
51
+ ```tsx
52
+ import { FormNavigation } from '@reformer/ui/form-navigation';
53
+
54
+ <FormNavigation form={form} config={config}>
55
+ <FormNavigation.Indicator steps={STEPS}>
56
+ {({ steps, goToStep }) => (
57
+ <nav>
58
+ {steps.map(step => (
59
+ <button
60
+ key={step.number}
61
+ onClick={() => goToStep(step.number)}
62
+ disabled={!step.canNavigate}
63
+ >
64
+ {step.title}
65
+ </button>
66
+ ))}
67
+ </nav>
68
+ )}
69
+ </FormNavigation.Indicator>
70
+
71
+ <FormNavigation.Step component={Step1} control={form} />
72
+ <FormNavigation.Step component={Step2} control={form} />
73
+
74
+ <FormNavigation.Actions onSubmit={handleSubmit}>
75
+ {({ prev, next, submit, isFirstStep, isLastStep }) => (
76
+ <div>
77
+ {!isFirstStep && <button {...prev}>Back</button>}
78
+ {!isLastStep ? (
79
+ <button {...next}>Next</button>
80
+ ) : (
81
+ <button {...submit}>Submit</button>
82
+ )}
83
+ </div>
84
+ )}
85
+ </FormNavigation.Actions>
86
+ </FormNavigation>
87
+ ```
88
+
89
+ ## Hooks
90
+
91
+ For full customization, use the hooks directly:
92
+
93
+ ```tsx
94
+ import { useFormArray } from '@reformer/ui/form-array';
95
+ import { useFormNavigation } from '@reformer/ui/form-navigation';
96
+ ```
97
+
98
+ ## License
99
+
100
+ MIT
@@ -0,0 +1,101 @@
1
+ import { jsx as o, Fragment as m } from "react/jsx-runtime";
2
+ import { useMemo as p, createContext as c, useContext as d, createElement as h, forwardRef as l, useImperativeHandle as v } from "react";
3
+ import { useFormControl as x } from "@reformer/core";
4
+ function C(t) {
5
+ const { length: r } = x(t);
6
+ return {
7
+ items: p(
8
+ () => t.map((e, n) => ({
9
+ control: e,
10
+ index: n,
11
+ id: e.id ?? n,
12
+ remove: () => t.removeAt(n)
13
+ })),
14
+ [t, r]
15
+ ),
16
+ length: r,
17
+ isEmpty: r === 0,
18
+ add: (e) => t.push(e),
19
+ clear: () => t.clear(),
20
+ insert: (e, n) => t.insert(e, n)
21
+ };
22
+ }
23
+ const y = c(null), A = c(null);
24
+ function u() {
25
+ const t = d(y);
26
+ if (!t)
27
+ throw new Error("FormArray.* components must be used within FormArray.Root");
28
+ return t;
29
+ }
30
+ function f() {
31
+ const t = d(A);
32
+ if (!t)
33
+ throw new Error("FormArray.Item* components must be used within FormArray.List");
34
+ return t;
35
+ }
36
+ function E({
37
+ children: t,
38
+ className: r,
39
+ as: s = "div"
40
+ }) {
41
+ const { items: e } = u(), n = e.map((i) => /* @__PURE__ */ o(A.Provider, { value: i, children: t(i) }, i.id));
42
+ return r ? h(s, { className: r }, n) : /* @__PURE__ */ o(m, { children: n });
43
+ }
44
+ function I({ children: t, initialValue: r, ...s }) {
45
+ const { add: e } = u();
46
+ return /* @__PURE__ */ o("button", { type: "button", onClick: () => e(r), ...s, children: t });
47
+ }
48
+ function b({ children: t, ...r }) {
49
+ const { remove: s } = f();
50
+ return /* @__PURE__ */ o("button", { type: "button", onClick: s, ...r, children: t });
51
+ }
52
+ function w({ children: t }) {
53
+ const { isEmpty: r } = u();
54
+ return r ? /* @__PURE__ */ o(m, { children: t }) : null;
55
+ }
56
+ function R({ render: t }) {
57
+ const { length: r } = u();
58
+ return t ? /* @__PURE__ */ o(m, { children: t(r) }) : /* @__PURE__ */ o(m, { children: r });
59
+ }
60
+ function g({ render: t }) {
61
+ const { index: r } = f();
62
+ return t ? /* @__PURE__ */ o(m, { children: t(r) }) : /* @__PURE__ */ o(m, { children: r + 1 });
63
+ }
64
+ function B({ control: t, children: r }, s) {
65
+ const e = C(t);
66
+ return v(
67
+ s,
68
+ () => ({
69
+ add: e.add,
70
+ clear: e.clear,
71
+ insert: e.insert,
72
+ removeAt: (n) => t.removeAt(n),
73
+ length: e.length,
74
+ isEmpty: e.isEmpty,
75
+ at: (n) => t.at(n)
76
+ }),
77
+ [e, t]
78
+ ), /* @__PURE__ */ o(y.Provider, { value: { ...e, control: t }, children: r });
79
+ }
80
+ const F = l(B), a = F;
81
+ a.Root = F;
82
+ a.List = E;
83
+ a.AddButton = I;
84
+ a.RemoveButton = b;
85
+ a.Empty = w;
86
+ a.Count = R;
87
+ a.ItemIndex = g;
88
+ export {
89
+ a as F,
90
+ E as a,
91
+ I as b,
92
+ b as c,
93
+ w as d,
94
+ R as e,
95
+ g as f,
96
+ y as g,
97
+ A as h,
98
+ u as i,
99
+ f as j,
100
+ C as u
101
+ };
@@ -0,0 +1,227 @@
1
+ import { jsx as f, Fragment as C } from "react/jsx-runtime";
2
+ import { createContext as $, useContext as z, forwardRef as J, useState as V, useCallback as m, useImperativeHandle as K, useMemo as O, Children as L, isValidElement as U, cloneElement as W } from "react";
3
+ import { validateForm as Y } from "@reformer/core/validators";
4
+ const G = $(null);
5
+ function P() {
6
+ const e = z(G);
7
+ if (!e)
8
+ throw new Error("useFormNavigation must be used within FormNavigation");
9
+ return e;
10
+ }
11
+ function x({
12
+ component: e,
13
+ control: i,
14
+ _stepIndex: a,
15
+ ...s
16
+ }) {
17
+ const { currentStep: o } = P();
18
+ return a === void 0 || o !== a ? null : /* @__PURE__ */ f(e, { control: i, ...s });
19
+ }
20
+ x.displayName = "FormNavigation.Step";
21
+ function M({ steps: e, children: i }) {
22
+ if (typeof i != "function")
23
+ throw new Error(
24
+ "FormNavigation.Indicator requires children as a render function. Example: <FormNavigation.Indicator steps={STEPS}>{({ steps }) => <YourUI />}</FormNavigation.Indicator>"
25
+ );
26
+ const { currentStep: a, totalSteps: s, completedSteps: o, goToStep: u } = P(), c = {
27
+ steps: e.map((t) => ({
28
+ ...t,
29
+ isCurrent: a === t.number,
30
+ isCompleted: o.includes(t.number),
31
+ canNavigate: t.number === 1 || o.includes(t.number - 1)
32
+ })),
33
+ goToStep: u,
34
+ currentStep: a,
35
+ totalSteps: s,
36
+ completedSteps: o
37
+ };
38
+ return /* @__PURE__ */ f(C, { children: i(c) });
39
+ }
40
+ M.displayName = "FormNavigation.Indicator";
41
+ function j({ onSubmit: e, children: i }) {
42
+ if (typeof i != "function")
43
+ throw new Error(
44
+ "FormNavigation.Actions requires children as a render function. Example: <FormNavigation.Actions>{({ prev, next }) => <YourUI />}</FormNavigation.Actions>"
45
+ );
46
+ const { isFirstStep: a, isLastStep: s, isValidating: o, isSubmitting: u, goToNextStep: p, goToPreviousStep: c } = P(), t = o || u;
47
+ return /* @__PURE__ */ f(C, { children: i({
48
+ prev: {
49
+ onClick: c,
50
+ disabled: t
51
+ },
52
+ next: {
53
+ onClick: () => p(),
54
+ disabled: t
55
+ },
56
+ submit: {
57
+ onClick: () => e?.(),
58
+ disabled: t,
59
+ isSubmitting: u
60
+ },
61
+ isFirstStep: a,
62
+ isLastStep: s,
63
+ isValidating: o,
64
+ isSubmitting: u
65
+ }) });
66
+ }
67
+ j.displayName = "FormNavigation.Actions";
68
+ function B({ children: e }) {
69
+ if (typeof e != "function")
70
+ throw new Error(
71
+ "FormNavigation.Progress requires children as a render function. Example: <FormNavigation.Progress>{({ current, total }) => <YourUI />}</FormNavigation.Progress>"
72
+ );
73
+ const { currentStep: i, totalSteps: a, completedSteps: s, isFirstStep: o, isLastStep: u } = P(), p = {
74
+ current: i,
75
+ total: a,
76
+ percent: Math.round(i / a * 100),
77
+ completedCount: s.length,
78
+ isFirstStep: o,
79
+ isLastStep: u
80
+ };
81
+ return /* @__PURE__ */ f(C, { children: e(p) });
82
+ }
83
+ B.displayName = "FormNavigation.Progress";
84
+ function Q({ form: e, config: i, children: a, onStepChange: s, scrollToTop: o = !0 }, u) {
85
+ const p = (n) => {
86
+ let r = 0;
87
+ return L.forEach(n, (l) => {
88
+ if (U(l))
89
+ if (l.type === x)
90
+ r += 1;
91
+ else {
92
+ const q = l.props;
93
+ q.children && (r += p(q.children));
94
+ }
95
+ }), r;
96
+ }, c = p(a), [t, v] = V(1), [d, D] = V([]), [g, S] = V(!1), E = e.submitting.value, N = m(async () => {
97
+ const n = i.stepValidations[t];
98
+ if (!n)
99
+ return console.warn(`No validation schema for step ${t}`), !0;
100
+ S(!0);
101
+ try {
102
+ return await Y(e, n);
103
+ } finally {
104
+ S(!1);
105
+ }
106
+ }, [e, t, i.stepValidations]), F = m(async () => {
107
+ if (!await N())
108
+ return e.markAsTouched(), !1;
109
+ if (d.includes(t) || D((r) => [...r, t]), t < c) {
110
+ const r = t + 1;
111
+ v(r), s?.(r), o && window.scrollTo({ top: 0, behavior: "smooth" });
112
+ }
113
+ return !0;
114
+ }, [
115
+ N,
116
+ t,
117
+ d,
118
+ c,
119
+ e,
120
+ s,
121
+ o
122
+ ]), h = m(() => {
123
+ if (t > 1) {
124
+ const n = t - 1;
125
+ v(n), s?.(n), o && window.scrollTo({ top: 0, behavior: "smooth" });
126
+ }
127
+ }, [t, s, o]), b = m(
128
+ (n) => (n === 1 || d.includes(n - 1)) && n >= 1 && n <= c ? (v(n), s?.(n), o && window.scrollTo({ top: 0, behavior: "smooth" }), !0) : !1,
129
+ [d, c, s, o]
130
+ ), A = m(
131
+ async (n) => {
132
+ S(!0);
133
+ try {
134
+ return await Y(e, i.fullValidation) ? e.submit(n) : (e.markAsTouched(), null);
135
+ } finally {
136
+ S(!1);
137
+ }
138
+ },
139
+ [e, i.fullValidation]
140
+ ), w = t === 1, y = t === c;
141
+ K(
142
+ u,
143
+ () => ({
144
+ currentStep: t,
145
+ completedSteps: d,
146
+ validateCurrentStep: N,
147
+ goToNextStep: F,
148
+ goToPreviousStep: h,
149
+ goToStep: b,
150
+ submit: A,
151
+ isFirstStep: w,
152
+ isLastStep: y,
153
+ isValidating: g
154
+ }),
155
+ [
156
+ t,
157
+ d,
158
+ N,
159
+ F,
160
+ h,
161
+ b,
162
+ A,
163
+ w,
164
+ y,
165
+ g
166
+ ]
167
+ );
168
+ const H = O(
169
+ () => ({
170
+ // State
171
+ currentStep: t,
172
+ totalSteps: c,
173
+ completedSteps: d,
174
+ isFirstStep: w,
175
+ isLastStep: y,
176
+ isValidating: g,
177
+ isSubmitting: E,
178
+ form: e,
179
+ // Navigation methods
180
+ goToNextStep: F,
181
+ goToPreviousStep: h,
182
+ goToStep: b
183
+ }),
184
+ [
185
+ t,
186
+ c,
187
+ d,
188
+ w,
189
+ y,
190
+ g,
191
+ E,
192
+ e,
193
+ F,
194
+ h,
195
+ b
196
+ ]
197
+ );
198
+ let k = 0;
199
+ const T = (n) => L.map(n, (r) => {
200
+ if (!U(r))
201
+ return r;
202
+ const l = r.props;
203
+ return r.type === x ? (k += 1, W(r, {
204
+ ...l,
205
+ _stepIndex: k
206
+ // 1-based indexing
207
+ })) : typeof l.children == "function" ? r : l.children ? W(r, {
208
+ ...l,
209
+ children: T(l.children)
210
+ }) : r;
211
+ }), R = T(a);
212
+ return /* @__PURE__ */ f(G.Provider, { value: H, children: R });
213
+ }
214
+ const X = J(Q), I = X;
215
+ I.Step = x;
216
+ I.Indicator = M;
217
+ I.Actions = j;
218
+ I.Progress = B;
219
+ export {
220
+ I as F,
221
+ x as a,
222
+ M as b,
223
+ j as c,
224
+ B as d,
225
+ G as e,
226
+ P as u
227
+ };
@@ -0,0 +1,170 @@
1
+ import type { FormFields, GroupNodeWithControls } from '@reformer/core';
2
+ import { FormArrayList } from './FormArrayList';
3
+ import { FormArrayAddButton } from './FormArrayAddButton';
4
+ import { FormArrayRemoveButton } from './FormArrayRemoveButton';
5
+ import { FormArrayEmpty } from './FormArrayEmpty';
6
+ import { FormArrayCount } from './FormArrayCount';
7
+ import { FormArrayItemIndex } from './FormArrayItemIndex';
8
+ import type { FormArrayRootProps } from './types';
9
+ /**
10
+ * Handle exposed via ref for external control of FormArray
11
+ */
12
+ export interface FormArrayHandle<T extends FormFields> {
13
+ /** Add a new item to the end of the array */
14
+ add: (value?: Partial<T>) => void;
15
+ /** Remove all items from the array */
16
+ clear: () => void;
17
+ /** Insert a new item at a specific index */
18
+ insert: (index: number, value?: Partial<T>) => void;
19
+ /** Remove item at specific index */
20
+ removeAt: (index: number) => void;
21
+ /** Current number of items */
22
+ length: number;
23
+ /** Whether the array is empty */
24
+ isEmpty: boolean;
25
+ /** Get item control at specific index */
26
+ at: (index: number) => GroupNodeWithControls<T> | undefined;
27
+ }
28
+ declare const FormArrayRoot: <T extends FormFields>(props: FormArrayRootProps<T> & {
29
+ ref?: React.ForwardedRef<FormArrayHandle<T>>;
30
+ }) => React.ReactElement;
31
+ type FormArrayComponent = typeof FormArrayRoot & {
32
+ Root: typeof FormArrayRoot;
33
+ List: typeof FormArrayList;
34
+ AddButton: typeof FormArrayAddButton;
35
+ RemoveButton: typeof FormArrayRemoveButton;
36
+ Empty: typeof FormArrayEmpty;
37
+ Count: typeof FormArrayCount;
38
+ ItemIndex: typeof FormArrayItemIndex;
39
+ };
40
+ /**
41
+ * FormArray - Headless compound component for managing form arrays
42
+ *
43
+ * Provides complete flexibility for building array UI while handling
44
+ * all the form array state and actions internally.
45
+ *
46
+ * ## Features
47
+ * - **Headless** - complete freedom in building UI
48
+ * - **Compound Components** - declarative API via nested components
49
+ * - **External Control** - control from outside via ref (useImperativeHandle)
50
+ * - **Type Safe** - full TypeScript support
51
+ *
52
+ * ## Sub-components
53
+ * - `FormArray.Root` - context provider, accepts ref for external control
54
+ * - `FormArray.List` - iterates over array items
55
+ * - `FormArray.AddButton` - button to add item
56
+ * - `FormArray.RemoveButton` - button to remove item (inside List)
57
+ * - `FormArray.Empty` - content for empty state
58
+ * - `FormArray.Count` - display item count
59
+ * - `FormArray.ItemIndex` - display item index (inside List)
60
+ *
61
+ * ## FormArrayHandle API (ref)
62
+ * - `add(value?)` - add item to the end
63
+ * - `insert(index, value?)` - insert item at position
64
+ * - `removeAt(index)` - remove item by index
65
+ * - `clear()` - clear array
66
+ * - `at(index)` - get item control by index
67
+ * - `length` - current item count
68
+ * - `isEmpty` - empty array flag
69
+ *
70
+ * @example Basic usage
71
+ * ```tsx
72
+ * <FormArray.Root control={form.properties}>
73
+ * <h3>Properties (<FormArray.Count />)</h3>
74
+ *
75
+ * <FormArray.Empty>
76
+ * <p className="text-gray-500">No properties added</p>
77
+ * </FormArray.Empty>
78
+ *
79
+ * <FormArray.List className="space-y-4">
80
+ * {({ control }) => (
81
+ * <div className="p-4 border rounded">
82
+ * <div className="flex justify-between mb-2">
83
+ * <h4>Property #<FormArray.ItemIndex /></h4>
84
+ * <FormArray.RemoveButton className="text-red-500">
85
+ * Remove
86
+ * </FormArray.RemoveButton>
87
+ * </div>
88
+ * <PropertyForm control={control} />
89
+ * </div>
90
+ * )}
91
+ * </FormArray.List>
92
+ *
93
+ * <FormArray.AddButton className="mt-4 btn-primary">
94
+ * + Add Property
95
+ * </FormArray.AddButton>
96
+ * </FormArray.Root>
97
+ * ```
98
+ *
99
+ * @example External control via ref
100
+ * ```tsx
101
+ * import { useRef } from 'react';
102
+ * import { FormArray, FormArrayHandle } from '@reformer/ui/form-array';
103
+ *
104
+ * function PropertiesManager() {
105
+ * const arrayRef = useRef<FormArrayHandle<Property>>(null);
106
+ *
107
+ * // Programmatic control from outside
108
+ * const handleAddApartment = () => {
109
+ * arrayRef.current?.add({ type: 'apartment', estimatedValue: 0 });
110
+ * };
111
+ *
112
+ * const handleClearAll = () => {
113
+ * if (confirm('Delete all items?')) {
114
+ * arrayRef.current?.clear();
115
+ * }
116
+ * };
117
+ *
118
+ * const handleRemoveFirst = () => {
119
+ * if (arrayRef.current && arrayRef.current.length > 0) {
120
+ * arrayRef.current.removeAt(0);
121
+ * }
122
+ * };
123
+ *
124
+ * const handleInsertAtStart = () => {
125
+ * arrayRef.current?.insert(0, { type: 'house' });
126
+ * };
127
+ *
128
+ * return (
129
+ * <div>
130
+ * <div className="toolbar">
131
+ * <button onClick={handleAddApartment}>+ Apartment</button>
132
+ * <button onClick={handleInsertAtStart}>Insert at start</button>
133
+ * <button onClick={handleRemoveFirst}>Remove first</button>
134
+ * <button onClick={handleClearAll}>Clear all</button>
135
+ * </div>
136
+ *
137
+ * <FormArray.Root ref={arrayRef} control={form.properties}>
138
+ * <FormArray.List>
139
+ * {({ control }) => <PropertyForm control={control} />}
140
+ * </FormArray.List>
141
+ * </FormArray.Root>
142
+ * </div>
143
+ * );
144
+ * }
145
+ * ```
146
+ *
147
+ * @example Using useFormArray hook for full customization
148
+ * ```tsx
149
+ * import { useFormArray } from '@reformer/ui/form-array';
150
+ *
151
+ * function CustomArrayUI() {
152
+ * const { items, add, isEmpty, length } = useFormArray(form.properties);
153
+ *
154
+ * return (
155
+ * <div>
156
+ * <span>Total: {length}</span>
157
+ * {items.map(({ control, id, remove }) => (
158
+ * <CustomCard key={id} onDelete={remove}>
159
+ * <PropertyForm control={control} />
160
+ * </CustomCard>
161
+ * ))}
162
+ * {isEmpty && <EmptyState />}
163
+ * <button onClick={() => add()}>Add</button>
164
+ * </div>
165
+ * );
166
+ * }
167
+ * ```
168
+ */
169
+ export declare const FormArray: FormArrayComponent;
170
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { FormArrayAddButtonProps } from './types';
2
+ /**
3
+ * FormArray.AddButton - Button to add new items to the array
4
+ *
5
+ * @example Basic usage
6
+ * ```tsx
7
+ * <FormArray.AddButton className="btn-primary">
8
+ * + Add Item
9
+ * </FormArray.AddButton>
10
+ * ```
11
+ *
12
+ * @example With initial value
13
+ * ```tsx
14
+ * <FormArray.AddButton initialValue={{ status: 'draft' }}>
15
+ * Add Draft
16
+ * </FormArray.AddButton>
17
+ * ```
18
+ */
19
+ export declare function FormArrayAddButton({ children, initialValue, ...props }: FormArrayAddButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import type { FormFields, ArrayNode } from '@reformer/core';
2
+ import type { FormArrayItem } from './useFormArray';
3
+ /**
4
+ * Context value for FormArray compound component
5
+ */
6
+ export interface FormArrayContextValue<T extends FormFields = FormFields> {
7
+ /** Array of items with their controls and actions */
8
+ items: FormArrayItem<T>[];
9
+ /** Current number of items */
10
+ length: number;
11
+ /** Whether the array is empty */
12
+ isEmpty: boolean;
13
+ /** Add a new item to the array */
14
+ add: (value?: Partial<T>) => void;
15
+ /** Remove all items */
16
+ clear: () => void;
17
+ /** Insert item at specific index */
18
+ insert: (index: number, value?: Partial<T>) => void;
19
+ /** The original ArrayNode control */
20
+ control: ArrayNode<T>;
21
+ }
22
+ /**
23
+ * Context value for individual array items
24
+ */
25
+ export interface FormArrayItemContextValue<T extends FormFields = FormFields> {
26
+ /** The form control for this item */
27
+ control: FormArrayItem<T>['control'];
28
+ /** Zero-based index of the item */
29
+ index: number;
30
+ /** Unique identifier for React key */
31
+ id: string | number;
32
+ /** Remove this item from the array */
33
+ remove: () => void;
34
+ }
35
+ export declare const FormArrayContext: import("react").Context<FormArrayContextValue<any> | null>;
36
+ export declare const FormArrayItemContext: import("react").Context<FormArrayItemContextValue<any> | null>;
37
+ /**
38
+ * Hook to access FormArray context
39
+ * @throws Error if used outside of FormArray.Root
40
+ */
41
+ export declare function useFormArrayContext<T extends FormFields = FormFields>(): FormArrayContextValue<T>;
42
+ /**
43
+ * Hook to access current item context within FormArray.List
44
+ * @throws Error if used outside of FormArray.List
45
+ */
46
+ export declare function useFormArrayItemContext<T extends FormFields = FormFields>(): FormArrayItemContextValue<T>;
@@ -0,0 +1,17 @@
1
+ import type { FormArrayCountProps } from './types';
2
+ /**
3
+ * FormArray.Count - Displays the number of items in the array
4
+ *
5
+ * @example Basic usage
6
+ * ```tsx
7
+ * <h3>Items (<FormArray.Count />)</h3>
8
+ * ```
9
+ *
10
+ * @example With custom render
11
+ * ```tsx
12
+ * <FormArray.Count render={(count) => (
13
+ * count === 0 ? 'No items' : `${count} item${count > 1 ? 's' : ''}`
14
+ * )} />
15
+ * ```
16
+ */
17
+ export declare function FormArrayCount({ render }: FormArrayCountProps): import("react/jsx-runtime").JSX.Element;