@fuyoo/dragresize v0.1.10
dragresize
this is a fork. from a7650/vue3-draggable-resizable
Vue3 组件 用于拖拽调整位置和大小的的组件,同时支持冲突检测,元素吸附对齐,实时参考线。 Vue3 Component Draggable and resizable component for vue3, and, support element adsorption alignment, real-time reference line, etc.
Table of Contents
Features
- Draggable and resizable
- Define handles for resizing
- Restrict movement and size in parent node
- Customize various class names
- Provide your own markup for handles
- Adsorption alignment
- Reference line
Usage
$ npm install @fuyoo/dragresize
Register the DragResize
// >main.js
import { createApp } from 'vue'
import App from './App.vue'
import DragResize from '@fuyoo/dragresize'
//default styles
import '@fuyoo/dragresize/dist/DragResize.css'
// You will have a global component named "DragResize"
createApp(App)
.use(DragResize)
.mount('#app')
You can also use it separately within the component
// >component.js
import { defineComponent } from 'vue'
import DragResize from '@fuyoo/dragresize'
//default styles
import '@fuyoo/dragresize/dist/DragResize.css'
export default defineComponent({
components: { DragResize }
// ...other
})
Here is a complete example of using "vue-template"
<template>
<div id="app">
<div class="parent">
<DragResize
:initW="110"
:initH="120"
v-model:x="x"
v-model:y="y"
v-model:w="w"
v-model:h="h"
v-model:active="active"
:draggable="true"
:resizable="true"
@activated="print('activated')"
@deactivated="print('deactivated')"
@drag-start="print('drag-start')"
@resize-start="print('resize-start')"
@dragging="print('dragging')"
@resizing="print('resizing')"
@drag-end="print('drag-end')"
@resize-end="print('resize-end')"
>
This is a test example
</DragResize>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue'
import DragResize from '@fuyoo/dragresize'
//default styles
import '@fuyoo/dragresize/dist/DragResize.css'
export default defineComponent({
components: { DragResize },
data() {
return {
x: 100,
y: 100,
h: 100,
w: 100,
active: false
}
},
methods: {
print(val) {
console.log(val)
}
}
})
</script>
<style>
.parent {
width: 200px;
height: 200px;
position: absolute;
top: 100px;
left: 100px;
border: 1px solid #000;
user-select: none;
}
</style>
Props
scale
type: Number
default: 1
Set initial scale
<DragResize :scale="1" />
initW
type: Number
default: null
Set initial width(px)
<DragResize :initW="100" />
initH
type: Number
default: null
Set initial height(px)
<DragResize :initH="100" />
w
type: Number
default: 0
Current width(px) of the container. You can use "v-model:w" to keeps it up-to-date
<DragResize v-model:w="100" />
h
type: Number
default: 0
Current height(px) of the container. You can use "v-model:h" to keeps it up-to-date
<DragResize v-model:h="100" />
x
type: Number
default: 0
Current left(px) of the container. You can use "v-model:x" to keeps it up-to-date
<DragResize v-model:x="100" />
y
type: Number
default: 0
The current top(px) of the container. You can use "v-model:y" to keeps it up-to-date
<DragResize v-model:y="100" />
minW
type: Number
default: 20
Minimum width(px)
<DragResize :minW="100" />
minH
type: Number
default: 20
Minimum height(px)
<DragResize :minH="100" />
active
type: Boolean
default: false
Indicates whether the component is selected. You can use "v-model:active" to keeps it up-to-date
<DragResize v-model:active="100" />
draggable
type: Boolean
default: true
Defines the component can be draggable or not
<DragResize :draggable="true" />
resizable
type: Boolean
default: true
Defines the component can be resizable or not
<DragResize :draggable="true" />
lockAspectRatio
type: Boolean
default: false
The lockAspectRatio
property is used to lock aspect ratio.
<DragResize :lockAspectRatio="true" />
disabledX
type: Boolean
default: false
Defines the component can be moved on x-axis or not
<DragResize :disabledX="true" />
disabledY
type: Boolean
default: false
Defines the component can be moved on y-axis or not
<DragResize :disabledY="true" />
disabledW
type: Boolean
default: false
Defines the component`s width can be modify or not
<DragResize :disabledW="true" />
disabledH
type: Boolean
default: false
Defines the component`s height can be modify or not
<DragResize :disabledH="true" />
parent
type: Boolean
default: false
Restrict movement and size within its parent node
<DragResize :parent="true" />
handles
type: Array
default: ['tl', 'tm', 'tr', 'ml', 'mr', 'bl', 'bm', 'br']
Define the array of handles to restrict the element resizing
tl
: Top lefttm
: Top middletr
: Top rightmr
: Middle rightml
: Middle leftbl
: Bottom leftbm
: Bottom middlebr
: Bottom right
<DragResize :handles="['tl','tr','bl','br']" />
classNameDraggable
type: String
default: draggable
Used to set the custom class
of a draggable-resizable component when draggable
is enable.
<DragResize classNameDraggable="draggable" />
classNameResizable
type: String
default: resizable
Used to set the custom class
of a draggable-resizable component when resizable
is enable.
<DragResize classNameResizable="resizable" />
classNameDragging
type: String
default: dragging
Used to set the custom class
of a draggable-resizable component when is dragging.
<DragResize classNameDragging="dragging" />
classNameResizing
type: String
default: resizing
Used to set the custom class
of a draggable-resizable component when is resizing.
<DragResize classNameResizing="resizing" />
classNameActive
type: String
default: active
Used to set the custom class
of a draggable-resizable component when is active.
<DragResize classNameActive="active" />
classNameHandle
type: String
default: handle
Used to set the custom common class
of each handle element.
<DragResize classNameHandle="my-handle" />
following handle nodes will be rendered
...
<div class="vdr-handle vdr-handle-tl my-handle my-handle-tl"></div>
<div class="vdr-handle vdr-handle-tm my-handle my-handle-tm"></div>
<div class="vdr-handle vdr-handle-tr my-handle my-handle-tr"></div>
<div class="vdr-handle vdr-handle-ml my-handle my-handle-mr"></div>
...
Events
activated
payload: -
<DragResize @activated="activatedHandle" />
deactivated
payload: -
<DragResize @deactivated="deactivatedHandle" />
drag-start
payload: { x: number, y: number }
<DragResize @drag-start="dragStartHandle" />
dragging
payload: { x: number, y: number }
<DragResize @dragging="dragStartHandle" />
drag-end
payload: { x: number, y: number }
<DragResize @drag-end="dragEndHandle" />
resize-start
payload: { x: number, y: number, w: number, h: number }
<DragResize @resize-start="resizeStartHandle" />
resizing
payload: { x: number, y: number, w: number, h: number }v
<DragResize @resizing="resizingHandle" />
resize-end
payload: { x: number, y: number, w: number, h: number }
<DragResize @resize-end="resizeEndHandle" />
Use-adsorption-alignment
You need to import another component to use the "adsorption alignment" feature.
This can be used as follows.
<template>
<div id="app">
<div class="parent">
<DragResizeContainer>
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue'
import DragResize from '@fuyoo/dragresize'
// This component is not exported by default
// If you used "app.use(DragResize)",then you don't need to import it, you can use it directly.
import { DragResizeContainer } from '@fuyoo/dragresize'
//default styles
import '@fuyoo/dragresize/dist/DragResize.css'
export default defineComponent({
components: { DragResize, DragResizeContainer }
})
</script>
<style>
.parent {
width: 200px;
height: 200px;
position: absolute;
top: 100px;
left: 100px;
border: 1px solid #000;
user-select: none;
}
</style>
DragResizeContainer Props
These props apply to DragResizeContainer
disabled
type: Boolean
default: false
Disable this feature
<DragResizeContainer :disabled="true">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
adsorbParent
type: Boolean
default: true
Adsorption near parent component
<DragResizeContainer :adsorbParent="false">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
adsorbCols
type: Array<Number>
default: null
Custom guides(column)
<DragResizeContainer :adsorbCols="[10,20,30]">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
adsorbRows
type: Array<Number>
default: null
Custom guides(row)
<DragResizeContainer :adsorbRows="[10,20,30]">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
referenceLineVisible
type: Boolean
default: true
reference line visible
<DragResizeContainer :referenceLineVisible="false">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>
referenceLineColor
type: String
default: #f00
reference line color
<DragResizeContainer :referenceLineColor="#0f0">
<DragResize>
Test
</DragResize>
<DragResize>
Another test
</DragResize>
</DragResizeContainer>