victory-core 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.
- package/CHANGELOG.md +8 -0
- package/dist/victory-core.js +395 -358
- package/dist/victory-core.min.js +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/types/prop-types.d.ts +1 -0
- package/es/victory-container/victory-container.d.ts +29 -35
- package/es/victory-container/victory-container.js +134 -162
- package/es/victory-portal/portal-context.d.ts +9 -8
- package/es/victory-portal/portal-context.js +34 -6
- package/es/victory-portal/portal-outlet.d.ts +12 -0
- package/es/victory-portal/portal-outlet.js +14 -0
- package/es/victory-portal/portal.d.ts +1 -12
- package/es/victory-portal/portal.js +6 -32
- package/es/victory-portal/victory-portal.d.ts +5 -22
- package/es/victory-portal/victory-portal.js +37 -52
- package/es/victory-util/index.d.ts +1 -0
- package/es/victory-util/index.js +1 -0
- package/es/victory-util/merge-refs.d.ts +13 -0
- package/es/victory-util/merge-refs.js +23 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +16 -4
- package/lib/types/prop-types.d.ts +1 -0
- package/lib/victory-container/victory-container.d.ts +29 -35
- package/lib/victory-container/victory-container.js +136 -163
- package/lib/victory-portal/portal-context.d.ts +9 -8
- package/lib/victory-portal/portal-context.js +37 -7
- package/lib/victory-portal/portal-outlet.d.ts +12 -0
- package/lib/victory-portal/portal-outlet.js +22 -0
- package/lib/victory-portal/portal.d.ts +1 -12
- package/lib/victory-portal/portal.js +6 -33
- package/lib/victory-portal/victory-portal.d.ts +5 -22
- package/lib/victory-portal/victory-portal.js +37 -52
- package/lib/victory-util/index.d.ts +1 -0
- package/lib/victory-util/index.js +12 -0
- package/lib/victory-util/merge-refs.d.ts +13 -0
- package/lib/victory-util/merge-refs.js +31 -0
- package/package.json +2 -2
- package/src/index.ts +2 -1
- package/src/types/prop-types.ts +7 -0
- package/src/victory-container/victory-container.tsx +167 -195
- package/src/victory-portal/portal-context.tsx +63 -0
- package/src/victory-portal/portal-outlet.tsx +26 -0
- package/src/victory-portal/portal.tsx +5 -42
- package/src/victory-portal/victory-portal.tsx +44 -73
- package/src/victory-util/index.ts +1 -0
- package/src/victory-util/merge-refs.ts +26 -0
- package/src/victory-portal/portal-context.ts +0 -14
package/es/index.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export * from "./victory-clip-container/victory-clip-container";
|
|
|
9
9
|
export * from "./victory-theme/types";
|
|
10
10
|
export * from "./victory-theme/victory-theme";
|
|
11
11
|
export * from "./victory-portal/portal";
|
|
12
|
-
export * from "./victory-portal/portal-context";
|
|
13
12
|
export * from "./victory-portal/victory-portal";
|
|
13
|
+
export * from "./victory-portal/portal-context";
|
|
14
|
+
export * from "./victory-portal/portal-outlet";
|
|
14
15
|
export * from "./victory-primitives";
|
|
15
16
|
export { Border as Box } from "./victory-primitives";
|
|
16
17
|
export type { BorderProps as BoxProps } from "./victory-primitives";
|
package/es/index.js
CHANGED
|
@@ -9,8 +9,9 @@ export * from "./victory-clip-container/victory-clip-container";
|
|
|
9
9
|
export * from "./victory-theme/types";
|
|
10
10
|
export * from "./victory-theme/victory-theme";
|
|
11
11
|
export * from "./victory-portal/portal";
|
|
12
|
-
export * from "./victory-portal/portal-context";
|
|
13
12
|
export * from "./victory-portal/victory-portal";
|
|
13
|
+
export * from "./victory-portal/portal-context";
|
|
14
|
+
export * from "./victory-portal/portal-outlet";
|
|
14
15
|
export * from "./victory-primitives";
|
|
15
16
|
export { Border as Box } from "./victory-primitives";
|
|
16
17
|
export * from "./victory-util";
|
package/es/types/prop-types.d.ts
CHANGED
|
@@ -126,5 +126,6 @@ export declare type CoordinatesPropType = {
|
|
|
126
126
|
x: number;
|
|
127
127
|
y: number;
|
|
128
128
|
};
|
|
129
|
+
export declare type VictoryEventHandler = (event?: any, targetProps?: any, eventKey?: any, context?: any) => void;
|
|
129
130
|
export {};
|
|
130
131
|
//# sourceMappingURL=prop-types.d.ts.map
|
|
@@ -14,9 +14,6 @@ export interface VictoryContainerProps {
|
|
|
14
14
|
height?: number;
|
|
15
15
|
name?: string;
|
|
16
16
|
origin?: OriginType;
|
|
17
|
-
ouiaId?: number | string;
|
|
18
|
-
ouiaSafe?: boolean;
|
|
19
|
-
ouiaType?: string;
|
|
20
17
|
polar?: boolean;
|
|
21
18
|
portalComponent?: React.ReactElement;
|
|
22
19
|
portalZIndex?: number;
|
|
@@ -32,38 +29,35 @@ export interface VictoryContainerProps {
|
|
|
32
29
|
theme?: VictoryThemeDefinition;
|
|
33
30
|
title?: string;
|
|
34
31
|
width?: number;
|
|
32
|
+
ouiaId?: number | string;
|
|
33
|
+
ouiaSafe?: boolean;
|
|
34
|
+
ouiaType?: string;
|
|
35
35
|
}
|
|
36
|
-
export declare
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
export declare function useVictoryContainer<TProps extends VictoryContainerProps>(initialProps: TProps): {
|
|
37
|
+
className: string;
|
|
38
|
+
portalComponent: JSX.Element;
|
|
39
|
+
portalZIndex: number;
|
|
40
|
+
responsive: boolean;
|
|
41
|
+
role: string;
|
|
42
|
+
} & TProps & {
|
|
43
|
+
titleId: string;
|
|
44
|
+
descId: string;
|
|
45
|
+
dimensions: {
|
|
46
|
+
width: string;
|
|
47
|
+
height: string;
|
|
48
|
+
} | {
|
|
49
|
+
width: number | undefined;
|
|
50
|
+
height: number | undefined;
|
|
45
51
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
portalRegister: () => number;
|
|
58
|
-
portalDeregister: (key: any) => void;
|
|
59
|
-
saveContainerRef: (container: HTMLElement) => HTMLElement;
|
|
60
|
-
handleWheel: (e: any) => any;
|
|
61
|
-
componentDidMount(): void;
|
|
62
|
-
componentWillUnmount(): void;
|
|
63
|
-
getIdForElement(elementName: any): string;
|
|
64
|
-
getChildren(props: any): any;
|
|
65
|
-
getOUIAProps(props: any): any;
|
|
66
|
-
renderContainer(props: any, svgProps: any, style: any): JSX.Element;
|
|
67
|
-
render(): JSX.Element;
|
|
68
|
-
}
|
|
52
|
+
viewBox: string | undefined;
|
|
53
|
+
preserveAspectRatio: string | undefined;
|
|
54
|
+
ariaLabelledBy: string | undefined;
|
|
55
|
+
ariaDescribedBy: string | undefined;
|
|
56
|
+
userProps: Record<string, string>;
|
|
57
|
+
localContainerRef: React.RefObject<HTMLDivElement>;
|
|
58
|
+
};
|
|
59
|
+
export declare const VictoryContainer: {
|
|
60
|
+
(initialProps: VictoryContainerProps): JSX.Element;
|
|
61
|
+
role: string;
|
|
62
|
+
};
|
|
69
63
|
//# sourceMappingURL=victory-container.d.ts.map
|
|
@@ -1,179 +1,151 @@
|
|
|
1
|
-
import _isObject from "lodash/isObject";
|
|
2
1
|
import _uniqueId from "lodash/uniqueId";
|
|
3
|
-
import _defaults from "lodash/defaults";
|
|
4
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
5
|
-
import React from "react";
|
|
3
|
+
import React, { useRef } from "react";
|
|
6
4
|
import { Portal } from "../victory-portal/portal";
|
|
7
|
-
import { PortalContext } from "../victory-portal/portal-context";
|
|
8
|
-
import TimerContext from "../victory-util/timer-context";
|
|
9
|
-
import * as Helpers from "../victory-util/helpers";
|
|
10
5
|
import * as UserProps from "../victory-util/user-props";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
import { mergeRefs } from "../victory-util";
|
|
7
|
+
import { PortalOutlet } from "../victory-portal/portal-outlet";
|
|
8
|
+
import { PortalProvider } from "../victory-portal/portal-context";
|
|
9
|
+
const defaultProps = {
|
|
10
|
+
className: "VictoryContainer",
|
|
11
|
+
portalComponent: /*#__PURE__*/React.createElement(Portal, null),
|
|
12
|
+
portalZIndex: 99,
|
|
13
|
+
responsive: true,
|
|
14
|
+
role: "img"
|
|
15
|
+
};
|
|
16
|
+
export function useVictoryContainer(initialProps) {
|
|
17
|
+
const props = {
|
|
18
|
+
...defaultProps,
|
|
19
|
+
...initialProps
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const {
|
|
22
|
+
title,
|
|
23
|
+
desc,
|
|
24
|
+
width,
|
|
25
|
+
height,
|
|
26
|
+
responsive
|
|
27
|
+
} = props;
|
|
28
|
+
const localContainerRef = useRef(null);
|
|
22
29
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return portal;
|
|
30
|
+
// Generated ID stored in ref because it needs to persist across renders
|
|
31
|
+
const generatedId = useRef(_uniqueId("victory-container-"));
|
|
32
|
+
const containerId = props.containerId ?? generatedId.current;
|
|
33
|
+
const getIdForElement = elName => `${containerId}-${elName}`;
|
|
34
|
+
const userProps = UserProps.getSafeUserProps(props);
|
|
35
|
+
const dimensions = responsive ? {
|
|
36
|
+
width: "100%",
|
|
37
|
+
height: "100%"
|
|
38
|
+
} : {
|
|
39
|
+
width,
|
|
40
|
+
height
|
|
35
41
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const viewBox = responsive ? `0 0 ${width} ${height}` : undefined;
|
|
43
|
+
const preserveAspectRatio = responsive ? props.preserveAspectRatio : undefined;
|
|
44
|
+
const ariaLabelledBy = [title && getIdForElement("title"), props["aria-labelledby"]].filter(Boolean).join(" ") || undefined;
|
|
45
|
+
const ariaDescribedBy = [desc && getIdForElement("desc"), props["aria-describedby"]].filter(Boolean).join(" ") || undefined;
|
|
46
|
+
const titleId = getIdForElement("title");
|
|
47
|
+
const descId = getIdForElement("desc");
|
|
48
|
+
return {
|
|
49
|
+
...props,
|
|
50
|
+
titleId,
|
|
51
|
+
descId,
|
|
52
|
+
dimensions,
|
|
53
|
+
viewBox,
|
|
54
|
+
preserveAspectRatio,
|
|
55
|
+
ariaLabelledBy,
|
|
56
|
+
ariaDescribedBy,
|
|
57
|
+
userProps,
|
|
58
|
+
localContainerRef
|
|
45
59
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
60
|
+
}
|
|
61
|
+
export const VictoryContainer = initialProps => {
|
|
62
|
+
const {
|
|
63
|
+
role,
|
|
64
|
+
title,
|
|
65
|
+
desc,
|
|
66
|
+
children,
|
|
67
|
+
className,
|
|
68
|
+
portalZIndex,
|
|
69
|
+
portalComponent,
|
|
70
|
+
width,
|
|
71
|
+
height,
|
|
72
|
+
style,
|
|
73
|
+
tabIndex,
|
|
74
|
+
responsive,
|
|
75
|
+
events,
|
|
76
|
+
ouiaId,
|
|
77
|
+
ouiaSafe,
|
|
78
|
+
ouiaType,
|
|
79
|
+
dimensions,
|
|
80
|
+
ariaDescribedBy,
|
|
81
|
+
ariaLabelledBy,
|
|
82
|
+
viewBox,
|
|
83
|
+
preserveAspectRatio,
|
|
84
|
+
userProps,
|
|
85
|
+
titleId,
|
|
86
|
+
descId,
|
|
87
|
+
containerRef,
|
|
88
|
+
localContainerRef
|
|
89
|
+
} = useVictoryContainer(initialProps);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
if (!events?.onWheel) return;
|
|
92
|
+
const handleWheel = e => e.preventDefault();
|
|
93
|
+
const container = localContainerRef?.current;
|
|
94
|
+
container?.addEventListener("wheel", handleWheel);
|
|
95
|
+
return () => {
|
|
96
|
+
container?.removeEventListener("wheel", handleWheel);
|
|
84
97
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
height,
|
|
94
|
-
portalZIndex,
|
|
95
|
-
responsive
|
|
96
|
-
} = props;
|
|
97
|
-
const children = this.getChildren(props);
|
|
98
|
-
const dimensions = responsive ? {
|
|
99
|
-
width: "100%",
|
|
100
|
-
height: "100%"
|
|
101
|
-
} : {
|
|
102
|
-
width,
|
|
103
|
-
height
|
|
104
|
-
};
|
|
105
|
-
const divStyle = Object.assign({
|
|
98
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
99
|
+
}, []);
|
|
100
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
className: className,
|
|
102
|
+
style: {
|
|
103
|
+
...style,
|
|
104
|
+
width: responsive ? style?.width : dimensions.width,
|
|
105
|
+
height: responsive ? style?.height : dimensions.height,
|
|
106
106
|
pointerEvents: "none",
|
|
107
107
|
touchAction: "none",
|
|
108
108
|
position: "relative"
|
|
109
|
-
},
|
|
110
|
-
|
|
109
|
+
},
|
|
110
|
+
"data-ouia-component-id": ouiaId,
|
|
111
|
+
"data-ouia-component-type": ouiaType,
|
|
112
|
+
"data-ouia-safe": ouiaSafe,
|
|
113
|
+
ref: mergeRefs([localContainerRef, containerRef])
|
|
114
|
+
}, /*#__PURE__*/React.createElement(PortalProvider, null, /*#__PURE__*/React.createElement("svg", _extends({
|
|
115
|
+
width: width,
|
|
116
|
+
height: height,
|
|
117
|
+
tabIndex: tabIndex,
|
|
118
|
+
role: role,
|
|
119
|
+
"aria-labelledby": ariaLabelledBy,
|
|
120
|
+
"aria-describedby": ariaDescribedBy,
|
|
121
|
+
viewBox: viewBox,
|
|
122
|
+
preserveAspectRatio: preserveAspectRatio,
|
|
123
|
+
style: {
|
|
124
|
+
...dimensions,
|
|
125
|
+
pointerEvents: "all"
|
|
126
|
+
}
|
|
127
|
+
}, userProps, events), title ? /*#__PURE__*/React.createElement("title", {
|
|
128
|
+
id: titleId
|
|
129
|
+
}, title) : null, desc ? /*#__PURE__*/React.createElement("desc", {
|
|
130
|
+
id: descId
|
|
131
|
+
}, desc) : null, children), /*#__PURE__*/React.createElement("div", {
|
|
132
|
+
style: {
|
|
133
|
+
...dimensions,
|
|
111
134
|
zIndex: portalZIndex,
|
|
112
135
|
position: "absolute",
|
|
113
136
|
top: 0,
|
|
114
137
|
left: 0
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
138
|
+
}
|
|
139
|
+
}, /*#__PURE__*/React.createElement(PortalOutlet, {
|
|
140
|
+
as: portalComponent,
|
|
141
|
+
width: width,
|
|
142
|
+
height: height,
|
|
143
|
+
viewBox: viewBox,
|
|
144
|
+
preserveAspectRatio: preserveAspectRatio,
|
|
145
|
+
style: {
|
|
146
|
+
...dimensions,
|
|
120
147
|
overflow: "visible"
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
viewBox: svgProps.viewBox,
|
|
126
|
-
preserveAspectRatio: svgProps.preserveAspectRatio,
|
|
127
|
-
style: portalSvgStyle
|
|
128
|
-
};
|
|
129
|
-
return /*#__PURE__*/React.createElement(PortalContext.Provider, {
|
|
130
|
-
value: {
|
|
131
|
-
portalUpdate: this.portalUpdate,
|
|
132
|
-
portalRegister: this.portalRegister,
|
|
133
|
-
portalDeregister: this.portalDeregister
|
|
134
|
-
}
|
|
135
|
-
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
136
|
-
style: _defaults({}, style, divStyle),
|
|
137
|
-
className: className,
|
|
138
|
-
ref: this.saveContainerRef
|
|
139
|
-
}, this.getOUIAProps(props)), /*#__PURE__*/React.createElement("svg", _extends({}, svgProps, {
|
|
140
|
-
style: svgStyle
|
|
141
|
-
}), title ? /*#__PURE__*/React.createElement("title", {
|
|
142
|
-
id: this.getIdForElement("title")
|
|
143
|
-
}, title) : null, desc ? /*#__PURE__*/React.createElement("desc", {
|
|
144
|
-
id: this.getIdForElement("desc")
|
|
145
|
-
}, desc) : null, children), /*#__PURE__*/React.createElement("div", {
|
|
146
|
-
style: portalDivStyle
|
|
147
|
-
}, /*#__PURE__*/React.cloneElement(portalComponent, {
|
|
148
|
-
...portalProps,
|
|
149
|
-
ref: this.savePortalRef
|
|
150
|
-
}))));
|
|
151
|
-
}
|
|
152
|
-
render() {
|
|
153
|
-
const {
|
|
154
|
-
width,
|
|
155
|
-
height,
|
|
156
|
-
responsive,
|
|
157
|
-
events,
|
|
158
|
-
title,
|
|
159
|
-
desc,
|
|
160
|
-
tabIndex,
|
|
161
|
-
preserveAspectRatio,
|
|
162
|
-
role
|
|
163
|
-
} = this.props;
|
|
164
|
-
const style = responsive ? this.props.style : Helpers.omit(this.props.style, ["height", "width"]);
|
|
165
|
-
const userProps = UserProps.getSafeUserProps(this.props);
|
|
166
|
-
const svgProps = Object.assign({
|
|
167
|
-
width,
|
|
168
|
-
height,
|
|
169
|
-
tabIndex,
|
|
170
|
-
role,
|
|
171
|
-
"aria-labelledby": [title && this.getIdForElement("title"), this.props["aria-labelledby"]].filter(Boolean).join(" ") || undefined,
|
|
172
|
-
"aria-describedby": [desc && this.getIdForElement("desc"), this.props["aria-describedby"]].filter(Boolean).join(" ") || undefined,
|
|
173
|
-
viewBox: responsive ? `0 0 ${width} ${height}` : undefined,
|
|
174
|
-
preserveAspectRatio: responsive ? preserveAspectRatio : undefined,
|
|
175
|
-
...userProps
|
|
176
|
-
}, events);
|
|
177
|
-
return this.renderContainer(this.props, svgProps, style);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
148
|
+
}
|
|
149
|
+
}))));
|
|
150
|
+
};
|
|
151
|
+
VictoryContainer.role = "container";
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export interface PortalContextValue {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
addChild: (id: string, node: React.ReactElement) => void;
|
|
4
|
+
removeChild: (id: string) => void;
|
|
5
|
+
children: Map<string, React.ReactElement>;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export declare const PortalContext: React.Context<PortalContextValue | undefined>;
|
|
8
|
+
export declare const usePortalContext: () => PortalContextValue | undefined;
|
|
9
|
+
export interface PortalProviderProps {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const PortalProvider: ({ children }: PortalProviderProps) => JSX.Element;
|
|
12
13
|
//# sourceMappingURL=portal-context.d.ts.map
|
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export const PortalContext = /*#__PURE__*/React.createContext(undefined);
|
|
3
|
+
PortalContext.displayName = "PortalContext";
|
|
4
|
+
export const usePortalContext = () => {
|
|
5
|
+
const context = React.useContext(PortalContext);
|
|
6
|
+
return context;
|
|
7
|
+
};
|
|
8
|
+
export const PortalProvider = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
children
|
|
11
|
+
} = _ref;
|
|
12
|
+
const [portalChildren, setPortalChildren] = React.useState(new Map());
|
|
13
|
+
const addChild = React.useCallback((id, element) => {
|
|
14
|
+
setPortalChildren(prevChildren => {
|
|
15
|
+
const nextChildren = new Map(prevChildren);
|
|
16
|
+
nextChildren.set(id, element);
|
|
17
|
+
return nextChildren;
|
|
18
|
+
});
|
|
19
|
+
}, [setPortalChildren]);
|
|
20
|
+
const removeChild = React.useCallback(id => {
|
|
21
|
+
setPortalChildren(prevChildren => {
|
|
22
|
+
const nextChildren = new Map(prevChildren);
|
|
23
|
+
nextChildren.delete(id);
|
|
24
|
+
return nextChildren;
|
|
25
|
+
});
|
|
26
|
+
}, [setPortalChildren]);
|
|
27
|
+
const contextValue = React.useMemo(() => ({
|
|
28
|
+
addChild,
|
|
29
|
+
removeChild,
|
|
30
|
+
children: portalChildren
|
|
31
|
+
}), [addChild, removeChild, portalChildren]);
|
|
32
|
+
return /*#__PURE__*/React.createElement(PortalContext.Provider, {
|
|
33
|
+
value: contextValue
|
|
34
|
+
}, children);
|
|
35
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PortalOutletProps {
|
|
3
|
+
as: React.ReactElement;
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
viewBox?: string;
|
|
7
|
+
preserveAspectRatio?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
children?: (children: React.ReactElement[]) => React.ReactNode | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const PortalOutlet: ({ as: portalComponent, ...props }: PortalOutletProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
|
|
12
|
+
//# sourceMappingURL=portal-outlet.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { usePortalContext } from "./portal-context";
|
|
3
|
+
export const PortalOutlet = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
as: portalComponent,
|
|
6
|
+
...props
|
|
7
|
+
} = _ref;
|
|
8
|
+
const portalContext = usePortalContext();
|
|
9
|
+
if (!portalContext) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const children = Array.from(portalContext.children.values());
|
|
13
|
+
return /*#__PURE__*/React.cloneElement(portalComponent, props, children);
|
|
14
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { PortalContextValue } from "./portal-context";
|
|
3
2
|
export interface PortalProps {
|
|
4
3
|
className?: string;
|
|
5
4
|
height?: number;
|
|
@@ -7,15 +6,5 @@ export interface PortalProps {
|
|
|
7
6
|
viewBox?: string;
|
|
8
7
|
width?: number;
|
|
9
8
|
}
|
|
10
|
-
export declare
|
|
11
|
-
static displayName: string;
|
|
12
|
-
private readonly map;
|
|
13
|
-
private index;
|
|
14
|
-
constructor(props: PortalProps);
|
|
15
|
-
portalRegister: () => number;
|
|
16
|
-
portalUpdate: (key: number, element: React.ReactElement) => void;
|
|
17
|
-
portalDeregister: (key: number) => void;
|
|
18
|
-
getChildren(): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
|
19
|
-
render(): JSX.Element;
|
|
20
|
-
}
|
|
9
|
+
export declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<SVGSVGElement>>;
|
|
21
10
|
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -1,33 +1,7 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
1
2
|
import React from "react";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.index = 1;
|
|
8
|
-
}
|
|
9
|
-
portalRegister = () => {
|
|
10
|
-
return ++this.index;
|
|
11
|
-
};
|
|
12
|
-
portalUpdate = (key, element) => {
|
|
13
|
-
this.map[key] = element;
|
|
14
|
-
this.forceUpdate();
|
|
15
|
-
};
|
|
16
|
-
portalDeregister = key => {
|
|
17
|
-
delete this.map[key];
|
|
18
|
-
this.forceUpdate();
|
|
19
|
-
};
|
|
20
|
-
getChildren() {
|
|
21
|
-
return Object.keys(this.map).map(key => {
|
|
22
|
-
const el = this.map[key];
|
|
23
|
-
return el ? /*#__PURE__*/React.cloneElement(el, {
|
|
24
|
-
key
|
|
25
|
-
}) : el;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Overridden in victory-core-native
|
|
30
|
-
render() {
|
|
31
|
-
return /*#__PURE__*/React.createElement("svg", this.props, this.getChildren());
|
|
32
|
-
}
|
|
33
|
-
}
|
|
3
|
+
export const Portal = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
4
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
5
|
+
ref: ref
|
|
6
|
+
}, props));
|
|
7
|
+
});
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { PortalContext } from "./portal-context";
|
|
3
2
|
export interface VictoryPortalProps {
|
|
4
|
-
children
|
|
3
|
+
children: React.ReactElement;
|
|
5
4
|
groupComponent?: React.ReactElement;
|
|
6
5
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
static displayName: string;
|
|
12
|
-
static role: string;
|
|
13
|
-
static defaultProps: {
|
|
14
|
-
groupComponent: JSX.Element;
|
|
15
|
-
};
|
|
16
|
-
static contextType: React.Context<import("./portal-context").PortalContextValue>;
|
|
17
|
-
private checkedContext;
|
|
18
|
-
private portalKey;
|
|
19
|
-
renderInPlace: boolean;
|
|
20
|
-
element: React.ReactElement;
|
|
21
|
-
componentDidMount(): void;
|
|
22
|
-
componentDidUpdate(): void;
|
|
23
|
-
componentWillUnmount(): void;
|
|
24
|
-
renderPortal(child: React.ReactElement): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
|
|
25
|
-
render(): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
|
|
26
|
-
}
|
|
6
|
+
export declare const VictoryPortal: {
|
|
7
|
+
(initialProps: VictoryPortalProps): any;
|
|
8
|
+
role: string;
|
|
9
|
+
};
|
|
27
10
|
//# sourceMappingURL=victory-portal.d.ts.map
|