Skip to content

Commit 7191805

Browse files
committed
feat: add v-drag-line component
1 parent ec1d664 commit 7191805

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

components/VDragLine.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script setup lang="ts">
2+
import { computed, onMounted, onUnmounted } from 'vue'
3+
import type { DragElementMarkdownSource } from '@slidev/client/composables/useDragElements.ts'
4+
import { useDragElement } from '@slidev/client/composables/useDragElements.ts'
5+
import Line from './Line.vue'
6+
7+
const props = defineProps<{
8+
pos?: string
9+
markdownSource?: DragElementMarkdownSource
10+
width?: number | string
11+
color?: string
12+
twoWay?: boolean
13+
}>()
14+
15+
const { dragId, mounted, unmounted, startDragging, stopDragging, x0, y0, width, height } = useDragElement(
16+
null,
17+
props.pos ?? '100,100,300,300',
18+
props.markdownSource,
19+
true
20+
)
21+
22+
onMounted(mounted)
23+
onUnmounted(unmounted)
24+
25+
const x1 = computed(() => x0.value - width.value / 2)
26+
const y1 = computed(() => y0.value - height.value / 2)
27+
const x2 = computed(() => x0.value + width.value / 2)
28+
const y2 = computed(() => y0.value + height.value / 2)
29+
</script>
30+
31+
<template>
32+
<Line
33+
:x1
34+
:y1
35+
:x2
36+
:y2
37+
:data-drag-id="dragId"
38+
:width="props.width"
39+
:color="props.color"
40+
:two-way="props.twoWay"
41+
@dblclick="startDragging"
42+
@click-outside="stopDragging"
43+
/>
44+
</template>

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default defineConfig({
6464
{ text: 'ArrowHeads', link: '/components/arrowheads' },
6565
{ text: 'Thumb', link: '/components/thumb' },
6666
{ text: 'Line', link: '/components/line' },
67+
{ text: 'VDragLine', link: '/components/vdragline' },
6768
],
6869
},
6970
{ text: 'Customizing', link: '/customizing' },

docs/components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ The current components are:
2626

2727
- [Line](/components/line) - draws a straight line (no arrowheads)
2828

29+
- [VDragLine](/components/vdragline) - draws a straight line (no arrowheads), the v-drag version.
30+
2931
Most component can just be included in-line in your markdown. However, in some cases it can make sense to position these components using the `v-drag` directive. For example, the `SpeechBubble` component can be positioned using the `v-drag` directive to place it in a specific location on the slide. This can be useful for creating custom layouts or animations. In that case, it makes sense to keep the component in the [default slot](/layouts#slots) of each layout.

docs/components/vdragline.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# VDragLine
2+
3+
## Description
4+
5+
Draws a line using the dragging feature.
6+
See [VDragArrow](https://sli.dev/builtin/components#vdragarrow) in the main slidev. This uses the same props as the [`Line` component](/components/line).

0 commit comments

Comments
 (0)