diff --git a/.changeset/two-walls-jam.md b/.changeset/two-walls-jam.md new file mode 100644 index 00000000..9c2eb07a --- /dev/null +++ b/.changeset/two-walls-jam.md @@ -0,0 +1,5 @@ +--- +'@reactflow/background': patch +--- + +add id and offset prop diff --git a/examples/vite-app/src/examples/Backgrounds/index.tsx b/examples/vite-app/src/examples/Backgrounds/index.tsx index c7783b00..0cbabf0a 100644 --- a/examples/vite-app/src/examples/Backgrounds/index.tsx +++ b/examples/vite-app/src/examples/Backgrounds/index.tsx @@ -19,13 +19,15 @@ const initialNodes: Node[] = [ }, ]; -const Flow: FC<{ id: string; bgProps: BackgroundProps }> = ({ id, bgProps }) => { +const Flow: FC<{ id: string; bgProps: BackgroundProps[] }> = ({ id, bgProps }) => { const [nodes, , onNodesChange] = useNodesState(initialNodes); return ( - + {bgProps.map((props, idx) => ( + + ))} ); @@ -33,9 +35,16 @@ const Flow: FC<{ id: string; bgProps: BackgroundProps }> = ({ id, bgProps }) => const Backgrounds: FC = () => (
- - - + + + +
); diff --git a/packages/background/src/Background.tsx b/packages/background/src/Background.tsx index bf8a4336..e0efd77b 100644 --- a/packages/background/src/Background.tsx +++ b/packages/background/src/Background.tsx @@ -21,12 +21,14 @@ const defaultSize = { const selector = (s: ReactFlowState) => ({ transform: s.transform, patternId: `pattern-${s.rfId}` }); function Background({ + id, variant = BackgroundVariant.Dots, - gap = 20, // only used for dots and cross - size, + gap = 20, // only used for lines and cross + size, lineWidth = 1, + offset = 2, color, style, className, @@ -44,8 +46,8 @@ function Background({ const patternDimensions: [number, number] = isCross ? [scaledSize, scaledSize] : scaledGap; const patternOffset = isDots - ? [scaledSize / 2, scaledSize / 2] - : [patternDimensions[0] / 2, patternDimensions[1] / 2]; + ? [scaledSize / offset, scaledSize / offset] + : [patternDimensions[0] / offset, patternDimensions[1] / offset]; return ( {isDots ? ( - + ) : ( )} - + ); } diff --git a/packages/background/src/types.ts b/packages/background/src/types.ts index 6f9a7155..f4cae1b5 100644 --- a/packages/background/src/types.ts +++ b/packages/background/src/types.ts @@ -7,10 +7,12 @@ export enum BackgroundVariant { } export type BackgroundProps = { + id?: string color?: string; className?: string; gap?: number | [number, number]; size?: number; + offset?: number; lineWidth?: number; variant?: BackgroundVariant; style?: CSSProperties;