Skip to content

Commit 5efe36f

Browse files
committed
feat: add connection component
1 parent 7c951a0 commit 5efe36f

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

apps/www/assets/css/tailwind.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
--input: 214.3 31.8% 91.4%;
6969
--ring: 221.2 83.2% 53.3%;
7070
--radius: 0.5rem;
71+
72+
--shadcn-ring: oklch(0.708 0 0);
7173
}
7274

7375
.dark {
@@ -98,6 +100,8 @@
98100
--border: 217.2 32.6% 17.5%;
99101
--input: 217.2 32.6% 17.5%;
100102
--ring: 224.3 76.3% 48%;
103+
104+
--shadcn-ring: oklch(0.439 0 0);
101105
}
102106
}
103107

@@ -109,13 +113,17 @@
109113
body {
110114
@apply bg-background text-foreground;
111115
}
116+
112117
:root {
113118
--color-background: hsl(var(--background));
114119
--color-muted-foreground: hsl(var(--muted-foreground));
120+
--color-ring: var(--shadcn-ring);
115121
}
122+
116123
.dark {
117124
--color-background: hsl(var(--background));
118125
--color-muted-foreground: hsl(var(--muted-foreground));
126+
--color-ring: var(--shadcn-ring);
119127
}
120128
}
121129

packages/elements/src/canvas/Canvas.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { FlowEmits, FlowProps } from '@vue-flow/core'
2+
import type { FlowEmits, FlowProps, FlowSlots } from '@vue-flow/core'
33
import { Background } from '@vue-flow/background'
44
import { VueFlow } from '@vue-flow/core'
55
import { useForwardPropsEmits } from 'reka-ui'
@@ -17,14 +17,17 @@ const props = withDefaults(defineProps<FlowProps>(), {
1717
})
1818
1919
const emits = defineEmits<FlowEmits>()
20-
20+
const slots = defineSlots<FlowSlots>()
2121
const forwarded = useForwardPropsEmits(props, emits)
2222
</script>
2323

2424
<template>
2525
<VueFlow data-slot="canvas" v-bind="forwarded">
2626
<Background />
2727
<Controls />
28-
<slot />
28+
29+
<template v-if="slots['connection-line']" #connection-line="connectionLineProps">
30+
<slot name="connection-line" v-bind="connectionLineProps" />
31+
</template>
2932
</VueFlow>
3033
</template>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script setup lang="ts">
2+
import type { ConnectionLineProps } from '@vue-flow/core'
3+
import { computed } from 'vue'
4+
5+
const props = defineProps<ConnectionLineProps>()
6+
7+
const HALF = 0.5
8+
9+
const pathD = computed(() => {
10+
const { sourceX, sourceY, targetX, targetY } = props
11+
const controlX1 = sourceX + (targetX - sourceX) * HALF
12+
const controlX2 = sourceX + (targetX - sourceX) * HALF
13+
return `M${sourceX},${sourceY} C ${controlX1},${sourceY} ${controlX2},${targetY} ${targetX},${targetY}`
14+
})
15+
</script>
16+
17+
<template>
18+
<g>
19+
<path
20+
class="animated"
21+
fill="none"
22+
stroke="var(--color-ring)"
23+
:stroke-width="1"
24+
:d="pathD"
25+
/>
26+
27+
<circle
28+
:cx="targetX"
29+
:cy="targetY"
30+
fill="#fff"
31+
:r="3"
32+
stroke="var(--color-ring)"
33+
:stroke-width="1"
34+
/>
35+
</g>
36+
</template>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Connection } from './Connection.vue'

packages/examples/src/workflow.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import type { Edge, Node } from '@vue-flow/core'
33
import { Canvas } from '@repo/elements/canvas'
4+
import { Connection } from '@repo/elements/connection'
45
import { nanoid } from 'nanoid'
56
import { ref } from 'vue'
67
@@ -33,6 +34,10 @@ const edges = ref<Edge[]>([
3334

3435
<template>
3536
<div style="height: 400px">
36-
<Canvas :nodes="nodes" :edges="edges" />
37+
<Canvas :nodes="nodes" :edges="edges">
38+
<template #connection-line="connectionLineProps">
39+
<Connection v-bind="connectionLineProps" />
40+
</template>
41+
</Canvas>
3742
</div>
3843
</template>

0 commit comments

Comments
 (0)