add id and offset to background props
This commit is contained in:
@@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user