# vue-drag-resize
**Repository Path**: seek/vue-drag-resize
## Basic Information
- **Project Name**: vue-drag-resize
- **Description**: Vue Component for resize and drag elements
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 8
- **Forks**: 0
- **Created**: 2020-08-20
- **Last Updated**: 2023-07-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README

Vue-drag-resize
[](https://npmjs.com/package/vue-drag-resize)
[](LICENSE.md)
[](https://www.npmjs.com/package/vue-drag-resize)
> Vue Component for draggable and resizable elements.
## Table of Contents
* [Features](#features)
* [Install and basic usage](#install-and-basic-usage)
* [Props](#props)
* [Events](#events)
* [Contributing](#contributing)
* [License](#license)
### Demo
[Demo](http://kirillmurashov.com/vue-drag-resize)
### Features
* A lightweight, no-dependency
* All props are reactive
* Support touch events
* Use draggable, resizable or both
* Define sticks for resizing
* Save aspect ratio for resizable components
* Restrict size and movement to parent element
* Restrict drag to vertical or horizontal axis
## Install and basic usage
```bash
$ npm i -s vue-drag-resize
```
Register the component:
```js
import Vue from 'vue'
import VueDragResize from 'vue-drag-resize'
Vue.component('vue-drag-resize', VueDragResize)
```
Use the component:
```vue
Hello World!
{{ top }} х {{ left }}
{{ width }} х {{ height }}
```
### Props
#### isActive
Type: `Boolean`
Required: `false`
Default: `false`
Determines whether the component should be active.
```html
```
#### preventActiveBehavior
Type: `Boolean`
Required: `false`
Default: `false`
Disable behavior of the component by clicking on it and clicking outside the component's area (isActive: true / false).
If the prop is enabled, the component is oriented only to the specified.
```html
```
#### parentW
Type: `Number`
Required: `false`
Default: `0`
Define the initial width of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.
```html
```
#### parentH
Type: `Number`
Required: `false`
Default: `0`
Define the initial height of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.
```html
```
#### parentScaleX
Type: `Number`
Required: `false`
Default: `1`
Define the initial horizontal scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.
```html
```
#### parentScaleY
Type: `Number`
Required: `false`
Default: `1`
Define the initial vertical scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.
```html
```
#### isDraggable
Type: `Boolean`
Required: `false`
Default: `true`
Determines whether the component should draggable.
```html
```
#### isResizable
Type: `Boolean`
Required: `false`
Default: `true`
Determines whether the component should resize.
```html
```
#### parentLimitation
Type: `Boolean`
Required: `false`
Default: `false`
Limits the scope of the component's change to its parent size.
```html
```
#### snapToGrid
Type: `Boolean`
Required: `false`
Default: `false`
Determines whether the component should move and resize in predefined steps.
```html
```
#### gridX
Type: `Number`
Required: `false`
Default: `50`
Define the grid step size for the horizontal axis. Both sides of the component (left and right) will snap to this step.
```html
```
#### gridY
Type: `Number`
Required: `false`
Default: `50`
Define the grid step size for the vertical axis. Both sides of the component (top and bottom) will snap to this step.
```html
```
#### aspectRatio
Type: `Boolean`
Required: `false`
Default: `false`
Determines whether the component should retain its proportions.
```html
```
#### w
Type: `Number`
Required: `false`
Default: `200`
Define the initial width of the component.
```html
```
#### h
Type: `Number`
Required: `false`
Default: `200`
Define the initial height of the component.
```html
```
#### minw
Type: `Number`
Required: `false`
Default: `50`
Define the minimal width of the component.
```html
```
#### minh
Type: `Number`
Required: `false`
Default: `50`
Define the minimal height of the component.
```html
```
#### x
Type: `Number`
Required: `false`
Default: `0`
Define the initial x position of the component.
```html
```
#### y
Type: `Number`
Required: `false`
Default: `0`
Define the initial y position of the component.
```html
```
#### z
Type: `Number|String`
Required: `false`
Default: `auto`
Define the zIndex of the component.
```html
```
#### sticks
Type: `Array`
Required: `false`
Default: `['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']`
Define the array of handles to restrict the element resizing:
* `tl` - Top left
* `tm` - Top middle
* `tr` - Top right
* `mr` - Middle right
* `br` - Bottom right
* `bm` - Bottom middle
* `bl` - Bottom left
* `ml` - Middle left
```html
```
#### axis
Type: `String`
Required: `false`
Default: `both`
Define the axis on which the element is draggable. Available values are `x`, `y`, `both` or `none`.
```html
```
#### dragHandle
Type: `String`
Required: `false`
Defines the selector that should be used to drag the component.
```html
```
#### dragCancel
Type: `String`
Required: `false`
Defines a selector that should be used to prevent drag initialization.
```html
```
---
### Events
#### clicked
Required: `false`
Parameters: `Original event handler`
Called whenever the component gets clicked.
```html
```
#### activated
Required: `false`
Parameters: `-`
Called whenever the component gets clicked, in order to show handles.
```html
```
#### deactivated
Required: `false`
Parameters: `-`
Called whenever the user clicks anywhere outside the component, in order to deactivate it.
```html
```
#### resizing
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```
Called whenever the component gets resized.
```html
```
#### resizestop
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```
Called whenever the component stops getting resized.
```html
```
#### dragging
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```
Called whenever the component gets dragged.
```html
```
#### dragstop
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```
Called whenever the component stops getting dragged.
```html
```
## Contributing
Any contribution to the code or any part of the documentation and any idea and/or suggestion are very welcome.
``` bash
# serve with hot reload at localhost:8081
npm run start
# distribution build
npm run build
```
## License
[MIT license](LICENSE)