From fb543d290efb593ee87dbf82fd92eb5a8e091818 Mon Sep 17 00:00:00 2001 From: moklick Date: Sat, 16 May 2020 01:10:20 +0200 Subject: [PATCH] refactor(plugins): create MiniMapNode file for component, cleanup --- src/plugins/Controls/index.tsx | 9 ++++--- src/plugins/MiniMap/MiniMapNode.tsx | 35 ++++++++++++++++++++++++ src/plugins/MiniMap/index.tsx | 42 +++++++---------------------- 3 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 src/plugins/MiniMap/MiniMapNode.tsx diff --git a/src/plugins/Controls/index.tsx b/src/plugins/Controls/index.tsx index 12e81c38..a26da2c0 100644 --- a/src/plugins/Controls/index.tsx +++ b/src/plugins/Controls/index.tsx @@ -23,11 +23,10 @@ interface ControlProps extends React.HTMLAttributes { showInteractive?: boolean; } -export default ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => { - const mapClasses: string = classnames('react-flow__controls', className); - +const Controls = ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => { const setInteractive = useStoreActions((actions) => actions.setInteractive); const { isInteractive } = useStoreState(({ isInteractive }) => ({ isInteractive })); + const mapClasses: string = classnames('react-flow__controls', className); return (
); }; + +Controls.displayName = 'Controls'; + +export default Controls; diff --git a/src/plugins/MiniMap/MiniMapNode.tsx b/src/plugins/MiniMap/MiniMapNode.tsx new file mode 100644 index 00000000..02ff5e2f --- /dev/null +++ b/src/plugins/MiniMap/MiniMapNode.tsx @@ -0,0 +1,35 @@ +import React from 'react'; + +import { Node } from '../../types'; + +interface MiniMapNodeProps { + node: Node; + color: string; + borderRadius: number; +} + +const MiniMapNode = ({ node, color, borderRadius }: MiniMapNodeProps) => { + const { + position: { x, y }, + width, + height, + } = node.__rg; + const { background, backgroundColor } = node.style || {}; + const fill = (background || backgroundColor || color) as string; + return ( + + ); +}; + +MiniMapNode.displayName = 'MiniMapNode'; + +export default MiniMapNode; diff --git a/src/plugins/MiniMap/index.tsx b/src/plugins/MiniMap/index.tsx index e91205c8..45b1486f 100644 --- a/src/plugins/MiniMap/index.tsx +++ b/src/plugins/MiniMap/index.tsx @@ -4,18 +4,14 @@ import classnames from 'classnames'; import { useStoreState } from '../../store/hooks'; import { getRectOfNodes, getBoundsofRects } from '../../utils/graph'; import { Node, Rect } from '../../types'; +import MiniMapNode from './MiniMapNode'; type StringFunc = (node: Node) => string; interface MiniMapProps extends React.HTMLAttributes { - nodeColor: string | StringFunc; - nodeBorderRadius: number; - maskColor: string; -} -interface MiniMapNodeProps { - node: Node; - color: string; - borderRadius: number; + nodeColor?: string | StringFunc; + nodeBorderRadius?: number; + maskColor?: string; } const baseStyle: CSSProperties = { @@ -27,29 +23,7 @@ const baseStyle: CSSProperties = { height: 150, }; -const MiniMapNode = ({ node, color, borderRadius }: MiniMapNodeProps) => { - const { - position: { x, y }, - width, - height, - } = node.__rg; - const { background, backgroundColor } = node.style || {}; - const fill = (background || backgroundColor || color) as string; - return ( - - ); -}; - -export default ({ +const MiniMap = ({ style = { backgroundColor: '#f8f8f8' }, className, nodeColor = '#ddd', @@ -105,7 +79,7 @@ export default ({ }} className={mapClasses} > - {state.nodes.map(node => ( + {state.nodes.map((node) => ( ))} ); }; + +MiniMap.displayName = 'MiniMap'; + +export default MiniMap;