Skip to content

Commit

Permalink
Migrate victory-legend to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
KenanYusuf committed Jan 12, 2024
1 parent b6ceae1 commit 724f451
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 307 deletions.
19 changes: 14 additions & 5 deletions packages/victory-core/src/victory-util/add-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export interface EventsMixinClass<TProps> {
defaultAnimationWhitelist: string[],
): React.ReactElement;
getComponentProps(
component: React.ReactElement,
component: React.ReactNode,
type: string,
index: number,
index: string | number,
): TProps;
dataKeys: string[];
}
Expand Down Expand Up @@ -352,7 +352,11 @@ export function addEvents<
return props.events;
}

getComponentProps(component, type, index) {
getComponentProps(
component: React.ReactNode,
type: string,
index: string | number,
) {
const name = this.props.name || WrappedComponent.role;
const key = (this.dataKeys && this.dataKeys[index]) || index;
const id = `${name}-${type}-${key}`;
Expand All @@ -365,13 +369,18 @@ export function addEvents<
return undefined;
}

const currentProps =
component && typeof component === "object" && "props" in component
? component.props
: undefined;

if (this.hasEvents) {
const baseEvents = this.getEvents(this.props, type, key);
const componentProps = defaults(
{ index, key: id },
this.getEventState(key, type),
this.getSharedEventState(key, type),
component.props,
currentProps,
baseProps,
{ id },
);
Expand All @@ -385,7 +394,7 @@ export function addEvents<
return assign({}, componentProps, { events });
}

return defaults({ index, key: id }, component.props, baseProps, { id });
return defaults({ index, key: id }, currentProps, baseProps, { id });
}

renderContainer(component, children) {
Expand Down
3 changes: 3 additions & 0 deletions packages/victory-legend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"peerDependencies": {
"react": ">=16.6.0"
},
"devDependencies": {
"victory-legend": "*"
},
"publishConfig": {
"provenance": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const getColumnWidths = (props, data) => {
: gutter || 0;
const dataByColumn = groupBy(data, "column");
const columns = keys(dataByColumn);
return columns.reduce((memo, curr, index) => {
return columns.reduce<number[]>((memo, curr, index) => {
const lengths = dataByColumn[curr].map((d) => {
return d.textSize.width + d.size + d.symbolSpacer + gutterWidth;
});
Expand All @@ -102,7 +102,7 @@ const getRowHeights = (props, data) => {
? (gutter.top || 0) + (gutter.bottom || 0)
: gutter || 0;
const dataByRow = groupBy(data, "row");
return keys(dataByRow).reduce((memo, curr, index) => {
return keys(dataByRow).reduce<number[]>((memo, curr, index) => {
const rows = dataByRow[curr];
const lengths = rows.map((d) => {
return d.textSize.height + d.symbolSpacer + gutterHeight;
Expand Down
59 changes: 0 additions & 59 deletions packages/victory-legend/src/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/victory-legend/src/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/victory-legend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./victory-legend";
240 changes: 0 additions & 240 deletions packages/victory-legend/src/victory-legend.js

This file was deleted.

Loading

0 comments on commit 724f451

Please sign in to comment.