diff --git a/cypress/integration/flow/basic.spec.js b/cypress/integration/flow/basic.spec.js index 121896d3..39209e42 100644 --- a/cypress/integration/flow/basic.spec.js +++ b/cypress/integration/flow/basic.spec.js @@ -13,9 +13,6 @@ describe('Basic Flow Rendering', () => { it('renders a grid', () => { cy.get('.react-flow__background'); - - const gridStroke = Cypress.$('.react-flow__background path').attr('stroke'); - expect(gridStroke).to.equal('#eee'); }); it('selects a node by click', () => { diff --git a/example/src/Overview/index.js b/example/src/Overview/index.js index d2247c38..c7e3c64f 100644 --- a/example/src/Overview/index.js +++ b/example/src/Overview/index.js @@ -136,7 +136,7 @@ const OverviewFlow = () => { }} /> - + ); }; diff --git a/src/additional-components/Background/index.tsx b/src/additional-components/Background/index.tsx index 685446e6..c655b544 100644 --- a/src/additional-components/Background/index.tsx +++ b/src/additional-components/Background/index.tsx @@ -1,4 +1,4 @@ -import React, { memo, HTMLAttributes } from 'react'; +import React, { memo, useMemo, HTMLAttributes } from 'react'; import cc from 'classcat'; import { useStoreState } from '../../store/hooks'; @@ -24,26 +24,27 @@ const Background = memo( const [x, y, scale] = useStoreState((s) => s.transform); const bgClasses = cc(['react-flow__background', className]); - const bgColor = color ? color : defaultColors[variant]; const scaledGap = gap * scale; const xOffset = x % scaledGap; const yOffset = y % scaledGap; - const isLines = variant === BackgroundVariant.Lines; - const path = isLines - ? createGridLinesPath(xOffset, yOffset, scaledGap) - : createGridDotsPath(xOffset, yOffset, scaledGap, size); - const fill = isLines ? 'none' : bgColor; - const stroke = isLines ? bgColor : 'none'; - const bg = ``; + const bgSvgTile = useMemo(() => { + const isLines = variant === BackgroundVariant.Lines; + const bgColor = color ? color : defaultColors[variant]; + const path = isLines ? createGridLinesPath(scaledGap, size, bgColor) : createGridDotsPath(size, bgColor); + + return encodeURIComponent( + `${path}` + ); + }, [variant, scaledGap, size, color]); return (
); diff --git a/src/additional-components/Background/utils.ts b/src/additional-components/Background/utils.ts index c9b33e3a..c0b6d315 100644 --- a/src/additional-components/Background/utils.ts +++ b/src/additional-components/Background/utils.ts @@ -1,13 +1,7 @@ -export const createGridLinesPath = (xOffset: number, yOffset: number, scaledGap: number): string => { - const x = xOffset < 0 ? scaledGap + xOffset : xOffset; - const y = yOffset < 0 ? scaledGap + yOffset : yOffset; - - return `M${x} 0 V${scaledGap} M0 ${y} H${scaledGap}`; +export const createGridLinesPath = (scaledGap: number, strokeWidth: number, stroke: string): string => { + return ``; }; -export const createGridDotsPath = (xOffset: number, yOffset: number, scaledGap: number, size: number): string => { - const x = xOffset < 0 ? scaledGap + xOffset : xOffset; - const y = yOffset < 0 ? scaledGap + yOffset : yOffset; - - return `M${x} ${y - size} l${size} ${size} l${-size} ${size} l${-size} ${-size}z`; +export const createGridDotsPath = (size: number, fill: string): string => { + return ``; };