add id and offset to background props

This commit is contained in:
Artyom Sovetnikov
2023-03-21 02:40:38 +03:00
parent 29790476d8
commit dedf0046b5
2 changed files with 11 additions and 7 deletions
+9 -7
View File
@@ -21,12 +21,14 @@ const defaultSize = {
const selector = (s: ReactFlowState) => ({ transform: s.transform, patternId: `pattern-${s.rfId}` }); const selector = (s: ReactFlowState) => ({ transform: s.transform, patternId: `pattern-${s.rfId}` });
function Background({ function Background({
id,
variant = BackgroundVariant.Dots, variant = BackgroundVariant.Dots,
gap = 20,
// only used for dots and cross // only used for dots and cross
size, gap = 20,
// only used for lines and cross // only used for lines and cross
size,
lineWidth = 1, lineWidth = 1,
offset = 2,
color, color,
style, style,
className, className,
@@ -44,8 +46,8 @@ function Background({
const patternDimensions: [number, number] = isCross ? [scaledSize, scaledSize] : scaledGap; const patternDimensions: [number, number] = isCross ? [scaledSize, scaledSize] : scaledGap;
const patternOffset = isDots const patternOffset = isDots
? [scaledSize / 2, scaledSize / 2] ? [scaledSize / offset, scaledSize / offset]
: [patternDimensions[0] / 2, patternDimensions[1] / 2]; : [patternDimensions[0] / offset, patternDimensions[1] / offset];
return ( return (
<svg <svg
@@ -62,7 +64,7 @@ function Background({
data-testid="rf__background" data-testid="rf__background"
> >
<pattern <pattern
id={patternId} id={patternId+id}
x={transform[0] % scaledGap[0]} x={transform[0] % scaledGap[0]}
y={transform[1] % scaledGap[1]} y={transform[1] % scaledGap[1]}
width={scaledGap[0]} width={scaledGap[0]}
@@ -71,12 +73,12 @@ function Background({
patternTransform={`translate(-${patternOffset[0]},-${patternOffset[1]})`} patternTransform={`translate(-${patternOffset[0]},-${patternOffset[1]})`}
> >
{isDots ? ( {isDots ? (
<DotPattern color={patternColor} radius={scaledSize / 2} /> <DotPattern color={patternColor} radius={scaledSize / offset} />
) : ( ) : (
<LinePattern dimensions={patternDimensions} color={patternColor} lineWidth={lineWidth} /> <LinePattern dimensions={patternDimensions} color={patternColor} lineWidth={lineWidth} />
)} )}
</pattern> </pattern>
<rect x="0" y="0" width="100%" height="100%" fill={`url(#${patternId})`} /> <rect x="0" y="0" width="100%" height="100%" fill={`url(#${patternId+id})`} />
</svg> </svg>
); );
} }
+2
View File
@@ -7,10 +7,12 @@ export enum BackgroundVariant {
} }
export type BackgroundProps = { export type BackgroundProps = {
id?: string
color?: string; color?: string;
className?: string; className?: string;
gap?: number | [number, number]; gap?: number | [number, number];
size?: number; size?: number;
offset?: number;
lineWidth?: number; lineWidth?: number;
variant?: BackgroundVariant; variant?: BackgroundVariant;
style?: CSSProperties; style?: CSSProperties;