Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate victory-legend to TypeScript #2712

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used a more inclusive type for the component, as it can also be a string or string[]

type: string,
index: number,
index: string | number,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a number, or a key of an object (string)

): 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