From 6ea206e3be2f4c8024cce73e2c15da563cb0bb30 Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 11 May 2020 19:08:07 +0200 Subject: [PATCH] feat(controls): add showZoom, showFitView, showInteractive options #211 --- README.md | 5 ++- src/plugins/Controls/index.tsx | 57 ++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 094af382..cf3a2550 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ const GraphWithMiniMap = () => ( ### Controls -The control panel contains a zoom-in, zoom-out and a fit-view button. You can use it by passing it as a children to your React Flow component: +The control panel contains a zoom-in, zoom-out, fit-view and a lock/unlock button. You can use it by passing it as a children to the React Flow component: ```javascript import ReactFlow, { Controls } from 'react-flow-renderer'; @@ -272,6 +272,9 @@ const GraphWithControls = () => ( - `style`: css properties - `className`: class name +- `showZoom`: boolean - default: true +- `showFitView`: boolean - default: true +- `showInteractive`: boolean - default: true ## Examples diff --git a/src/plugins/Controls/index.tsx b/src/plugins/Controls/index.tsx index 79519e43..12e81c38 100644 --- a/src/plugins/Controls/index.tsx +++ b/src/plugins/Controls/index.tsx @@ -17,12 +17,16 @@ const baseStyle: CSSProperties = { left: 10, }; -interface ControlProps extends React.HTMLAttributes {} +interface ControlProps extends React.HTMLAttributes { + showZoom?: boolean; + showFitView?: boolean; + showInteractive?: boolean; +} -export default ({ style, className }: ControlProps) => { +export default ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => { const mapClasses: string = classnames('react-flow__controls', className); - const setInteractive = useStoreActions(actions => actions.setInteractive); + const setInteractive = useStoreActions((actions) => actions.setInteractive); const { isInteractive } = useStoreState(({ isInteractive }) => ({ isInteractive })); return ( @@ -33,30 +37,29 @@ export default ({ style, className }: ControlProps) => { ...style, }} > -
- -
-
- -
-
fitView()} - > - -
-
setInteractive(!isInteractive)} - > - { isInteractive ? : } -
+ {showZoom && ( + <> +
+ +
+
+ +
+ + )} + {showFitView && ( +
fitView()}> + +
+ )} + {showInteractive && ( +
setInteractive(!isInteractive)} + > + {isInteractive ? : } +
+ )} ); };