react-children-hooks 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -13
- package/dist/index.cjs +131 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -55
- package/dist/index.d.ts +107 -55
- package/dist/index.js +118 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ElementType, ReactNode, ReactElement } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Inclusive minimum and maximum bounds used by the bounded validation hooks.
|
|
6
|
+
*/
|
|
7
|
+
type ChildrenCountBounds = {
|
|
8
|
+
/**
|
|
9
|
+
* The minimum number of matching direct child elements required.
|
|
10
|
+
*/
|
|
11
|
+
minimum: number;
|
|
12
|
+
/**
|
|
13
|
+
* The maximum number of matching direct child elements allowed.
|
|
14
|
+
*/
|
|
15
|
+
maximum: number;
|
|
16
|
+
};
|
|
4
17
|
/**
|
|
5
18
|
* Represents a React element whose props and element type are narrowed to the provided React element type.
|
|
6
19
|
*
|
|
7
20
|
* @typeParam T The React element type used to narrow the element's props and type.
|
|
8
21
|
*/
|
|
9
22
|
type ElementOfType<T extends React.ElementType> = React.ReactElement<React.ComponentProps<T>, T>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional reporting metadata used by the validation hooks to derive thrown validation messages.
|
|
25
|
+
*/
|
|
26
|
+
type ValidationOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
29
|
+
*/
|
|
30
|
+
traceCode?: string;
|
|
31
|
+
/**
|
|
32
|
+
* An optional human-readable child name that is included in the thrown validation message.
|
|
33
|
+
*/
|
|
34
|
+
childName?: string;
|
|
35
|
+
};
|
|
10
36
|
|
|
11
37
|
/**
|
|
12
38
|
* Returns the first direct child element whose React element type exactly matches the provided type.
|
|
@@ -24,8 +50,31 @@ declare function useChildByType<T extends ElementType>(children: ReactNode, type
|
|
|
24
50
|
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
25
51
|
* @returns The first direct child element that satisfies the provided predicate, or `null` when no match is found.
|
|
26
52
|
*/
|
|
27
|
-
declare function
|
|
28
|
-
declare function
|
|
53
|
+
declare function useChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T | null;
|
|
54
|
+
declare function useChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when the count falls outside the inclusive bounds.
|
|
58
|
+
*
|
|
59
|
+
* @param children The React children value to inspect.
|
|
60
|
+
* @param type The element or component type to match against each direct child element.
|
|
61
|
+
* @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
|
|
62
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
63
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
64
|
+
*/
|
|
65
|
+
declare function useBoundedChildrenByType<T extends ElementType>(children: ReactNode, type: T, bounds: ChildrenCountBounds, options?: ValidationOptions): ElementOfType<T>[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns the direct child elements that satisfy the provided predicate, or throws when the count falls outside the inclusive bounds.
|
|
69
|
+
*
|
|
70
|
+
* @param children The React children value to inspect.
|
|
71
|
+
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
72
|
+
* @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
|
|
73
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
74
|
+
* @returns The direct child elements that satisfy the provided predicate.
|
|
75
|
+
*/
|
|
76
|
+
declare function useBoundedChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, bounds: ChildrenCountBounds, options?: ValidationOptions): T[];
|
|
77
|
+
declare function useBoundedChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, bounds: ChildrenCountBounds, options?: ValidationOptions): ReactElement[];
|
|
29
78
|
|
|
30
79
|
/**
|
|
31
80
|
* Returns the direct child elements whose React element type exactly matches the provided type.
|
|
@@ -43,19 +92,20 @@ declare function useChildrenByType<T extends ElementType>(children: ReactNode, t
|
|
|
43
92
|
* @param predicate A predicate that is called with each direct child element to determine whether it should be included in the result.
|
|
44
93
|
* @returns An array of direct child elements that satisfy the provided predicate.
|
|
45
94
|
*/
|
|
46
|
-
declare function
|
|
47
|
-
declare function
|
|
95
|
+
declare function useChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T[];
|
|
96
|
+
declare function useChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when the exact count is not met.
|
|
100
|
+
*
|
|
101
|
+
* @param children The React children value to inspect.
|
|
102
|
+
* @param type The element or component type to match against each direct child element.
|
|
103
|
+
* @param exactCount The exact number of matching direct child elements required.
|
|
104
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
105
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
106
|
+
*/
|
|
107
|
+
declare function useExactChildrenByType<T extends ElementType>(children: ReactNode, type: T, exactCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
48
108
|
|
|
49
|
-
type UseExactChildrenWhereOptions = {
|
|
50
|
-
/**
|
|
51
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
52
|
-
*/
|
|
53
|
-
traceCode?: string;
|
|
54
|
-
/**
|
|
55
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
56
|
-
*/
|
|
57
|
-
childName?: string;
|
|
58
|
-
};
|
|
59
109
|
/**
|
|
60
110
|
* Returns the direct child elements that satisfy the provided predicate, or throws when the exact count is not met.
|
|
61
111
|
*
|
|
@@ -65,8 +115,8 @@ type UseExactChildrenWhereOptions = {
|
|
|
65
115
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
66
116
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
67
117
|
*/
|
|
68
|
-
declare function
|
|
69
|
-
declare function
|
|
118
|
+
declare function useExactChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, exactCount: number, options?: ValidationOptions): T[];
|
|
119
|
+
declare function useExactChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, exactCount: number, options?: ValidationOptions): ReactElement[];
|
|
70
120
|
|
|
71
121
|
/**
|
|
72
122
|
* Determines whether any direct child element satisfies the provided predicate.
|
|
@@ -75,19 +125,20 @@ declare function useExactChildrenWhere(children: ReactNode, predicate: (element:
|
|
|
75
125
|
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
76
126
|
* @returns `true` when at least one direct child element satisfies the provided predicate; otherwise `false`.
|
|
77
127
|
*/
|
|
78
|
-
declare function
|
|
79
|
-
declare function
|
|
128
|
+
declare function useHasChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): boolean;
|
|
129
|
+
declare function useHasChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when more than the maximum count are found.
|
|
133
|
+
*
|
|
134
|
+
* @param children The React children value to inspect.
|
|
135
|
+
* @param type The element or component type to match against each direct child element.
|
|
136
|
+
* @param maximumCount The maximum number of matching direct child elements allowed.
|
|
137
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
138
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
139
|
+
*/
|
|
140
|
+
declare function useMaximumChildrenByType<T extends ElementType>(children: ReactNode, type: T, maximumCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
80
141
|
|
|
81
|
-
type UseMaximumChildrenWhereOptions = {
|
|
82
|
-
/**
|
|
83
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
84
|
-
*/
|
|
85
|
-
traceCode?: string;
|
|
86
|
-
/**
|
|
87
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
88
|
-
*/
|
|
89
|
-
childName?: string;
|
|
90
|
-
};
|
|
91
142
|
/**
|
|
92
143
|
* Returns the direct child elements that satisfy the provided predicate, or throws when more than the maximum count are found.
|
|
93
144
|
*
|
|
@@ -97,19 +148,20 @@ type UseMaximumChildrenWhereOptions = {
|
|
|
97
148
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
98
149
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
99
150
|
*/
|
|
100
|
-
declare function
|
|
101
|
-
declare function
|
|
151
|
+
declare function useMaximumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, maximumCount: number, options?: ValidationOptions): T[];
|
|
152
|
+
declare function useMaximumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, maximumCount: number, options?: ValidationOptions): ReactElement[];
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when fewer than the minimum count are found.
|
|
156
|
+
*
|
|
157
|
+
* @param children The React children value to inspect.
|
|
158
|
+
* @param type The element or component type to match against each direct child element.
|
|
159
|
+
* @param minimumCount The minimum number of matching direct child elements required.
|
|
160
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
161
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
162
|
+
*/
|
|
163
|
+
declare function useMinimumChildrenByType<T extends ElementType>(children: ReactNode, type: T, minimumCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
102
164
|
|
|
103
|
-
type UseMinimumChildrenWhereOptions = {
|
|
104
|
-
/**
|
|
105
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
106
|
-
*/
|
|
107
|
-
traceCode?: string;
|
|
108
|
-
/**
|
|
109
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
110
|
-
*/
|
|
111
|
-
childName?: string;
|
|
112
|
-
};
|
|
113
165
|
/**
|
|
114
166
|
* Returns the direct child elements that satisfy the provided predicate, or throws when fewer than the minimum count are found.
|
|
115
167
|
*
|
|
@@ -119,19 +171,19 @@ type UseMinimumChildrenWhereOptions = {
|
|
|
119
171
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
120
172
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
121
173
|
*/
|
|
122
|
-
declare function
|
|
123
|
-
declare function
|
|
174
|
+
declare function useMinimumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: ValidationOptions): T[];
|
|
175
|
+
declare function useMinimumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: ValidationOptions): ReactElement[];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Returns the first direct child element whose React element type exactly matches the provided type, or throws when no match is found.
|
|
179
|
+
*
|
|
180
|
+
* @param children The React children value to inspect.
|
|
181
|
+
* @param type The element or component type to match against each direct child element.
|
|
182
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
183
|
+
* @returns The first direct child element whose type matches the provided element type.
|
|
184
|
+
*/
|
|
185
|
+
declare function useRequiredChildByType<T extends ElementType>(children: ReactNode, type: T, options?: ValidationOptions): ElementOfType<T>;
|
|
124
186
|
|
|
125
|
-
type UseRequiredChildWhereOptions = {
|
|
126
|
-
/**
|
|
127
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
128
|
-
*/
|
|
129
|
-
traceCode?: string;
|
|
130
|
-
/**
|
|
131
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
132
|
-
*/
|
|
133
|
-
childName?: string;
|
|
134
|
-
};
|
|
135
187
|
/**
|
|
136
188
|
* Returns the first direct child element that satisfies the provided predicate, or throws when no match is found.
|
|
137
189
|
*
|
|
@@ -140,8 +192,8 @@ type UseRequiredChildWhereOptions = {
|
|
|
140
192
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
141
193
|
* @returns The first direct child element that satisfies the provided predicate.
|
|
142
194
|
*/
|
|
143
|
-
declare function
|
|
144
|
-
declare function
|
|
195
|
+
declare function useRequiredChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
196
|
+
declare function useRequiredChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
145
197
|
|
|
146
198
|
/**
|
|
147
199
|
* Normalizes a React children value into an array containing only valid direct child elements.
|
|
@@ -168,4 +220,4 @@ declare function isElementOfType<T extends ElementType>(element: ReactElement, t
|
|
|
168
220
|
*/
|
|
169
221
|
declare function isReactElement(node: ReactNode): node is ReactElement;
|
|
170
222
|
|
|
171
|
-
export { type
|
|
223
|
+
export { type ChildrenCountBounds, type ElementOfType, type ValidationOptions, childrenToElements, isElementOfType, isReactElement, useBoundedChildrenByType, useBoundedChildrenMatching, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useRequiredChildByType, useRequiredChildMatching };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ElementType, ReactNode, ReactElement } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Inclusive minimum and maximum bounds used by the bounded validation hooks.
|
|
6
|
+
*/
|
|
7
|
+
type ChildrenCountBounds = {
|
|
8
|
+
/**
|
|
9
|
+
* The minimum number of matching direct child elements required.
|
|
10
|
+
*/
|
|
11
|
+
minimum: number;
|
|
12
|
+
/**
|
|
13
|
+
* The maximum number of matching direct child elements allowed.
|
|
14
|
+
*/
|
|
15
|
+
maximum: number;
|
|
16
|
+
};
|
|
4
17
|
/**
|
|
5
18
|
* Represents a React element whose props and element type are narrowed to the provided React element type.
|
|
6
19
|
*
|
|
7
20
|
* @typeParam T The React element type used to narrow the element's props and type.
|
|
8
21
|
*/
|
|
9
22
|
type ElementOfType<T extends React.ElementType> = React.ReactElement<React.ComponentProps<T>, T>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional reporting metadata used by the validation hooks to derive thrown validation messages.
|
|
25
|
+
*/
|
|
26
|
+
type ValidationOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
29
|
+
*/
|
|
30
|
+
traceCode?: string;
|
|
31
|
+
/**
|
|
32
|
+
* An optional human-readable child name that is included in the thrown validation message.
|
|
33
|
+
*/
|
|
34
|
+
childName?: string;
|
|
35
|
+
};
|
|
10
36
|
|
|
11
37
|
/**
|
|
12
38
|
* Returns the first direct child element whose React element type exactly matches the provided type.
|
|
@@ -24,8 +50,31 @@ declare function useChildByType<T extends ElementType>(children: ReactNode, type
|
|
|
24
50
|
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
25
51
|
* @returns The first direct child element that satisfies the provided predicate, or `null` when no match is found.
|
|
26
52
|
*/
|
|
27
|
-
declare function
|
|
28
|
-
declare function
|
|
53
|
+
declare function useChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T | null;
|
|
54
|
+
declare function useChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when the count falls outside the inclusive bounds.
|
|
58
|
+
*
|
|
59
|
+
* @param children The React children value to inspect.
|
|
60
|
+
* @param type The element or component type to match against each direct child element.
|
|
61
|
+
* @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
|
|
62
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
63
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
64
|
+
*/
|
|
65
|
+
declare function useBoundedChildrenByType<T extends ElementType>(children: ReactNode, type: T, bounds: ChildrenCountBounds, options?: ValidationOptions): ElementOfType<T>[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns the direct child elements that satisfy the provided predicate, or throws when the count falls outside the inclusive bounds.
|
|
69
|
+
*
|
|
70
|
+
* @param children The React children value to inspect.
|
|
71
|
+
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
72
|
+
* @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
|
|
73
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
74
|
+
* @returns The direct child elements that satisfy the provided predicate.
|
|
75
|
+
*/
|
|
76
|
+
declare function useBoundedChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, bounds: ChildrenCountBounds, options?: ValidationOptions): T[];
|
|
77
|
+
declare function useBoundedChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, bounds: ChildrenCountBounds, options?: ValidationOptions): ReactElement[];
|
|
29
78
|
|
|
30
79
|
/**
|
|
31
80
|
* Returns the direct child elements whose React element type exactly matches the provided type.
|
|
@@ -43,19 +92,20 @@ declare function useChildrenByType<T extends ElementType>(children: ReactNode, t
|
|
|
43
92
|
* @param predicate A predicate that is called with each direct child element to determine whether it should be included in the result.
|
|
44
93
|
* @returns An array of direct child elements that satisfy the provided predicate.
|
|
45
94
|
*/
|
|
46
|
-
declare function
|
|
47
|
-
declare function
|
|
95
|
+
declare function useChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T[];
|
|
96
|
+
declare function useChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when the exact count is not met.
|
|
100
|
+
*
|
|
101
|
+
* @param children The React children value to inspect.
|
|
102
|
+
* @param type The element or component type to match against each direct child element.
|
|
103
|
+
* @param exactCount The exact number of matching direct child elements required.
|
|
104
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
105
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
106
|
+
*/
|
|
107
|
+
declare function useExactChildrenByType<T extends ElementType>(children: ReactNode, type: T, exactCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
48
108
|
|
|
49
|
-
type UseExactChildrenWhereOptions = {
|
|
50
|
-
/**
|
|
51
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
52
|
-
*/
|
|
53
|
-
traceCode?: string;
|
|
54
|
-
/**
|
|
55
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
56
|
-
*/
|
|
57
|
-
childName?: string;
|
|
58
|
-
};
|
|
59
109
|
/**
|
|
60
110
|
* Returns the direct child elements that satisfy the provided predicate, or throws when the exact count is not met.
|
|
61
111
|
*
|
|
@@ -65,8 +115,8 @@ type UseExactChildrenWhereOptions = {
|
|
|
65
115
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
66
116
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
67
117
|
*/
|
|
68
|
-
declare function
|
|
69
|
-
declare function
|
|
118
|
+
declare function useExactChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, exactCount: number, options?: ValidationOptions): T[];
|
|
119
|
+
declare function useExactChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, exactCount: number, options?: ValidationOptions): ReactElement[];
|
|
70
120
|
|
|
71
121
|
/**
|
|
72
122
|
* Determines whether any direct child element satisfies the provided predicate.
|
|
@@ -75,19 +125,20 @@ declare function useExactChildrenWhere(children: ReactNode, predicate: (element:
|
|
|
75
125
|
* @param predicate A predicate that is called with each direct child element to determine whether it matches.
|
|
76
126
|
* @returns `true` when at least one direct child element satisfies the provided predicate; otherwise `false`.
|
|
77
127
|
*/
|
|
78
|
-
declare function
|
|
79
|
-
declare function
|
|
128
|
+
declare function useHasChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): boolean;
|
|
129
|
+
declare function useHasChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean): boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when more than the maximum count are found.
|
|
133
|
+
*
|
|
134
|
+
* @param children The React children value to inspect.
|
|
135
|
+
* @param type The element or component type to match against each direct child element.
|
|
136
|
+
* @param maximumCount The maximum number of matching direct child elements allowed.
|
|
137
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
138
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
139
|
+
*/
|
|
140
|
+
declare function useMaximumChildrenByType<T extends ElementType>(children: ReactNode, type: T, maximumCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
80
141
|
|
|
81
|
-
type UseMaximumChildrenWhereOptions = {
|
|
82
|
-
/**
|
|
83
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
84
|
-
*/
|
|
85
|
-
traceCode?: string;
|
|
86
|
-
/**
|
|
87
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
88
|
-
*/
|
|
89
|
-
childName?: string;
|
|
90
|
-
};
|
|
91
142
|
/**
|
|
92
143
|
* Returns the direct child elements that satisfy the provided predicate, or throws when more than the maximum count are found.
|
|
93
144
|
*
|
|
@@ -97,19 +148,20 @@ type UseMaximumChildrenWhereOptions = {
|
|
|
97
148
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
98
149
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
99
150
|
*/
|
|
100
|
-
declare function
|
|
101
|
-
declare function
|
|
151
|
+
declare function useMaximumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, maximumCount: number, options?: ValidationOptions): T[];
|
|
152
|
+
declare function useMaximumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, maximumCount: number, options?: ValidationOptions): ReactElement[];
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns the direct child elements whose React element type exactly matches the provided type, or throws when fewer than the minimum count are found.
|
|
156
|
+
*
|
|
157
|
+
* @param children The React children value to inspect.
|
|
158
|
+
* @param type The element or component type to match against each direct child element.
|
|
159
|
+
* @param minimumCount The minimum number of matching direct child elements required.
|
|
160
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
161
|
+
* @returns The direct child elements whose type matches the provided element type.
|
|
162
|
+
*/
|
|
163
|
+
declare function useMinimumChildrenByType<T extends ElementType>(children: ReactNode, type: T, minimumCount: number, options?: ValidationOptions): ElementOfType<T>[];
|
|
102
164
|
|
|
103
|
-
type UseMinimumChildrenWhereOptions = {
|
|
104
|
-
/**
|
|
105
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
106
|
-
*/
|
|
107
|
-
traceCode?: string;
|
|
108
|
-
/**
|
|
109
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
110
|
-
*/
|
|
111
|
-
childName?: string;
|
|
112
|
-
};
|
|
113
165
|
/**
|
|
114
166
|
* Returns the direct child elements that satisfy the provided predicate, or throws when fewer than the minimum count are found.
|
|
115
167
|
*
|
|
@@ -119,19 +171,19 @@ type UseMinimumChildrenWhereOptions = {
|
|
|
119
171
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
120
172
|
* @returns The direct child elements that satisfy the provided predicate.
|
|
121
173
|
*/
|
|
122
|
-
declare function
|
|
123
|
-
declare function
|
|
174
|
+
declare function useMinimumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: ValidationOptions): T[];
|
|
175
|
+
declare function useMinimumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: ValidationOptions): ReactElement[];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Returns the first direct child element whose React element type exactly matches the provided type, or throws when no match is found.
|
|
179
|
+
*
|
|
180
|
+
* @param children The React children value to inspect.
|
|
181
|
+
* @param type The element or component type to match against each direct child element.
|
|
182
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
183
|
+
* @returns The first direct child element whose type matches the provided element type.
|
|
184
|
+
*/
|
|
185
|
+
declare function useRequiredChildByType<T extends ElementType>(children: ReactNode, type: T, options?: ValidationOptions): ElementOfType<T>;
|
|
124
186
|
|
|
125
|
-
type UseRequiredChildWhereOptions = {
|
|
126
|
-
/**
|
|
127
|
-
* An optional consumer-defined trace code that is prefixed to the thrown validation message.
|
|
128
|
-
*/
|
|
129
|
-
traceCode?: string;
|
|
130
|
-
/**
|
|
131
|
-
* An optional human-readable child name that is included in the thrown validation message.
|
|
132
|
-
*/
|
|
133
|
-
childName?: string;
|
|
134
|
-
};
|
|
135
187
|
/**
|
|
136
188
|
* Returns the first direct child element that satisfies the provided predicate, or throws when no match is found.
|
|
137
189
|
*
|
|
@@ -140,8 +192,8 @@ type UseRequiredChildWhereOptions = {
|
|
|
140
192
|
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
141
193
|
* @returns The first direct child element that satisfies the provided predicate.
|
|
142
194
|
*/
|
|
143
|
-
declare function
|
|
144
|
-
declare function
|
|
195
|
+
declare function useRequiredChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
196
|
+
declare function useRequiredChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
145
197
|
|
|
146
198
|
/**
|
|
147
199
|
* Normalizes a React children value into an array containing only valid direct child elements.
|
|
@@ -168,4 +220,4 @@ declare function isElementOfType<T extends ElementType>(element: ReactElement, t
|
|
|
168
220
|
*/
|
|
169
221
|
declare function isReactElement(node: ReactNode): node is ReactElement;
|
|
170
222
|
|
|
171
|
-
export { type
|
|
223
|
+
export { type ChildrenCountBounds, type ElementOfType, type ValidationOptions, childrenToElements, isElementOfType, isReactElement, useBoundedChildrenByType, useBoundedChildrenMatching, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useRequiredChildByType, useRequiredChildMatching };
|