Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
Showing
26 changed files
with
1,084 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Draggable Elements | ||
|
||
Draggable elements give you the ability to move, resize and rotate elements by dragging them with the mouse. This is useful for creating floating elements in your slides. | ||
|
||
## Directive Usage | ||
|
||
### Data from the frontmatter | ||
|
||
```md | ||
--- | ||
dragPos: | ||
square: Left,Top,Width,Height,Rotate | ||
--- | ||
|
||
<img v-drag="'square'" src="https://sli.dev/logo.png"> | ||
``` | ||
|
||
### Data from the directive value | ||
|
||
::: warning | ||
Slidev use regex to update the position value in the slide content. If you meet problems, please use the frontmatter to define the values instead. | ||
::: | ||
|
||
```md | ||
<img v-drag="[Left,Top,Width,Height,Rotate]" src="https://sli.dev/logo.png"> | ||
``` | ||
|
||
## Component Usage | ||
|
||
### Data from the frontmatter | ||
|
||
```md | ||
--- | ||
dragPos: | ||
foo: Left,Top,Width,Height,Rotate | ||
--- | ||
|
||
<v-drag pos="foo" text-3xl> | ||
<carbon:arrow-up /> | ||
Use the `v-drag` component to have a draggable container! | ||
</v-drag> | ||
``` | ||
|
||
### Data from props | ||
|
||
```md | ||
<v-drag pos="Left,Top,Width,Height,Rotate" text-3xl> | ||
<carbon:arrow-up /> | ||
Use the `v-drag` component to have a draggable container! | ||
</v-drag> | ||
``` | ||
|
||
## Automatic Height | ||
|
||
You can set `Height` to `NaN` (if you use the directive) or `_` (if you use the component) to make the height of the draggable element automatically adjust to its content. | ||
|
||
## Create a Draggable Element | ||
|
||
When you first create a draggable element, you don't need to specify the position value (but you need to specify the position name if you want to use the frontmatter). Slidev will automatically generate the initial position value for you. | ||
|
||
## Controls | ||
|
||
- Double click the draggable element to start dragging it. | ||
- You can also use the arrow keys to move the element. | ||
- Hold `Shift` while dragging to preserve its aspect ratio. | ||
- Click outside the draggable element to stop dragging it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, onUnmounted } from 'vue' | ||
import type { DragElementMarkdownSource } from '../composables/useDragElements' | ||
import { useDragElement } from '../composables/useDragElements' | ||
const props = defineProps<{ | ||
pos?: string | ||
markdownSource?: DragElementMarkdownSource | ||
}>() | ||
const { id, container, containerStyle, mounted, unmounted, startDragging } = useDragElement(null, props.pos, props.markdownSource) | ||
onMounted(mounted) | ||
onUnmounted(unmounted) | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="container" | ||
:data-drag-id="id" | ||
:style="containerStyle" | ||
class="p-1" | ||
@dblclick="startDragging" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
Oops, something went wrong.