Skip to content

Commit f3075bc

Browse files
authored
docs: add custom components to getting-started example (#1677)
Signed-off-by: braks <[email protected]>
1 parent 59be22d commit f3075bc

File tree

1 file changed

+155
-2
lines changed

1 file changed

+155
-2
lines changed

docs/src/guide/getting-started.md

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Here's a simple example to get you started:
7474

7575
::: code-group
7676

77-
```vue [<LogosJavascript />]
77+
```vue [App.vue <LogosJavascript />]
7878
<script setup>
7979
import { ref } from 'vue'
8080
import { VueFlow } from '@vue-flow/core'
@@ -182,7 +182,100 @@ const edges = ref([
182182
</style>
183183
```
184184

185-
```vue [<LogosTypescript />]
185+
```vue [SpecialNode.vue <LogosJavascript />]
186+
<script setup>
187+
import { computed } from 'vue'
188+
189+
const props = defineProps({
190+
position: {
191+
type: Object,
192+
required: true,
193+
}
194+
})
195+
196+
const x = computed(() => `${Math.round(props.position.x)}px`)
197+
const y = computed(() => `${Math.round(props.position.y)}px`)
198+
</script>
199+
200+
<template>
201+
<div class="vue-flow__node-default">
202+
<div>{{ data.label }}</div>
203+
204+
<div>
205+
{x} {y}
206+
</div>
207+
208+
<Handle type="source" :position="Position.Bottom" />
209+
</div>
210+
</template>
211+
```
212+
213+
```vue [SpecialEdge.vue <LogosJavascript />]
214+
<script setup>
215+
import { BaseEdge, EdgeLabelRenderer, getBezierPath } from '@vue-flow/core'
216+
import { computed } from 'vue'
217+
218+
const props = defineProps({
219+
sourceX: {
220+
type: Number,
221+
required: true,
222+
},
223+
sourceY: {
224+
type: Number,
225+
required: true,
226+
},
227+
targetX: {
228+
type: Number,
229+
required: true,
230+
},
231+
targetY: {
232+
type: Number,
233+
required: true,
234+
},
235+
sourcePosition: {
236+
type: String,
237+
required: true,
238+
},
239+
targetPosition: {
240+
type: String,
241+
required: true,
242+
},
243+
data: {
244+
type: Object,
245+
required: true,
246+
}
247+
})
248+
249+
const path = computed(() => getBezierPath(props))
250+
</script>
251+
252+
<script>
253+
export default {
254+
inheritAttrs: false,
255+
}
256+
</script>
257+
258+
<template>
259+
<!-- You can use the `BaseEdge` component to create your own custom edge more easily -->
260+
<BaseEdge :path="path[0]" />
261+
262+
<!-- Use the `EdgeLabelRenderer` to escape the SVG world of edges and render your own custom label in a `<div>` ctx -->
263+
<EdgeLabelRenderer>
264+
<div
265+
:style="{
266+
pointerEvents: 'all',
267+
position: 'absolute',
268+
transform: `translate(-50%, -50%) translate(${path[1]}px,${path[2]}px)`,
269+
}"
270+
class="nodrag nopan"
271+
>
272+
{{ data.hello }}
273+
</div>
274+
</EdgeLabelRenderer>
275+
</template>
276+
```
277+
278+
```vue [App.vue <LogosTypescript />]
186279
<script setup lang="ts">
187280
import { ref } from 'vue'
188281
import type { Node, Edge } from '@vue-flow/core'
@@ -291,6 +384,66 @@ const edges = ref<Edge[]>([
291384
</style>
292385
```
293386

387+
```vue [SpecialNode.vue <LogosTypescript />]
388+
<script setup lang="ts">
389+
import { computed } from 'vue'
390+
import type { NodeProps } from '@vue-flow/core'
391+
392+
const props = defineProps<NodeProps>()
393+
394+
const x = computed(() => `${Math.round(props.position.x)}px`)
395+
const y = computed(() => `${Math.round(props.position.y)}px`)
396+
</script>
397+
398+
<template>
399+
<div class="vue-flow__node-default">
400+
<div>{{ data.label }}</div>
401+
402+
<div>
403+
{x} {y}
404+
</div>
405+
406+
<Handle type="source" :position="Position.Bottom" />
407+
</div>
408+
</template>
409+
```
410+
411+
```vue [SpecialEdge.vue <LogosTypescript />]
412+
<script setup lang="ts">
413+
import { BaseEdge, EdgeLabelRenderer, getBezierPath, type EdgeProps } from '@vue-flow/core'
414+
import { computed } from 'vue'
415+
416+
const props = defineProps<EdgeProps>()
417+
418+
const path = computed(() => getBezierPath(props))
419+
</script>
420+
421+
<script>
422+
export default {
423+
inheritAttrs: false,
424+
}
425+
</script>
426+
427+
<template>
428+
<!-- You can use the `BaseEdge` component to create your own custom edge more easily -->
429+
<BaseEdge :path="path[0]" />
430+
431+
<!-- Use the `EdgeLabelRenderer` to escape the SVG world of edges and render your own custom label in a `<div>` ctx -->
432+
<EdgeLabelRenderer>
433+
<div
434+
:style="{
435+
pointerEvents: 'all',
436+
position: 'absolute',
437+
transform: `translate(-50%, -50%) translate(${path[1]}px,${path[2]}px)`,
438+
}"
439+
class="nodrag nopan"
440+
>
441+
{{ data.hello }}
442+
</div>
443+
</EdgeLabelRenderer>
444+
</template>
445+
```
446+
294447
:::
295448

296449
## TypeScript

0 commit comments

Comments
 (0)