feat: Add pattern slot to background

# What's changed?

* Add a slot named pattern to background
* Allows for icons or similar things to be passed as bg pattern
This commit is contained in:
Braks
2022-05-11 22:10:40 +02:00
parent 5fb0280e5b
commit 152801edac
@@ -26,7 +26,7 @@ const background = $computed(() => {
const scaledGap = gap && gap * viewport.zoom
const xOffset = scaledGap && viewport.x % scaledGap
const yOffset = scaledGap && viewport.y % scaledGap
const bgSize = size || 0.4 * viewport.zoom
const bgSize = size * viewport.zoom
return {
scaledGap,
@@ -66,15 +66,17 @@ export default {
:height="background.scaledGap"
patternUnits="userSpaceOnUse"
>
<template v-if="variant === BackgroundVariant.Lines">
<path :stroke="patternColor" :stroke-width="size" :d="d" />
</template>
<template v-else-if="variant === BackgroundVariant.Dots">
<circle :cx="background.size" :cy="background.size" :r="background.size" :fill="patternColor" />
</template>
<svg v-if="bgColor" height="100" width="100">
<rect width="100%" height="100%" :fill="bgColor" />
</svg>
<slot name="pattern">
<template v-if="variant === BackgroundVariant.Lines">
<path :stroke="patternColor" :stroke-width="size" :d="d" />
</template>
<template v-else-if="variant === BackgroundVariant.Dots">
<circle :cx="background.size" :cy="background.size" :r="background.size" :fill="patternColor" />
</template>
<svg v-if="bgColor" height="100" width="100">
<rect width="100%" height="100%" :fill="bgColor" />
</svg>
</slot>
</pattern>
<rect :x="x" :y="y" width="100%" height="100%" :fill="`url(#${patternId})`" />
<slot></slot>