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.
Files changed (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/victory-core.js +395 -358
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/index.d.ts +2 -1
  5. package/es/index.js +2 -1
  6. package/es/types/prop-types.d.ts +1 -0
  7. package/es/victory-container/victory-container.d.ts +29 -35
  8. package/es/victory-container/victory-container.js +134 -162
  9. package/es/victory-portal/portal-context.d.ts +9 -8
  10. package/es/victory-portal/portal-context.js +34 -6
  11. package/es/victory-portal/portal-outlet.d.ts +12 -0
  12. package/es/victory-portal/portal-outlet.js +14 -0
  13. package/es/victory-portal/portal.d.ts +1 -12
  14. package/es/victory-portal/portal.js +6 -32
  15. package/es/victory-portal/victory-portal.d.ts +5 -22
  16. package/es/victory-portal/victory-portal.js +37 -52
  17. package/es/victory-util/index.d.ts +1 -0
  18. package/es/victory-util/index.js +1 -0
  19. package/es/victory-util/merge-refs.d.ts +13 -0
  20. package/es/victory-util/merge-refs.js +23 -0
  21. package/lib/index.d.ts +2 -1
  22. package/lib/index.js +16 -4
  23. package/lib/types/prop-types.d.ts +1 -0
  24. package/lib/victory-container/victory-container.d.ts +29 -35
  25. package/lib/victory-container/victory-container.js +136 -163
  26. package/lib/victory-portal/portal-context.d.ts +9 -8
  27. package/lib/victory-portal/portal-context.js +37 -7
  28. package/lib/victory-portal/portal-outlet.d.ts +12 -0
  29. package/lib/victory-portal/portal-outlet.js +22 -0
  30. package/lib/victory-portal/portal.d.ts +1 -12
  31. package/lib/victory-portal/portal.js +6 -33
  32. package/lib/victory-portal/victory-portal.d.ts +5 -22
  33. package/lib/victory-portal/victory-portal.js +37 -52
  34. package/lib/victory-util/index.d.ts +1 -0
  35. package/lib/victory-util/index.js +12 -0
  36. package/lib/victory-util/merge-refs.d.ts +13 -0
  37. package/lib/victory-util/merge-refs.js +31 -0
  38. package/package.json +2 -2
  39. package/src/index.ts +2 -1
  40. package/src/types/prop-types.ts +7 -0
  41. package/src/victory-container/victory-container.tsx +167 -195
  42. package/src/victory-portal/portal-context.tsx +63 -0
  43. package/src/victory-portal/portal-outlet.tsx +26 -0
  44. package/src/victory-portal/portal.tsx +5 -42
  45. package/src/victory-portal/victory-portal.tsx +44 -73
  46. package/src/victory-util/index.ts +1 -0
  47. package/src/victory-util/merge-refs.ts +26 -0
  48. 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";
@@ -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 class VictoryContainer<TProps extends VictoryContainerProps> extends React.Component<TProps> {
37
- static displayName: string;
38
- static role: string;
39
- static defaultProps: {
40
- className: string;
41
- portalComponent: JSX.Element;
42
- portalZIndex: number;
43
- responsive: boolean;
44
- role: string;
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
- static contextType: React.Context<{
47
- transitionTimer: import("..").Timer;
48
- animationTimer: import("..").Timer;
49
- }>;
50
- private containerId;
51
- private portalRef;
52
- private containerRef;
53
- private shouldHandleWheel;
54
- constructor(props: TProps);
55
- savePortalRef: (portal: any) => any;
56
- portalUpdate: (key: any, el: any) => void;
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
- export class VictoryContainer extends React.Component {
12
- static displayName = "VictoryContainer";
13
- static role = "container";
14
- static defaultProps = {
15
- className: "VictoryContainer",
16
- portalComponent: /*#__PURE__*/React.createElement(Portal, null),
17
- portalZIndex: 99,
18
- responsive: true,
19
- role: "img"
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
- static contextType = TimerContext;
21
+ const {
22
+ title,
23
+ desc,
24
+ width,
25
+ height,
26
+ responsive
27
+ } = props;
28
+ const localContainerRef = useRef(null);
22
29
 
23
- // @ts-expect-error Ref will be initialized on mount
24
-
25
- // @ts-expect-error Ref will be initialized on mount
26
-
27
- constructor(props) {
28
- super(props);
29
- this.containerId = !_isObject(props) || props.containerId === undefined ? _uniqueId("victory-container-") : props.containerId;
30
- this.shouldHandleWheel = !!(props && props.events && props.events.onWheel);
31
- }
32
- savePortalRef = portal => {
33
- this.portalRef = portal;
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
- portalUpdate = (key, el) => this.portalRef.portalUpdate(key, el);
37
- portalRegister = () => this.portalRef.portalRegister();
38
- portalDeregister = key => this.portalRef.portalDeregister(key);
39
- saveContainerRef = container => {
40
- if (Helpers.isFunction(this.props.containerRef)) {
41
- this.props.containerRef(container);
42
- }
43
- this.containerRef = container;
44
- return container;
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
- handleWheel = e => e.preventDefault();
47
- componentDidMount() {
48
- if (this.shouldHandleWheel && this.containerRef) {
49
- this.containerRef.addEventListener("wheel", this.handleWheel);
50
- }
51
- }
52
- componentWillUnmount() {
53
- if (this.shouldHandleWheel && this.containerRef) {
54
- this.containerRef.removeEventListener("wheel", this.handleWheel);
55
- }
56
- }
57
- getIdForElement(elementName) {
58
- return `${this.containerId}-${elementName}`;
59
- }
60
-
61
- // overridden in custom containers
62
- getChildren(props) {
63
- return props.children;
64
- }
65
-
66
- // Get props defined by the Open UI Automation (OUIA) 1.0-RC spec
67
- // See https://ouia.readthedocs.io/en/latest/README.html#ouia-component
68
- getOUIAProps(props) {
69
- const {
70
- ouiaId,
71
- ouiaSafe,
72
- ouiaType
73
- } = props;
74
- return {
75
- ...(ouiaId && {
76
- "data-ouia-component-id": ouiaId
77
- }),
78
- ...(ouiaType && {
79
- "data-ouia-component-type": ouiaType
80
- }),
81
- ...(ouiaSafe !== undefined && {
82
- "data-ouia-safe": ouiaSafe
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
- renderContainer(props, svgProps, style) {
87
- const {
88
- title,
89
- desc,
90
- portalComponent,
91
- className,
92
- width,
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
- }, dimensions);
110
- const portalDivStyle = Object.assign({
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
- }, dimensions);
116
- const svgStyle = Object.assign({
117
- pointerEvents: "all"
118
- }, dimensions);
119
- const portalSvgStyle = Object.assign({
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
- }, dimensions);
122
- const portalProps = {
123
- width,
124
- height,
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
- portalRegister(): number;
4
- portalUpdate(key: number, element: React.ReactElement): void;
5
- portalDeregister(key: number): void;
3
+ addChild: (id: string, node: React.ReactElement) => void;
4
+ removeChild: (id: string) => void;
5
+ children: Map<string, React.ReactElement>;
6
6
  }
7
- /**
8
- * The React context object consumers may use to access the context of the
9
- * portal.
10
- */
11
- export declare const PortalContext: React.Context<PortalContextValue>;
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
- * The React context object consumers may use to access the context of the
4
- * portal.
5
- */
6
- export const PortalContext = /*#__PURE__*/React.createContext({});
7
- PortalContext.displayName = "PortalContext";
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 class Portal extends React.Component<PortalProps> implements PortalContextValue {
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 class Portal extends React.Component {
3
- static displayName = "Portal";
4
- constructor(props) {
5
- super(props);
6
- this.map = {};
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?: React.ReactElement;
3
+ children: React.ReactElement;
5
4
  groupComponent?: React.ReactElement;
6
5
  }
7
- export interface VictoryPortal {
8
- context: React.ContextType<typeof PortalContext>;
9
- }
10
- export declare class VictoryPortal extends React.Component<VictoryPortalProps> {
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