victory-core 36.6.0 → 36.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # victory-core
2
2
 
3
+ ## 36.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - - Removed Template Literal Types to increase TS compatibility (fixes [#2418](https://github.com/FormidableLabs/victory/issues/2418)) ([#2420](https://github.com/FormidableLabs/victory/pull/2420))
8
+ - Improved type for `VictoryLabelProps["textAnchor"]` (fixes [#2361](https://github.com/FormidableLabs/victory/issues/2361))
9
+ - Fixed exported types for `VictoryAxis`, `VictoryBoxPlot`, `VictoryErrorBar`, and `VictoryScatter` (fixes [#2411](https://github.com/FormidableLabs/victory/issues/2411))
10
+ - Migrate `victory-cursor-container` to TS (fixes [#2402](https://github.com/FormidableLabs/victory/issues/2402))
11
+ - Updated dependencies []:
12
+ - victory-vendor@36.6.1
13
+
3
14
  ## 36.6.0
4
15
 
5
16
  ### Minor Changes
@@ -10065,7 +10065,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
10065
10065
  var USER_PROPS_SAFELIST = {
10066
10066
  startsWith: ["data-", "aria-"],
10067
10067
  exactMatch: []
10068
- };
10068
+ }; // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
10069
+
10070
+ // `data-${string}` | `aria-${string}`;
10069
10071
 
10070
10072
  /**
10071
10073
  * doesPropStartWith: Function that takes a prop's key and runs it against all
@@ -12,7 +12,7 @@ export interface CallbackArgs {
12
12
  data?: Datum[];
13
13
  datum?: Datum;
14
14
  horizontal?: boolean;
15
- index: ID;
15
+ index?: ID;
16
16
  x?: number;
17
17
  y?: number;
18
18
  scale?: {
@@ -34,4 +34,5 @@ export declare type VictoryOrientationCallback = (args: CallbackArgs) => Orienta
34
34
  export declare type NumberOrCallback = number | VictoryNumberCallback;
35
35
  export declare type PaddingOrCallback = number | BlockProps | VictoryPaddingCallback;
36
36
  export declare type OrientationOrCallback = OrientationTypes | VictoryOrientationCallback;
37
+ export declare type ValueOrCallback<TValue> = TValue | ((args: CallbackArgs) => TValue);
37
38
  //# sourceMappingURL=callbacks.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { NumberOrCallback, StringOrCallback, StringOrNumberOrCallback } from "../types/callbacks";
2
+ import { NumberOrCallback, StringOrCallback, StringOrNumberOrCallback, ValueOrCallback } from "../types/callbacks";
3
3
  import { PaddingProps, VerticalAnchorType, VictoryLabelStyleObject } from "../victory-theme/victory-theme";
4
4
  export declare type TextAnchorType = "start" | "middle" | "end" | "inherit";
5
5
  export declare type OriginType = {
@@ -34,15 +34,11 @@ export interface VictoryLabelProps {
34
34
  tabIndex?: NumberOrCallback;
35
35
  text?: string[] | StringOrNumberOrCallback;
36
36
  textComponent?: React.ReactElement;
37
- textAnchor?: TextAnchorType | {
38
- (): TextAnchorType;
39
- };
37
+ textAnchor?: ValueOrCallback<TextAnchorType>;
40
38
  title?: string;
41
- transform?: string | object | (() => string | object);
39
+ transform?: ValueOrCallback<string | object>;
42
40
  tspanComponent?: React.ReactElement;
43
- verticalAnchor?: VerticalAnchorType | {
44
- (): VerticalAnchorType;
45
- };
41
+ verticalAnchor?: ValueOrCallback<VerticalAnchorType>;
46
42
  x?: number;
47
43
  y?: number;
48
44
  dx?: StringOrNumberOrCallback;
@@ -26,7 +26,7 @@ export interface EventsMixinClass<TProps> {
26
26
  getEventState: typeof Events.getEventState;
27
27
  renderData(props: TProps): any;
28
28
  renderContinuousData(props: TProps): any;
29
- animateComponent(props: TProps, defaultAnimationWhitelist: any): any;
29
+ animateComponent(props: TProps, defaultAnimationWhitelist: string[]): React.ReactElement;
30
30
  getComponentProps(component: React.ReactElement, type: string, index: number): TProps;
31
31
  dataKeys: string[];
32
32
  }
@@ -41,14 +41,30 @@ export interface EventMixinCalculatedValues {
41
41
  hasEvents: unknown;
42
42
  events: unknown;
43
43
  }
44
+ /**
45
+ * These are the common roles that we care about internally.
46
+ */
47
+ export declare type VictoryComponentCommonRole = "container" | "group" | "histogram" | "label" | "line" | "portal" | "stack" | "tooltip" | "voronoi";
48
+ /**
49
+ * A component can have any "role",
50
+ * but there are certain ones that we actually care about internally
51
+ */
52
+ export declare type VictoryComponentRole = VictoryComponentCommonRole | string;
53
+ /**
54
+ * Static component fields used by Victory for common behavior
55
+ */
56
+ export interface VictoryComponentConfiguration<TProps> {
57
+ getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
58
+ role?: VictoryComponentRole;
59
+ expectedComponents?: Array<keyof TProps | string>;
60
+ getChildren?: (props: TProps, childComponents?: Array<React.ReactNode>, calculatedProps?: TProps) => void;
61
+ animationWhitelist?: Array<keyof TProps | string>;
62
+ }
44
63
  /**
45
64
  * This represents the class itself, including static fields
46
65
  */
47
- export interface WrappedComponentClass<TProps> {
66
+ export interface WrappedComponentClass<TProps> extends VictoryComponentConfiguration<TProps> {
48
67
  new (props: TProps): React.Component<TProps>;
49
- getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
50
- role?: string;
51
- expectedComponents?: string[];
52
68
  }
53
69
  export declare function addEvents<TBase extends WrappedComponentClass<TProps>, TProps extends EventMixinCommonProps>(WrappedComponent: TBase, options?: MixinOptions): {
54
70
  new (props: TProps): {
@@ -76,7 +92,7 @@ export declare function addEvents<TBase extends WrappedComponentClass<TProps>, T
76
92
  getAllEvents(props: any): any;
77
93
  getComponentProps(component: any, type: any, index: any): any;
78
94
  renderContainer(component: any, children: any): React.DetailedReactHTMLElement<any, HTMLElement>;
79
- animateComponent(props: TProps, defaultAnimationWhitelist: string[]): JSX.Element;
95
+ animateComponent(props: TProps, defaultAnimationWhitelist: string[]): React.ReactElement;
80
96
  renderContinuousData(props: TProps): React.DetailedReactHTMLElement<any, HTMLElement>;
81
97
  renderData(props: any, shouldRenderDatum?: (datum: any) => boolean): React.DetailedReactHTMLElement<any, HTMLElement>;
82
98
  context: unknown;
@@ -104,6 +120,8 @@ export declare function addEvents<TBase extends WrappedComponentClass<TProps>, T
104
120
  };
105
121
  getBaseProps?(props: TProps): Record<string, object>;
106
122
  role?: string | undefined;
107
- expectedComponents?: string[] | undefined;
123
+ expectedComponents?: (string | keyof TProps)[] | undefined;
124
+ getChildren?: ((props: TProps, childComponents?: React.ReactNode[] | undefined, calculatedProps?: TProps | undefined) => void) | undefined;
125
+ animationWhitelist?: (string | keyof TProps)[] | undefined;
108
126
  } & TBase;
109
127
  //# sourceMappingURL=add-events.d.ts.map
@@ -6,7 +6,7 @@ export interface ComponentEvent {
6
6
  eventKey?: ComponentEventKey | ComponentEventKey[];
7
7
  eventHandlers: ComponentEventHandlers;
8
8
  }
9
- export declare type ComponentEventName = `on${Capitalize<string>}`;
9
+ export declare type ComponentEventName = string;
10
10
  export interface ComponentEventHandlers {
11
11
  [k: ComponentEventName]: ComponentEventHandler;
12
12
  }
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { CallbackArgs, ValueOrCallback } from "../types/callbacks";
2
3
  /**
3
4
  * creates an object with some keys excluded
4
5
  * replacement for lodash.omit for performance. does not mimic the entire lodash.omit api
@@ -23,7 +24,7 @@ export declare function getPadding(props: any, name?: string): {
23
24
  export declare function isTooltip(component: any): boolean;
24
25
  export declare function getDefaultStyles(props: any, role: any): any;
25
26
  export declare function getStyles(style: any, defaultStyles: any): any;
26
- export declare function evaluateProp(prop: any, props: any): any;
27
+ export declare function evaluateProp<TValue>(prop: ValueOrCallback<TValue>, props: CallbackArgs): TValue;
27
28
  export declare function evaluateStyle(style: any, props: any): any;
28
29
  export declare function degreesToRadians(degrees: any): any;
29
30
  export declare function radiansToDegrees(radians: any): any;
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- declare type SafeAttribute = `data-${string}` | `aria-${string}`;
2
+ declare type SafeAttribute = string;
3
3
  /**
4
4
  * getSafeUserProps - function that takes in a props object and removes any
5
5
  * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
@@ -27,7 +27,9 @@ import * as React from "react";
27
27
  var USER_PROPS_SAFELIST = {
28
28
  startsWith: ["data-", "aria-"],
29
29
  exactMatch: []
30
- };
30
+ }; // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
31
+
32
+ // `data-${string}` | `aria-${string}`;
31
33
 
32
34
  /**
33
35
  * doesPropStartWith: Function that takes a prop's key and runs it against all
@@ -31,7 +31,7 @@ export declare function getStringsFromChildren(props: any, childComponents: any)
31
31
  x: any[];
32
32
  y: any[];
33
33
  };
34
- export declare function getCategories(props: any, childComponents: any, allStrings: any): {
34
+ export declare function getCategories(props: any, childComponents: any, allStrings?: any): {
35
35
  x: any;
36
36
  y: any;
37
37
  };
@@ -12,7 +12,7 @@ export interface CallbackArgs {
12
12
  data?: Datum[];
13
13
  datum?: Datum;
14
14
  horizontal?: boolean;
15
- index: ID;
15
+ index?: ID;
16
16
  x?: number;
17
17
  y?: number;
18
18
  scale?: {
@@ -34,4 +34,5 @@ export declare type VictoryOrientationCallback = (args: CallbackArgs) => Orienta
34
34
  export declare type NumberOrCallback = number | VictoryNumberCallback;
35
35
  export declare type PaddingOrCallback = number | BlockProps | VictoryPaddingCallback;
36
36
  export declare type OrientationOrCallback = OrientationTypes | VictoryOrientationCallback;
37
+ export declare type ValueOrCallback<TValue> = TValue | ((args: CallbackArgs) => TValue);
37
38
  //# sourceMappingURL=callbacks.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { NumberOrCallback, StringOrCallback, StringOrNumberOrCallback } from "../types/callbacks";
2
+ import { NumberOrCallback, StringOrCallback, StringOrNumberOrCallback, ValueOrCallback } from "../types/callbacks";
3
3
  import { PaddingProps, VerticalAnchorType, VictoryLabelStyleObject } from "../victory-theme/victory-theme";
4
4
  export declare type TextAnchorType = "start" | "middle" | "end" | "inherit";
5
5
  export declare type OriginType = {
@@ -34,15 +34,11 @@ export interface VictoryLabelProps {
34
34
  tabIndex?: NumberOrCallback;
35
35
  text?: string[] | StringOrNumberOrCallback;
36
36
  textComponent?: React.ReactElement;
37
- textAnchor?: TextAnchorType | {
38
- (): TextAnchorType;
39
- };
37
+ textAnchor?: ValueOrCallback<TextAnchorType>;
40
38
  title?: string;
41
- transform?: string | object | (() => string | object);
39
+ transform?: ValueOrCallback<string | object>;
42
40
  tspanComponent?: React.ReactElement;
43
- verticalAnchor?: VerticalAnchorType | {
44
- (): VerticalAnchorType;
45
- };
41
+ verticalAnchor?: ValueOrCallback<VerticalAnchorType>;
46
42
  x?: number;
47
43
  y?: number;
48
44
  dx?: StringOrNumberOrCallback;
@@ -26,7 +26,7 @@ export interface EventsMixinClass<TProps> {
26
26
  getEventState: typeof Events.getEventState;
27
27
  renderData(props: TProps): any;
28
28
  renderContinuousData(props: TProps): any;
29
- animateComponent(props: TProps, defaultAnimationWhitelist: any): any;
29
+ animateComponent(props: TProps, defaultAnimationWhitelist: string[]): React.ReactElement;
30
30
  getComponentProps(component: React.ReactElement, type: string, index: number): TProps;
31
31
  dataKeys: string[];
32
32
  }
@@ -41,14 +41,30 @@ export interface EventMixinCalculatedValues {
41
41
  hasEvents: unknown;
42
42
  events: unknown;
43
43
  }
44
+ /**
45
+ * These are the common roles that we care about internally.
46
+ */
47
+ export declare type VictoryComponentCommonRole = "container" | "group" | "histogram" | "label" | "line" | "portal" | "stack" | "tooltip" | "voronoi";
48
+ /**
49
+ * A component can have any "role",
50
+ * but there are certain ones that we actually care about internally
51
+ */
52
+ export declare type VictoryComponentRole = VictoryComponentCommonRole | string;
53
+ /**
54
+ * Static component fields used by Victory for common behavior
55
+ */
56
+ export interface VictoryComponentConfiguration<TProps> {
57
+ getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
58
+ role?: VictoryComponentRole;
59
+ expectedComponents?: Array<keyof TProps | string>;
60
+ getChildren?: (props: TProps, childComponents?: Array<React.ReactNode>, calculatedProps?: TProps) => void;
61
+ animationWhitelist?: Array<keyof TProps | string>;
62
+ }
44
63
  /**
45
64
  * This represents the class itself, including static fields
46
65
  */
47
- export interface WrappedComponentClass<TProps> {
66
+ export interface WrappedComponentClass<TProps> extends VictoryComponentConfiguration<TProps> {
48
67
  new (props: TProps): React.Component<TProps>;
49
- getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
50
- role?: string;
51
- expectedComponents?: string[];
52
68
  }
53
69
  export declare function addEvents<TBase extends WrappedComponentClass<TProps>, TProps extends EventMixinCommonProps>(WrappedComponent: TBase, options?: MixinOptions): {
54
70
  new (props: TProps): {
@@ -76,7 +92,7 @@ export declare function addEvents<TBase extends WrappedComponentClass<TProps>, T
76
92
  getAllEvents(props: any): any;
77
93
  getComponentProps(component: any, type: any, index: any): any;
78
94
  renderContainer(component: any, children: any): React.DetailedReactHTMLElement<any, HTMLElement>;
79
- animateComponent(props: TProps, defaultAnimationWhitelist: string[]): JSX.Element;
95
+ animateComponent(props: TProps, defaultAnimationWhitelist: string[]): React.ReactElement;
80
96
  renderContinuousData(props: TProps): React.DetailedReactHTMLElement<any, HTMLElement>;
81
97
  renderData(props: any, shouldRenderDatum?: (datum: any) => boolean): React.DetailedReactHTMLElement<any, HTMLElement>;
82
98
  context: unknown;
@@ -104,6 +120,8 @@ export declare function addEvents<TBase extends WrappedComponentClass<TProps>, T
104
120
  };
105
121
  getBaseProps?(props: TProps): Record<string, object>;
106
122
  role?: string | undefined;
107
- expectedComponents?: string[] | undefined;
123
+ expectedComponents?: (string | keyof TProps)[] | undefined;
124
+ getChildren?: ((props: TProps, childComponents?: React.ReactNode[] | undefined, calculatedProps?: TProps | undefined) => void) | undefined;
125
+ animationWhitelist?: (string | keyof TProps)[] | undefined;
108
126
  } & TBase;
109
127
  //# sourceMappingURL=add-events.d.ts.map
@@ -6,7 +6,7 @@ export interface ComponentEvent {
6
6
  eventKey?: ComponentEventKey | ComponentEventKey[];
7
7
  eventHandlers: ComponentEventHandlers;
8
8
  }
9
- export declare type ComponentEventName = `on${Capitalize<string>}`;
9
+ export declare type ComponentEventName = string;
10
10
  export interface ComponentEventHandlers {
11
11
  [k: ComponentEventName]: ComponentEventHandler;
12
12
  }
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { CallbackArgs, ValueOrCallback } from "../types/callbacks";
2
3
  /**
3
4
  * creates an object with some keys excluded
4
5
  * replacement for lodash.omit for performance. does not mimic the entire lodash.omit api
@@ -23,7 +24,7 @@ export declare function getPadding(props: any, name?: string): {
23
24
  export declare function isTooltip(component: any): boolean;
24
25
  export declare function getDefaultStyles(props: any, role: any): any;
25
26
  export declare function getStyles(style: any, defaultStyles: any): any;
26
- export declare function evaluateProp(prop: any, props: any): any;
27
+ export declare function evaluateProp<TValue>(prop: ValueOrCallback<TValue>, props: CallbackArgs): TValue;
27
28
  export declare function evaluateStyle(style: any, props: any): any;
28
29
  export declare function degreesToRadians(degrees: any): any;
29
30
  export declare function radiansToDegrees(radians: any): any;
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- declare type SafeAttribute = `data-${string}` | `aria-${string}`;
2
+ declare type SafeAttribute = string;
3
3
  /**
4
4
  * getSafeUserProps - function that takes in a props object and removes any
5
5
  * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
@@ -38,7 +38,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
38
38
  var USER_PROPS_SAFELIST = {
39
39
  startsWith: ["data-", "aria-"],
40
40
  exactMatch: []
41
- };
41
+ }; // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
42
+
43
+ // `data-${string}` | `aria-${string}`;
42
44
 
43
45
  /**
44
46
  * doesPropStartWith: Function that takes a prop's key and runs it against all
@@ -31,7 +31,7 @@ export declare function getStringsFromChildren(props: any, childComponents: any)
31
31
  x: any[];
32
32
  y: any[];
33
33
  };
34
- export declare function getCategories(props: any, childComponents: any, allStrings: any): {
34
+ export declare function getCategories(props: any, childComponents: any, allStrings?: any): {
35
35
  x: any;
36
36
  y: any;
37
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-core",
3
- "version": "36.6.0",
3
+ "version": "36.6.1",
4
4
  "description": "Victory Core",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -23,7 +23,7 @@
23
23
  "lodash": "^4.17.21",
24
24
  "prop-types": "^15.8.1",
25
25
  "react-fast-compare": "^3.2.0",
26
- "victory-vendor": "^36.6.0"
26
+ "victory-vendor": "^36.6.1"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=16.6.0"
@@ -130,6 +130,14 @@
130
130
  "pnpm-lock.yaml"
131
131
  ]
132
132
  },
133
+ "check": {
134
+ "dependencies": [
135
+ "types:check",
136
+ "jest",
137
+ "format",
138
+ "lint"
139
+ ]
140
+ },
133
141
  "types:check": {
134
142
  "command": "nps types:pkg:check",
135
143
  "files": [
@@ -184,6 +192,19 @@
184
192
  "pnpm-lock.yaml"
185
193
  ]
186
194
  },
195
+ "format:fix": {
196
+ "command": "pnpm run format || nps format:pkg:fix",
197
+ "files": [
198
+ "src/**",
199
+ "*.json",
200
+ "../../.prettierignore",
201
+ "../../.prettierrc.json"
202
+ ],
203
+ "output": [],
204
+ "packageLocks": [
205
+ "pnpm-lock.yaml"
206
+ ]
207
+ },
187
208
  "lint": {
188
209
  "command": "nps lint:pkg",
189
210
  "files": [
@@ -204,19 +225,6 @@
204
225
  "pnpm-lock.yaml"
205
226
  ]
206
227
  },
207
- "format:fix": {
208
- "command": "pnpm run format || nps format:pkg:fix",
209
- "files": [
210
- "src/**",
211
- "*.json",
212
- "../../.prettierignore",
213
- "../../.prettierrc.json"
214
- ],
215
- "output": [],
216
- "packageLocks": [
217
- "pnpm-lock.yaml"
218
- ]
219
- },
220
228
  "lint:fix": {
221
229
  "command": "pnpm run lint || nps lint:pkg:fix",
222
230
  "files": [
@@ -269,6 +277,7 @@
269
277
  "build:dist": "wireit",
270
278
  "build:dist:dev": "wireit",
271
279
  "build:dist:min": "wireit",
280
+ "check": "wireit",
272
281
  "types:check": "wireit",
273
282
  "types:create": "wireit",
274
283
  "format": "wireit",
@@ -13,7 +13,7 @@ export interface CallbackArgs {
13
13
  data?: Datum[];
14
14
  datum?: Datum;
15
15
  horizontal?: boolean;
16
- index: ID;
16
+ index?: ID;
17
17
  x?: number;
18
18
  y?: number;
19
19
  scale?: {
@@ -51,3 +51,5 @@ export type PaddingOrCallback = number | BlockProps | VictoryPaddingCallback;
51
51
  export type OrientationOrCallback =
52
52
  | OrientationTypes
53
53
  | VictoryOrientationCallback;
54
+
55
+ export type ValueOrCallback<TValue> = TValue | ((args: CallbackArgs) => TValue);
@@ -17,6 +17,7 @@ import {
17
17
  NumberOrCallback,
18
18
  StringOrCallback,
19
19
  StringOrNumberOrCallback,
20
+ ValueOrCallback,
20
21
  } from "../types/callbacks";
21
22
  import {
22
23
  PaddingProps,
@@ -55,11 +56,11 @@ export interface VictoryLabelProps {
55
56
  tabIndex?: NumberOrCallback;
56
57
  text?: string[] | StringOrNumberOrCallback;
57
58
  textComponent?: React.ReactElement;
58
- textAnchor?: TextAnchorType | { (): TextAnchorType };
59
+ textAnchor?: ValueOrCallback<TextAnchorType>;
59
60
  title?: string;
60
- transform?: string | object | (() => string | object);
61
+ transform?: ValueOrCallback<string | object>;
61
62
  tspanComponent?: React.ReactElement;
62
- verticalAnchor?: VerticalAnchorType | { (): VerticalAnchorType };
63
+ verticalAnchor?: ValueOrCallback<VerticalAnchorType>;
63
64
  x?: number;
64
65
  y?: number;
65
66
  dx?: StringOrNumberOrCallback;
@@ -63,7 +63,10 @@ export interface EventsMixinClass<TProps> {
63
63
  getEventState: typeof Events.getEventState;
64
64
  renderData(props: TProps);
65
65
  renderContinuousData(props: TProps);
66
- animateComponent(props: TProps, defaultAnimationWhitelist);
66
+ animateComponent(
67
+ props: TProps,
68
+ defaultAnimationWhitelist: string[],
69
+ ): React.ReactElement;
67
70
  getComponentProps(
68
71
  component: React.ReactElement,
69
72
  type: string,
@@ -84,14 +87,47 @@ export interface EventMixinCalculatedValues {
84
87
  events: unknown;
85
88
  }
86
89
 
90
+ /**
91
+ * These are the common roles that we care about internally.
92
+ */
93
+ export type VictoryComponentCommonRole =
94
+ | "container"
95
+ | "group"
96
+ | "histogram"
97
+ | "label"
98
+ | "line"
99
+ | "portal"
100
+ | "stack"
101
+ | "tooltip"
102
+ | "voronoi";
103
+
104
+ /**
105
+ * A component can have any "role",
106
+ * but there are certain ones that we actually care about internally
107
+ */
108
+ export type VictoryComponentRole = VictoryComponentCommonRole | string;
109
+
110
+ /**
111
+ * Static component fields used by Victory for common behavior
112
+ */
113
+ export interface VictoryComponentConfiguration<TProps> {
114
+ getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
115
+ role?: VictoryComponentRole;
116
+ expectedComponents?: Array<keyof TProps | string>;
117
+ getChildren?: (
118
+ props: TProps,
119
+ childComponents?: Array<React.ReactNode>,
120
+ calculatedProps?: TProps,
121
+ ) => void;
122
+ animationWhitelist?: Array<keyof TProps | string>;
123
+ }
124
+
87
125
  /**
88
126
  * This represents the class itself, including static fields
89
127
  */
90
- export interface WrappedComponentClass<TProps> {
128
+ export interface WrappedComponentClass<TProps>
129
+ extends VictoryComponentConfiguration<TProps> {
91
130
  new (props: TProps): React.Component<TProps>;
92
- getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
93
- role?: string;
94
- expectedComponents?: string[];
95
131
  }
96
132
 
97
133
  export function addEvents<
@@ -366,7 +402,10 @@ export function addEvents<
366
402
  return React.cloneElement(component, parentProps, children);
367
403
  }
368
404
 
369
- animateComponent(props: TProps, defaultAnimationWhitelist: string[]) {
405
+ animateComponent(
406
+ props: TProps,
407
+ defaultAnimationWhitelist: string[],
408
+ ): React.ReactElement {
370
409
  const animationWhitelist =
371
410
  (typeof props.animate === "object" &&
372
411
  props.animate?.animationWhitelist) ||
@@ -20,7 +20,8 @@ export interface ComponentEvent {
20
20
  eventKey?: ComponentEventKey | ComponentEventKey[];
21
21
  eventHandlers: ComponentEventHandlers;
22
22
  }
23
- export type ComponentEventName = `on${Capitalize<string>}`;
23
+ // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
24
+ export type ComponentEventName = string; // `on${Capitalize<string>}`;
24
25
  export interface ComponentEventHandlers {
25
26
  [k: ComponentEventName]: ComponentEventHandler;
26
27
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-use-before-define */
2
2
  import React from "react";
3
3
  import { defaults, isFunction, property, pick, assign, keys } from "lodash";
4
+ import { CallbackArgs, ValueOrCallback } from "../types/callbacks";
4
5
 
5
6
  // Private Functions
6
7
 
@@ -126,7 +127,10 @@ export function getStyles(style, defaultStyles) {
126
127
  };
127
128
  }
128
129
 
129
- export function evaluateProp(prop, props) {
130
+ export function evaluateProp<TValue>(
131
+ prop: ValueOrCallback<TValue>,
132
+ props: CallbackArgs,
133
+ ): TValue {
130
134
  return isFunction(prop) ? prop(props) : prop;
131
135
  }
132
136
 
@@ -11,7 +11,8 @@ const USER_PROPS_SAFELIST = {
11
11
  exactMatch: [] as string[],
12
12
  };
13
13
 
14
- type SafeAttribute = `data-${string}` | `aria-${string}`;
14
+ // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
15
+ type SafeAttribute = string; // `data-${string}` | `aria-${string}`;
15
16
 
16
17
  /**
17
18
  * doesPropStartWith: Function that takes a prop's key and runs it against all
@@ -449,7 +449,7 @@ export function getStringsFromChildren(props, childComponents) {
449
449
  };
450
450
  }
451
451
 
452
- export function getCategories(props, childComponents, allStrings) {
452
+ export function getCategories(props, childComponents, allStrings?) {
453
453
  const xPropCategories =
454
454
  props.categories && !Array.isArray(props.categories)
455
455
  ? props.categories.x