From dd9334f50a7c1f636e3ba34c30d34835f3987d0d Mon Sep 17 00:00:00 2001 From: moklick Date: Fri, 26 Mar 2021 22:10:49 +0100 Subject: [PATCH] feat(controls): extendable controls via control button comp closes #1030 --- src/additional-components/Controls/index.tsx | 35 ++++++++++++-------- src/additional-components/index.ts | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/additional-components/Controls/index.tsx b/src/additional-components/Controls/index.tsx index bae66f1f..e56d301a 100644 --- a/src/additional-components/Controls/index.tsx +++ b/src/additional-components/Controls/index.tsx @@ -1,4 +1,4 @@ -import React, { memo, useCallback, HTMLAttributes } from 'react'; +import React, { memo, useCallback, HTMLAttributes, FC } from 'react'; import cc from 'classcat'; import { useStoreState, useStoreActions } from '../../store/hooks'; @@ -23,7 +23,15 @@ export interface ControlProps extends HTMLAttributes { onInteractiveChange?: (interactiveStatus: boolean) => void; } -const Controls = ({ +export interface ControlButtonProps extends HTMLAttributes {} + +export const ControlButton: FC = ({ children, className, onClick }) => ( +
+ {children} +
+); + +const Controls: FC = ({ style, showZoom = true, showFitView = true, @@ -34,7 +42,8 @@ const Controls = ({ onFitView, onInteractiveChange, className, -}: ControlProps) => { + children, +}) => { const setInteractive = useStoreActions((actions) => actions.setInteractive); const { zoomIn, zoomOut, fitView } = useZoomPanHelper(); @@ -65,27 +74,25 @@ const Controls = ({
{showZoom && ( <> -
+ -
-
+ + -
+ )} {showFitView && ( -
+ -
+ )} {showInteractive && ( -
+ {isInteractive ? : } -
+ )} + {children}
); }; diff --git a/src/additional-components/index.ts b/src/additional-components/index.ts index 41c7020c..3c96dfb6 100644 --- a/src/additional-components/index.ts +++ b/src/additional-components/index.ts @@ -2,6 +2,6 @@ // but the user can add them as children of a React Flow component export { default as MiniMap } from './MiniMap'; -export { default as Controls } from './Controls'; +export { default as Controls, ControlButton } from './Controls'; export { default as Background } from './Background'; export { default as ReactFlowProvider } from './ReactFlowProvider';