Skip to content

Commit

Permalink
feat: 新增点击 NodeLegend 的回调
Browse files Browse the repository at this point in the history
  • Loading branch information
yunyi authored and yunyi committed Jun 30, 2022
1 parent c03ed7f commit 66f2ae6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/graphin/src/components/Legend/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { LegendChildrenProps, OptionType } from './typing';
const LegendNode: React.FunctionComponent<LegendChildrenProps> = props => {
const { graph, theme } = React.useContext(GraphinContext);

const { options: defaultOptions, dataMap } = props;
const { options: defaultOptions, dataMap, onChange } = props;

const { mode } = theme;

Expand Down Expand Up @@ -54,6 +54,8 @@ const LegendNode: React.FunctionComponent<LegendChildrenProps> = props => {
graph.setItemState(edge, 'inactive', !checkedValue.checked);
})
});

onChange(checkedValue, result);
};

return (
Expand Down
8 changes: 6 additions & 2 deletions packages/graphin/src/components/Legend/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LegendChildrenProps } from '@antv/graphin';
import type { LegendChildrenProps, OptionType } from '@antv/graphin';
import Graphin, { Components, Utils } from '@antv/graphin';
import iconsLoader from '@antv/graphin-icons';
import * as React from 'react';
Expand Down Expand Up @@ -43,12 +43,16 @@ data.nodes.forEach((node, index) => {
});

const Demo = () => {
const onChange = (checkedValue: OptionType, options: OptionType[]) => {
console.log(checkedValue, options);
}

return (
<Graphin data={data}>
<Legend bindType="node" sortKey="data.type">
{(renderProps: LegendChildrenProps) => {
console.log('renderProps', renderProps);
return <Legend.Node {...renderProps} />;
return <Legend.Node {...renderProps} onChange={onChange}/>;
}}
</Legend>
</Graphin>
Expand Down
1 change: 1 addition & 0 deletions packages/graphin/src/components/Legend/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export interface LegendChildrenProps {
sortKey: string;
dataMap: Map<string | number, any>;
options: OptionType[];
onChange: (checkedValue: OptionType, result: OptionType[]) => void;
}

0 comments on commit 66f2ae6

Please sign in to comment.