refactor(additional-components): use vue flow id for bg pattern id
This commit is contained in:
@@ -20,7 +20,7 @@ const defaultColors: Record<BackgroundVariant, string> = {
|
|||||||
[BackgroundVariant.Lines]: '#eee',
|
[BackgroundVariant.Lines]: '#eee',
|
||||||
}
|
}
|
||||||
|
|
||||||
const { viewport } = useVueFlow()
|
const { id, viewport } = useVueFlow()
|
||||||
|
|
||||||
const background = $computed(() => {
|
const background = $computed(() => {
|
||||||
const scaledGap = gap && gap * viewport.value.zoom
|
const scaledGap = gap && gap * viewport.value.zoom
|
||||||
@@ -37,7 +37,7 @@ const background = $computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// when there are multiple flows on a page we need to make sure that every background gets its own pattern.
|
// when there are multiple flows on a page we need to make sure that every background gets its own pattern.
|
||||||
const patternId = `pattern-${Math.floor(Math.random() * 100000)}`
|
const patternId = `pattern-${id}`
|
||||||
|
|
||||||
const patternColor = computed(() => initialPatternColor || defaultColors[variant || BackgroundVariant.Dots])
|
const patternColor = computed(() => initialPatternColor || defaultColors[variant || BackgroundVariant.Dots])
|
||||||
|
|
||||||
@@ -73,16 +73,20 @@ export default {
|
|||||||
<template v-if="variant === BackgroundVariant.Lines">
|
<template v-if="variant === BackgroundVariant.Lines">
|
||||||
<path :stroke="patternColor" :stroke-width="size" :d="d" />
|
<path :stroke="patternColor" :stroke-width="size" :d="d" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else-if="variant === BackgroundVariant.Dots">
|
<template v-else-if="variant === BackgroundVariant.Dots">
|
||||||
<circle :cx="background.size" :cy="background.size" :r="background.size" :fill="patternColor" />
|
<circle :cx="background.size" :cy="background.size" :r="background.size" :fill="patternColor" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<svg v-if="bgColor" height="100" width="100">
|
<svg v-if="bgColor" height="100" width="100">
|
||||||
<rect width="100%" height="100%" :fill="bgColor" />
|
<rect width="100%" height="100%" :fill="bgColor" />
|
||||||
</svg>
|
</svg>
|
||||||
</slot>
|
</slot>
|
||||||
</pattern>
|
</pattern>
|
||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
<rect :x="x" :y="y" width="100%" height="100%" :fill="`url(#${patternId})`" />
|
<rect :x="x" :y="y" width="100%" height="100%" :fill="`url(#${patternId})`" />
|
||||||
|
|
||||||
<slot :id="patternId" />
|
<slot :id="patternId" />
|
||||||
</svg>
|
</svg>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user