Files
xyflow/examples/nextjs/pages/Backgrounds/index.tsx
T
Moritz KlackandGitHub 97c22ace71 Refactor: CSS handling (#2344)
* refactor(css): only load base styles, add css task, cleanup exports
* style(base): add edge label bg
* refactor(css): use css-utils
* feat(core): add Panel component
* refactor(background): cleanup
* refactor(css-handling): cleanup
2022-08-05 18:36:32 +02:00

56 lines
1.1 KiB
TypeScript

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 (
<ReactFlowProvider>
<ReactFlow nodes={nodes} onNodesChange={onNodesChange} id={id}>
<Background {...bgProps} />
</ReactFlow>
</ReactFlowProvider>
);
};
const Backgrounds: FC = () => (
<div className={styles.wrapper}>
<Flow id="flow-a" bgProps={{ variant: BackgroundVariant.Dots }} />
<Flow
id="flow-b"
bgProps={{ variant: BackgroundVariant.Lines, gap: [50, 50] }}
/>
<Flow
id="flow-c"
bgProps={{ variant: BackgroundVariant.Cross, gap: [100, 50] }}
/>
</div>
);
export default Backgrounds;