victory-create-container 37.0.2 → 37.1.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.
@@ -1,44 +1,399 @@
1
1
  import React from "react";
2
- export declare type ContainerType = "brush" | "cursor" | "selection" | "voronoi" | "zoom";
3
- declare type MixinFunction = (...args: any[]) => any;
4
- export declare const combineContainerMixins: (mixins: MixinFunction[], Container: React.ComponentType<any>) => {
5
- new (): {
6
- [x: string]: any;
7
- getChildren(props: any): any;
8
- };
9
- [x: string]: any;
2
+ import { VictoryContainer } from "victory-core";
3
+ export declare type ContainerType = "zoom" | "selection" | "brush" | "cursor" | "voronoi";
4
+ declare type ContainerComponents = Record<ContainerType, React.ComponentType<any> & {
5
+ defaultEvents: (props: any) => any[];
6
+ }>;
7
+ export declare function makeCreateContainerFunction<TContainerComponents extends ContainerComponents>(containerComponents: TContainerComponents, VictoryContainerBase: typeof VictoryContainer): <TContainerA extends ContainerType, TContainerB extends ContainerType>(containerA: TContainerA, containerB: TContainerB) => {
8
+ (props: React.ComponentProps<TContainerComponents[TContainerA]> & React.ComponentProps<TContainerComponents[TContainerB]>): JSX.Element;
10
9
  displayName: string;
11
- propTypes: any;
12
- defaultProps: any;
13
- defaultEvents(props: any): ({
10
+ role: string;
11
+ defaultEvents(props: React.ComponentProps<TContainerComponents[TContainerA]> & React.ComponentProps<TContainerComponents[TContainerB]>): ({
14
12
  target: string;
15
13
  eventHandlers: any;
16
14
  } | null)[];
17
15
  };
18
- export declare const makeCreateContainerFunction: (mixinMap: Record<ContainerType, MixinFunction[]>, Container: React.ComponentType<any>) => (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
19
- new (): {
20
- [x: string]: any;
21
- getChildren(props: any): any;
22
- };
23
- [x: string]: any;
16
+ export declare const createContainer: <TContainerA extends ContainerType, TContainerB extends ContainerType>(containerA: TContainerA, containerB: TContainerB) => {
17
+ (props: React.ComponentProps<{
18
+ zoom: {
19
+ (initialProps: import("victory-zoom-container").VictoryZoomContainerProps): JSX.Element;
20
+ role: string;
21
+ defaultEvents(initialProps: import("victory-zoom-container").VictoryZoomContainerProps): {
22
+ target: string;
23
+ eventHandlers: {
24
+ onMouseDown: import("victory-core").VictoryEventHandler;
25
+ onTouchStart: import("victory-core").VictoryEventHandler;
26
+ onMouseUp: import("victory-core").VictoryEventHandler;
27
+ onTouchEnd: import("victory-core").VictoryEventHandler;
28
+ onMouseLeave: import("victory-core").VictoryEventHandler;
29
+ onTouchCancel: import("victory-core").VictoryEventHandler;
30
+ onMouseMove: import("victory-core").VictoryEventHandler;
31
+ onTouchMove: import("victory-core").VictoryEventHandler;
32
+ onWheel: import("victory-core").VictoryEventHandler;
33
+ };
34
+ }[];
35
+ };
36
+ selection: {
37
+ (initialProps: import("victory-selection-container").VictorySelectionContainerProps): JSX.Element;
38
+ role: string;
39
+ defaultEvents(initialProps: import("victory-selection-container").VictorySelectionContainerProps): {
40
+ target: string;
41
+ eventHandlers: {
42
+ onMouseDown: import("victory-core").VictoryEventHandler;
43
+ onTouchStart: import("victory-core").VictoryEventHandler;
44
+ onMouseMove: import("victory-core").VictoryEventHandler;
45
+ onTouchMove: import("victory-core").VictoryEventHandler;
46
+ onMouseUp: import("victory-core").VictoryEventHandler;
47
+ onTouchEnd: import("victory-core").VictoryEventHandler;
48
+ };
49
+ }[];
50
+ };
51
+ brush: {
52
+ (initialProps: import("victory-brush-container").VictoryBrushContainerProps): JSX.Element;
53
+ role: string;
54
+ defaultEvents(initialProps: import("victory-brush-container").VictoryBrushContainerProps): {
55
+ target: string;
56
+ eventHandlers: {
57
+ onMouseDown: import("victory-core").VictoryEventHandler;
58
+ onTouchStart: import("victory-core").VictoryEventHandler;
59
+ onGlobalMouseMove: import("victory-core").VictoryEventHandler;
60
+ onGlobalTouchMove: import("victory-core").VictoryEventHandler;
61
+ onGlobalMouseUp: import("victory-core").VictoryEventHandler;
62
+ onGlobalTouchEnd: import("victory-core").VictoryEventHandler;
63
+ onGlobalTouchCancel: import("victory-core").VictoryEventHandler;
64
+ };
65
+ }[];
66
+ };
67
+ cursor: {
68
+ (initialProps: import("victory-cursor-container").VictoryCursorContainerProps): JSX.Element;
69
+ role: string;
70
+ defaultEvents(initialProps: import("victory-cursor-container").VictoryCursorContainerProps): {
71
+ target: string;
72
+ eventHandlers: {
73
+ onMouseLeave: import("victory-core").VictoryEventHandler;
74
+ onMouseMove: import("victory-core").VictoryEventHandler;
75
+ onTouchMove: import("victory-core").VictoryEventHandler;
76
+ };
77
+ }[];
78
+ };
79
+ voronoi: {
80
+ (initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): JSX.Element;
81
+ role: string;
82
+ defaultEvents(initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): ({
83
+ target: string;
84
+ eventHandlers: {
85
+ onMouseLeave: import("victory-core").VictoryEventHandler;
86
+ onTouchCancel: import("victory-core").VictoryEventHandler;
87
+ onMouseMove: import("victory-core").VictoryEventHandler;
88
+ onTouchMove: import("victory-core").VictoryEventHandler;
89
+ onMouseOver?: undefined;
90
+ onMouseOut?: undefined;
91
+ };
92
+ } | {
93
+ target: string;
94
+ eventHandlers: {
95
+ onMouseLeave?: undefined;
96
+ onTouchCancel?: undefined;
97
+ onMouseMove?: undefined;
98
+ onTouchMove?: undefined;
99
+ onMouseOver?: undefined;
100
+ onMouseOut?: undefined;
101
+ } | {
102
+ onMouseOver: () => null;
103
+ onMouseOut: () => null;
104
+ onMouseMove: () => null;
105
+ onMouseLeave?: undefined;
106
+ onTouchCancel?: undefined;
107
+ onTouchMove?: undefined;
108
+ };
109
+ })[];
110
+ };
111
+ }[TContainerA]> & React.ComponentProps<{
112
+ zoom: {
113
+ (initialProps: import("victory-zoom-container").VictoryZoomContainerProps): JSX.Element;
114
+ role: string;
115
+ defaultEvents(initialProps: import("victory-zoom-container").VictoryZoomContainerProps): {
116
+ target: string;
117
+ eventHandlers: {
118
+ onMouseDown: import("victory-core").VictoryEventHandler;
119
+ onTouchStart: import("victory-core").VictoryEventHandler;
120
+ onMouseUp: import("victory-core").VictoryEventHandler;
121
+ onTouchEnd: import("victory-core").VictoryEventHandler;
122
+ onMouseLeave: import("victory-core").VictoryEventHandler;
123
+ onTouchCancel: import("victory-core").VictoryEventHandler;
124
+ onMouseMove: import("victory-core").VictoryEventHandler;
125
+ onTouchMove: import("victory-core").VictoryEventHandler;
126
+ onWheel: import("victory-core").VictoryEventHandler;
127
+ };
128
+ }[];
129
+ };
130
+ selection: {
131
+ (initialProps: import("victory-selection-container").VictorySelectionContainerProps): JSX.Element;
132
+ role: string;
133
+ defaultEvents(initialProps: import("victory-selection-container").VictorySelectionContainerProps): {
134
+ target: string;
135
+ eventHandlers: {
136
+ onMouseDown: import("victory-core").VictoryEventHandler;
137
+ onTouchStart: import("victory-core").VictoryEventHandler;
138
+ onMouseMove: import("victory-core").VictoryEventHandler;
139
+ onTouchMove: import("victory-core").VictoryEventHandler;
140
+ onMouseUp: import("victory-core").VictoryEventHandler;
141
+ onTouchEnd: import("victory-core").VictoryEventHandler;
142
+ };
143
+ }[];
144
+ };
145
+ brush: {
146
+ (initialProps: import("victory-brush-container").VictoryBrushContainerProps): JSX.Element;
147
+ role: string;
148
+ defaultEvents(initialProps: import("victory-brush-container").VictoryBrushContainerProps): {
149
+ target: string;
150
+ eventHandlers: {
151
+ onMouseDown: import("victory-core").VictoryEventHandler;
152
+ onTouchStart: import("victory-core").VictoryEventHandler;
153
+ onGlobalMouseMove: import("victory-core").VictoryEventHandler;
154
+ onGlobalTouchMove: import("victory-core").VictoryEventHandler;
155
+ onGlobalMouseUp: import("victory-core").VictoryEventHandler;
156
+ onGlobalTouchEnd: import("victory-core").VictoryEventHandler;
157
+ onGlobalTouchCancel: import("victory-core").VictoryEventHandler;
158
+ };
159
+ }[];
160
+ };
161
+ cursor: {
162
+ (initialProps: import("victory-cursor-container").VictoryCursorContainerProps): JSX.Element;
163
+ role: string;
164
+ defaultEvents(initialProps: import("victory-cursor-container").VictoryCursorContainerProps): {
165
+ target: string;
166
+ eventHandlers: {
167
+ onMouseLeave: import("victory-core").VictoryEventHandler;
168
+ onMouseMove: import("victory-core").VictoryEventHandler;
169
+ onTouchMove: import("victory-core").VictoryEventHandler;
170
+ };
171
+ }[];
172
+ };
173
+ voronoi: {
174
+ (initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): JSX.Element;
175
+ role: string;
176
+ defaultEvents(initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): ({
177
+ target: string;
178
+ eventHandlers: {
179
+ onMouseLeave: import("victory-core").VictoryEventHandler;
180
+ onTouchCancel: import("victory-core").VictoryEventHandler;
181
+ onMouseMove: import("victory-core").VictoryEventHandler;
182
+ onTouchMove: import("victory-core").VictoryEventHandler;
183
+ onMouseOver?: undefined;
184
+ onMouseOut?: undefined;
185
+ };
186
+ } | {
187
+ target: string;
188
+ eventHandlers: {
189
+ onMouseLeave?: undefined;
190
+ onTouchCancel?: undefined;
191
+ onMouseMove?: undefined;
192
+ onTouchMove?: undefined;
193
+ onMouseOver?: undefined;
194
+ onMouseOut?: undefined;
195
+ } | {
196
+ onMouseOver: () => null;
197
+ onMouseOut: () => null;
198
+ onMouseMove: () => null;
199
+ onMouseLeave?: undefined;
200
+ onTouchCancel?: undefined;
201
+ onTouchMove?: undefined;
202
+ };
203
+ })[];
204
+ };
205
+ }[TContainerB]>): JSX.Element;
24
206
  displayName: string;
25
- propTypes: any;
26
- defaultProps: any;
27
- defaultEvents(props: any): ({
28
- target: string;
29
- eventHandlers: any;
30
- } | null)[];
31
- };
32
- export declare const createContainer: (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
33
- new (): {
34
- [x: string]: any;
35
- getChildren(props: any): any;
36
- };
37
- [x: string]: any;
38
- displayName: string;
39
- propTypes: any;
40
- defaultProps: any;
41
- defaultEvents(props: any): ({
207
+ role: string;
208
+ defaultEvents(props: React.ComponentProps<{
209
+ zoom: {
210
+ (initialProps: import("victory-zoom-container").VictoryZoomContainerProps): JSX.Element;
211
+ role: string;
212
+ defaultEvents(initialProps: import("victory-zoom-container").VictoryZoomContainerProps): {
213
+ target: string;
214
+ eventHandlers: {
215
+ onMouseDown: import("victory-core").VictoryEventHandler;
216
+ onTouchStart: import("victory-core").VictoryEventHandler;
217
+ onMouseUp: import("victory-core").VictoryEventHandler;
218
+ onTouchEnd: import("victory-core").VictoryEventHandler;
219
+ onMouseLeave: import("victory-core").VictoryEventHandler;
220
+ onTouchCancel: import("victory-core").VictoryEventHandler;
221
+ onMouseMove: import("victory-core").VictoryEventHandler;
222
+ onTouchMove: import("victory-core").VictoryEventHandler;
223
+ onWheel: import("victory-core").VictoryEventHandler;
224
+ };
225
+ }[];
226
+ };
227
+ selection: {
228
+ (initialProps: import("victory-selection-container").VictorySelectionContainerProps): JSX.Element;
229
+ role: string;
230
+ defaultEvents(initialProps: import("victory-selection-container").VictorySelectionContainerProps): {
231
+ target: string;
232
+ eventHandlers: {
233
+ onMouseDown: import("victory-core").VictoryEventHandler;
234
+ onTouchStart: import("victory-core").VictoryEventHandler;
235
+ onMouseMove: import("victory-core").VictoryEventHandler;
236
+ onTouchMove: import("victory-core").VictoryEventHandler;
237
+ onMouseUp: import("victory-core").VictoryEventHandler;
238
+ onTouchEnd: import("victory-core").VictoryEventHandler;
239
+ };
240
+ }[];
241
+ };
242
+ brush: {
243
+ (initialProps: import("victory-brush-container").VictoryBrushContainerProps): JSX.Element;
244
+ role: string;
245
+ defaultEvents(initialProps: import("victory-brush-container").VictoryBrushContainerProps): {
246
+ target: string;
247
+ eventHandlers: {
248
+ onMouseDown: import("victory-core").VictoryEventHandler;
249
+ onTouchStart: import("victory-core").VictoryEventHandler;
250
+ onGlobalMouseMove: import("victory-core").VictoryEventHandler;
251
+ onGlobalTouchMove: import("victory-core").VictoryEventHandler;
252
+ onGlobalMouseUp: import("victory-core").VictoryEventHandler;
253
+ onGlobalTouchEnd: import("victory-core").VictoryEventHandler;
254
+ onGlobalTouchCancel: import("victory-core").VictoryEventHandler;
255
+ };
256
+ }[];
257
+ };
258
+ cursor: {
259
+ (initialProps: import("victory-cursor-container").VictoryCursorContainerProps): JSX.Element;
260
+ role: string;
261
+ defaultEvents(initialProps: import("victory-cursor-container").VictoryCursorContainerProps): {
262
+ target: string;
263
+ eventHandlers: {
264
+ onMouseLeave: import("victory-core").VictoryEventHandler;
265
+ onMouseMove: import("victory-core").VictoryEventHandler;
266
+ onTouchMove: import("victory-core").VictoryEventHandler;
267
+ };
268
+ }[];
269
+ };
270
+ voronoi: {
271
+ (initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): JSX.Element;
272
+ role: string;
273
+ defaultEvents(initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): ({
274
+ target: string;
275
+ eventHandlers: {
276
+ onMouseLeave: import("victory-core").VictoryEventHandler;
277
+ onTouchCancel: import("victory-core").VictoryEventHandler;
278
+ onMouseMove: import("victory-core").VictoryEventHandler;
279
+ onTouchMove: import("victory-core").VictoryEventHandler;
280
+ onMouseOver?: undefined;
281
+ onMouseOut?: undefined;
282
+ };
283
+ } | {
284
+ target: string;
285
+ eventHandlers: {
286
+ onMouseLeave?: undefined;
287
+ onTouchCancel?: undefined;
288
+ onMouseMove?: undefined;
289
+ onTouchMove?: undefined;
290
+ onMouseOver?: undefined;
291
+ onMouseOut?: undefined;
292
+ } | {
293
+ onMouseOver: () => null;
294
+ onMouseOut: () => null;
295
+ onMouseMove: () => null;
296
+ onMouseLeave?: undefined;
297
+ onTouchCancel?: undefined;
298
+ onTouchMove?: undefined;
299
+ };
300
+ })[];
301
+ };
302
+ }[TContainerA]> & React.ComponentProps<{
303
+ zoom: {
304
+ (initialProps: import("victory-zoom-container").VictoryZoomContainerProps): JSX.Element;
305
+ role: string;
306
+ defaultEvents(initialProps: import("victory-zoom-container").VictoryZoomContainerProps): {
307
+ target: string;
308
+ eventHandlers: {
309
+ onMouseDown: import("victory-core").VictoryEventHandler;
310
+ onTouchStart: import("victory-core").VictoryEventHandler;
311
+ onMouseUp: import("victory-core").VictoryEventHandler;
312
+ onTouchEnd: import("victory-core").VictoryEventHandler;
313
+ onMouseLeave: import("victory-core").VictoryEventHandler;
314
+ onTouchCancel: import("victory-core").VictoryEventHandler;
315
+ onMouseMove: import("victory-core").VictoryEventHandler;
316
+ onTouchMove: import("victory-core").VictoryEventHandler;
317
+ onWheel: import("victory-core").VictoryEventHandler;
318
+ };
319
+ }[];
320
+ };
321
+ selection: {
322
+ (initialProps: import("victory-selection-container").VictorySelectionContainerProps): JSX.Element;
323
+ role: string;
324
+ defaultEvents(initialProps: import("victory-selection-container").VictorySelectionContainerProps): {
325
+ target: string;
326
+ eventHandlers: {
327
+ onMouseDown: import("victory-core").VictoryEventHandler;
328
+ onTouchStart: import("victory-core").VictoryEventHandler;
329
+ onMouseMove: import("victory-core").VictoryEventHandler;
330
+ onTouchMove: import("victory-core").VictoryEventHandler;
331
+ onMouseUp: import("victory-core").VictoryEventHandler;
332
+ onTouchEnd: import("victory-core").VictoryEventHandler;
333
+ };
334
+ }[];
335
+ };
336
+ brush: {
337
+ (initialProps: import("victory-brush-container").VictoryBrushContainerProps): JSX.Element;
338
+ role: string;
339
+ defaultEvents(initialProps: import("victory-brush-container").VictoryBrushContainerProps): {
340
+ target: string;
341
+ eventHandlers: {
342
+ onMouseDown: import("victory-core").VictoryEventHandler;
343
+ onTouchStart: import("victory-core").VictoryEventHandler;
344
+ onGlobalMouseMove: import("victory-core").VictoryEventHandler;
345
+ onGlobalTouchMove: import("victory-core").VictoryEventHandler;
346
+ onGlobalMouseUp: import("victory-core").VictoryEventHandler;
347
+ onGlobalTouchEnd: import("victory-core").VictoryEventHandler;
348
+ onGlobalTouchCancel: import("victory-core").VictoryEventHandler;
349
+ };
350
+ }[];
351
+ };
352
+ cursor: {
353
+ (initialProps: import("victory-cursor-container").VictoryCursorContainerProps): JSX.Element;
354
+ role: string;
355
+ defaultEvents(initialProps: import("victory-cursor-container").VictoryCursorContainerProps): {
356
+ target: string;
357
+ eventHandlers: {
358
+ onMouseLeave: import("victory-core").VictoryEventHandler;
359
+ onMouseMove: import("victory-core").VictoryEventHandler;
360
+ onTouchMove: import("victory-core").VictoryEventHandler;
361
+ };
362
+ }[];
363
+ };
364
+ voronoi: {
365
+ (initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): JSX.Element;
366
+ role: string;
367
+ defaultEvents(initialProps: import("victory-voronoi-container").VictoryVoronoiContainerProps): ({
368
+ target: string;
369
+ eventHandlers: {
370
+ onMouseLeave: import("victory-core").VictoryEventHandler;
371
+ onTouchCancel: import("victory-core").VictoryEventHandler;
372
+ onMouseMove: import("victory-core").VictoryEventHandler;
373
+ onTouchMove: import("victory-core").VictoryEventHandler;
374
+ onMouseOver?: undefined;
375
+ onMouseOut?: undefined;
376
+ };
377
+ } | {
378
+ target: string;
379
+ eventHandlers: {
380
+ onMouseLeave?: undefined;
381
+ onTouchCancel?: undefined;
382
+ onMouseMove?: undefined;
383
+ onTouchMove?: undefined;
384
+ onMouseOver?: undefined;
385
+ onMouseOut?: undefined;
386
+ } | {
387
+ onMouseOver: () => null;
388
+ onMouseOut: () => null;
389
+ onMouseMove: () => null;
390
+ onMouseLeave?: undefined;
391
+ onTouchCancel?: undefined;
392
+ onTouchMove?: undefined;
393
+ };
394
+ })[];
395
+ };
396
+ }[TContainerB]>): ({
42
397
  target: string;
43
398
  eventHandlers: any;
44
399
  } | null)[];
@@ -1,14 +1,14 @@
1
+ import _toPairs from "lodash/toPairs";
1
2
  import _isEmpty from "lodash/isEmpty";
2
- import _flow from "lodash/flow";
3
- import _forOwn from "lodash/forOwn";
4
3
  import _groupBy from "lodash/groupBy";
5
- import _toPairs from "lodash/toPairs";
6
- import { Helpers, VictoryContainer, Log } from "victory-core";
7
- import { voronoiContainerMixin } from "victory-voronoi-container";
8
- import { zoomContainerMixin } from "victory-zoom-container";
9
- import { selectionContainerMixin } from "victory-selection-container";
10
- import { brushContainerMixin } from "victory-brush-container";
11
- import { cursorContainerMixin } from "victory-cursor-container";
4
+ import _forOwn from "lodash/forOwn";
5
+ import { VictoryZoomContainer, useVictoryZoomContainer } from "victory-zoom-container";
6
+ import { VictorySelectionContainer, useVictorySelectionContainer } from "victory-selection-container";
7
+ import React from "react";
8
+ import { VictoryContainer } from "victory-core";
9
+ import { VictoryVoronoiContainer, useVictoryVoronoiContainer } from "victory-voronoi-container";
10
+ import { VictoryCursorContainer, useVictoryCursorContainer } from "victory-cursor-container";
11
+ import { VictoryBrushContainer, useVictoryBrushContainer } from "victory-brush-container";
12
12
  function ensureArray(thing) {
13
13
  if (!thing) {
14
14
  return [];
@@ -54,65 +54,55 @@ const combineDefaultEvents = defaultEvents => {
54
54
  });
55
55
  return events.filter(Boolean);
56
56
  };
57
- export const combineContainerMixins = (mixins, Container) => {
58
- // similar to Object.assign(A, B), this function will decide conflicts in favor mixinB.
59
- // this applies to propTypes and defaultProps.
60
- // getChildren will call A's getChildren() and pass the resulting children to B's.
61
- // defaultEvents attempts to resolve any conflicts between A and B's defaultEvents.
62
- const Classes = mixins.map(mixin => mixin(Container));
63
- const instances = Classes.map(Class => new Class());
64
- const NaiveCombinedContainer = _flow(mixins)(Container);
65
- const displayType = Classes.map(Class => {
66
- const match = Class.displayName.match(/Victory(.*)Container/);
67
- return match[1] || "";
68
- }).join("");
69
- return class VictoryCombinedContainer extends NaiveCombinedContainer {
70
- static displayName = `Victory${displayType}Container`;
71
- static propTypes = Classes.reduce((propTypes, Class) => ({
72
- ...propTypes,
73
- ...Class.propTypes
74
- }), {});
75
- static defaultProps = Classes.reduce((defaultProps, Class) => ({
76
- ...defaultProps,
77
- ...Class.defaultProps
78
- }), {});
79
- static defaultEvents(props) {
80
- return combineDefaultEvents(Classes.reduce((defaultEvents, Class) => {
81
- const events = Helpers.isFunction(Class.defaultEvents) ? Class.defaultEvents(props) : Class.defaultEvents;
82
- return [...defaultEvents, ...events];
83
- }, []));
84
- }
85
- getChildren(props) {
86
- return instances.reduce((children, instance) => instance.getChildren({
87
- ...props,
88
- children
89
- }), props.children);
90
- }
91
- };
92
- };
93
- const checkBehaviorName = (behavior, behaviors) => {
94
- if (behavior && !behaviors.includes(behavior)) {
95
- Log.warn(`"${behavior}" is not a valid behavior. Choose from [${behaviors.join(", ")}].`);
96
- }
57
+ /**
58
+ * Container hooks are used to provide the container logic to the container components through props and a modified children object
59
+ * - These hooks contain shared logic for both web and Victory Native containers.
60
+ * - In this utility, we call multiple of these hooks with the props returned by the previous to combine the container logic.
61
+ */
62
+ const CONTAINER_HOOKS = {
63
+ zoom: useVictoryZoomContainer,
64
+ selection: useVictorySelectionContainer,
65
+ brush: useVictoryBrushContainer,
66
+ cursor: useVictoryCursorContainer,
67
+ voronoi: useVictoryVoronoiContainer
97
68
  };
98
- export const makeCreateContainerFunction = (mixinMap, Container) => function (behaviorA, behaviorB) {
99
- const behaviors = Object.keys(mixinMap);
100
- checkBehaviorName(behaviorA, behaviors);
101
- checkBehaviorName(behaviorB, behaviors);
102
- if (arguments.length <= 2 ? 0 : arguments.length - 2) {
103
- Log.warn("too many arguments given to createContainer (maximum accepted: 2).");
104
- }
105
- const firstMixins = mixinMap[behaviorA];
106
- const secondMixins = mixinMap[behaviorB] || [];
107
- if (!firstMixins) {
108
- return Container;
109
- }
110
- return combineContainerMixins([...firstMixins, ...secondMixins], Container);
69
+
70
+ /**
71
+ * Container hooks are wrappers that return a VictoryContainer with the props provided by their respective hooks, and the modified children.
72
+ * - These containers are specific to the web. Victory Native has its own container components.
73
+ * - For this utility, we only need the container components to extract the defaultEvents.
74
+ */
75
+ const CONTAINER_COMPONENTS_WEB = {
76
+ zoom: VictoryZoomContainer,
77
+ selection: VictorySelectionContainer,
78
+ brush: VictoryBrushContainer,
79
+ cursor: VictoryCursorContainer,
80
+ voronoi: VictoryVoronoiContainer
111
81
  };
112
- export const createContainer = makeCreateContainerFunction({
113
- zoom: [zoomContainerMixin],
114
- voronoi: [voronoiContainerMixin],
115
- selection: [selectionContainerMixin],
116
- cursor: [cursorContainerMixin],
117
- brush: [brushContainerMixin]
118
- }, VictoryContainer);
82
+ export function makeCreateContainerFunction(containerComponents, VictoryContainerBase) {
83
+ return function combineContainers(containerA, containerB) {
84
+ const ContainerA = containerComponents[containerA];
85
+ const ContainerB = containerComponents[containerB];
86
+ const useContainerA = CONTAINER_HOOKS[containerA];
87
+ const useContainerB = CONTAINER_HOOKS[containerB];
88
+ const CombinedContainer = props => {
89
+ const {
90
+ children: childrenA,
91
+ props: propsA
92
+ } = useContainerA(props);
93
+ const {
94
+ children: combinedChildren,
95
+ props: combinedProps
96
+ } = useContainerB({
97
+ ...propsA,
98
+ children: childrenA
99
+ });
100
+ return /*#__PURE__*/React.createElement(VictoryContainerBase, combinedProps, combinedChildren);
101
+ };
102
+ CombinedContainer.displayName = `Victory${containerA}${containerB}Container`;
103
+ CombinedContainer.role = "container";
104
+ CombinedContainer.defaultEvents = props => combineDefaultEvents([...ContainerA.defaultEvents(props), ...ContainerB.defaultEvents(props)]);
105
+ return CombinedContainer;
106
+ };
107
+ }
108
+ export const createContainer = makeCreateContainerFunction(CONTAINER_COMPONENTS_WEB, VictoryContainer);