From 7f18bfbe6461a5c68aff3877b7cc51856c71847e Mon Sep 17 00:00:00 2001 From: moklick Date: Tue, 26 Jul 2022 18:26:20 +0200 Subject: [PATCH] feat(background): add cross variant closes #2320 --- examples/nextjs/pages/Backgrounds/index.tsx | 53 +++++++++++++++ .../nextjs/pages/Backgrounds/style.module.css | 13 ++++ examples/nextjs/pages/_app.tsx | 3 +- examples/nextjs/pages/index.tsx | 2 +- packages/background/src/Background.tsx | 64 +++++++++++++------ packages/background/src/types.ts | 12 ++-- packages/background/src/utils.tsx | 21 +++++- 7 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 examples/nextjs/pages/Backgrounds/index.tsx create mode 100644 examples/nextjs/pages/Backgrounds/style.module.css diff --git a/examples/nextjs/pages/Backgrounds/index.tsx b/examples/nextjs/pages/Backgrounds/index.tsx new file mode 100644 index 00000000..e9a550a0 --- /dev/null +++ b/examples/nextjs/pages/Backgrounds/index.tsx @@ -0,0 +1,53 @@ +import React, { FC } from 'react'; + +import ReactFlow, { + Node, + ReactFlowProvider, + useNodesState, +} from '@react-flow/core'; + +import Background, { + BackgroundProps, + BackgroundVariant, +} from '@react-flow/background'; + +import styles from './style.module.css'; + +const initialNodes: Node[] = [ + { + id: '1', + data: { label: 'Node 1' }, + position: { x: 50, y: 50 }, + }, +]; + +const Flow: FC<{ id: string; bgProps: BackgroundProps }> = ({ + id, + bgProps, +}) => { + const [nodes, , onNodesChange] = useNodesState(initialNodes); + + return ( + + + + + + ); +}; + +const Backgrounds: FC = () => ( +
+ + + +
+); + +export default Backgrounds; diff --git a/examples/nextjs/pages/Backgrounds/style.module.css b/examples/nextjs/pages/Backgrounds/style.module.css new file mode 100644 index 00000000..0b9ab158 --- /dev/null +++ b/examples/nextjs/pages/Backgrounds/style.module.css @@ -0,0 +1,13 @@ +.wrapper { + display: flex; + height: 100%; +} + +.wrapper :global .react-flow { + width: 100%; + height: 100%; +} + +.wrapper :global .react-flow { + border-right: 1px solid #ddd; +} diff --git a/examples/nextjs/pages/_app.tsx b/examples/nextjs/pages/_app.tsx index 7c1cac6a..4144798a 100755 --- a/examples/nextjs/pages/_app.tsx +++ b/examples/nextjs/pages/_app.tsx @@ -4,6 +4,7 @@ import '../styles/globals.css'; const routes = [ '/', + '/Backgrounds', '/ControlledUncontrolled', '/CustomConnectionLine', '/CustomNode', @@ -47,7 +48,7 @@ function MyApp({ Component, pageProps }) { return ( <>
- + React Flow Dev