Skip to content

Commit

Permalink
feat(editor): deleteKey as prop
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 3, 2019
1 parent a4887ea commit 5ffe4f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/GlobalKeyHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useStoreState, useStoreActions } from 'easy-peasy';
import useKeyPress from '../hooks/useKeyPress';
import { isEdge, getConnectedEdges } from '../graph-utils';

export default memo((props) => {
export default memo(({ deleteKey, onElementsRemove }) => {
const state = useStoreState(s => ({ selectedElements: s.selectedElements, edges: s.edges }))
const setNodesSelection = useStoreActions(a => a.setNodesSelection);
const removePressed = useKeyPress('Backspace');
const removePressed = useKeyPress(deleteKey);

useEffect(() => {
if (removePressed && state.selectedElements.length) {
Expand All @@ -19,7 +19,7 @@ export default memo((props) => {
elementsToRemove = [...state.selectedElements, ...connectedEdges];
}

props.onElementsRemove(elementsToRemove);
onElementsRemove(elementsToRemove);
setNodesSelection({ isActive: false });
}
}, [removePressed])
Expand Down
7 changes: 5 additions & 2 deletions src/ReactGraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import '../style.css';
const ReactGraph = ({
style, onElementClick, elements, children,
nodeTypes, edgeTypes, onLoad, onMove, onElementsRemove,
onConnect, onNodeDragStop, connectionLineType, connectionLineStyle
onConnect, onNodeDragStop, connectionLineType, connectionLineStyle,
deleteKey
}) => {
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
Expand All @@ -47,6 +48,7 @@ const ReactGraph = ({
/>
<GlobalKeyHandler
onElementsRemove={onElementsRemove}
deleteKey={deleteKey}
/>
{children}
</StoreProvider>
Expand Down Expand Up @@ -74,7 +76,8 @@ ReactGraph.defaultProps = {
step: StepEdge
},
connectionLineType: 'bezier',
connectionLineStyle: {}
connectionLineStyle: {},
deleteKey: 'Backspace'
};

export default ReactGraph;

0 comments on commit 5ffe4f9

Please sign in to comment.