feat: bind props to slots

* bind props to slots in edges, handle, nodes

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-18 13:40:06 +01:00
parent b2d124ef7a
commit 0be492b7c6
8 changed files with 36 additions and 8 deletions
+11 -1
View File
@@ -34,6 +34,7 @@ interface BezierEdgeProps extends EdgeProps {
sourceHandleId?: ElementId sourceHandleId?: ElementId
targetHandleId?: ElementId targetHandleId?: ElementId
} }
const props = withDefaults(defineProps<BezierEdgeProps>(), { const props = withDefaults(defineProps<BezierEdgeProps>(), {
selected: false, selected: false,
sourcePosition: Position.Bottom, sourcePosition: Position.Bottom,
@@ -65,7 +66,16 @@ export default {
</script> </script>
<template> <template>
<path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" /> <path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" />
<slot> <slot
:x="centered[0]"
:y="centered[1]"
:label="props.label"
:label-style="props.labelStyle"
:label-show-bg="props.labelShowBg"
:label-bg-style="props.labelBgStyle"
:label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius"
>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centered[0]" :x="centered[0]"
+1 -1
View File
@@ -44,7 +44,7 @@ const bgPadding = computed(() => [props.labelBgPadding[0], props.labelBgPadding[
:ry="props.labelBgBorderRadius" :ry="props.labelBgBorderRadius"
/> />
<text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle"> <text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle">
<slot> <slot v-bind="props">
<component <component
:is="props.label?.component" :is="props.label?.component"
v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'" v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
+10 -1
View File
@@ -68,7 +68,16 @@ export default {
</script> </script>
<template> <template>
<path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" /> <path class="vue-flow__edge-path" :style="props.style" :d="path" :marker-end="markerEnd" />
<slot> <slot
:x="centered[0]"
:y="centered[1]"
:label="props.label"
:label-style="props.labelStyle"
:label-show-bg="props.labelShowBg"
:label-bg-style="props.labelBgStyle"
:label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius"
>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centered[0]" :x="centered[0]"
+10 -1
View File
@@ -70,7 +70,16 @@ export default {
</script> </script>
<template> <template>
<path :style="props.style" class="vue-flow__edge-path" :d="path" :marker-end="markerEnd" /> <path :style="props.style" class="vue-flow__edge-path" :d="path" :marker-end="markerEnd" />
<slot> <slot
:x="centerX"
:y="centerY"
:label="props.label"
:label-style="props.labelStyle"
:label-show-bg="props.labelShowBg"
:label-bg-style="props.labelBgStyle"
:label-bg-padding="props.labelBgPadding"
:label-bg-border-radius="props.labelBgBorderRadius"
>
<EdgeText <EdgeText
v-if="props.label" v-if="props.label"
:x="centerX" :x="centerX"
+1 -1
View File
@@ -43,6 +43,6 @@ const onMouseDownHandler = (event: MouseEvent) =>
]" ]"
@mousedown="onMouseDownHandler" @mousedown="onMouseDownHandler"
> >
<slot></slot> <slot :node-id="nodeId" v-bind="props"></slot>
</div> </div>
</template> </template>
+1 -1
View File
@@ -23,7 +23,7 @@ export default {
</script> </script>
<template> <template>
<Handle type="target" :position="props.targetPosition" :is-connectable="props.connectable" /> <Handle type="target" :position="props.targetPosition" :is-connectable="props.connectable" />
<slot> <slot v-bind="props">
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot> </slot>
+1 -1
View File
@@ -20,7 +20,7 @@ export default {
} }
</script> </script>
<template> <template>
<slot> <slot v-bind="props">
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot> </slot>
+1 -1
View File
@@ -20,7 +20,7 @@ export default {
} }
</script> </script>
<template> <template>
<slot> <slot v-bind="props">
<component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" /> <component :is="props.data?.label" v-if="typeof props.data?.label !== 'string'" />
<span v-else v-html="props.data?.label"></span> <span v-else v-html="props.data?.label"></span>
</slot> </slot>