0.0.4 • Published 4 years ago

@dragndrop/vue-draggable v0.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Draggable

Draggable component for VueJS 2+ which implements @dragndrop/draggable component.

Design & API Documentation

Installation

npm install @dragndrop/vue-draggable

Usage

Draggable element can be used for different functionalities - from moving elements around to make sortable list or draggable grid elements.

Typescript support

Component has its declarations (*.d.ts) for Typescript available.

Registration

import {VueDraggable} from '@dragndrop/vue-draggable';

Vue.component('VueDraggable', VueDraggable);

Registration as plugin

import Vue from 'vue';
import VueDraggable from '@dragndrop/vue-draggable';

Vue.use(VueDraggable);

Simple example

<template>
    <VueDraggable 
        :data="dataTransfer"
        :avatar="avatar"
        @onDrag="onDrag"
    >
        <div>Example element</div>
    </VueDraggable>
</template>
<script>
    export default {
        data() {
            return {
                dataTransfer: 'example data',
                avatar: new Avatar.clone(),
            }
        },
        methods: {
            onDrag(event) {
                console.log(event.dragInfo.data); // 'example data'
            }
        }
    }
</script>

CSS Classes (they can be changed)

CSS ClassDescription
draggable--draggingSets this class to element when dragging
draggable--occurringSets this class to body element when dragging

Shadow DOM

If you want to use dragndrop in Shadow DOM you need to add draggable--retarget attribute to your host element so events will be bubble through Shoadow DOM and recursive elementFromPoint() calls will work correctly.

Events

EventsTypeDataDescription
onDragStartCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging starts
onDragCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging
onDragEndCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging ends

DragInfo

DragInfoTypeDescription
draggableIdNumberId of draggable element
elementElementDraggable element
dataType GenericData attached to draggable with data property
startPositionPointStart position
avatarAvatarAvatar attached to draggable with avatar property
axisAxisAxis which dragging is handled 'horizontal', 'vertical' and 'both'
positionPointCurrent position of cursor
shiftPointDistance from start position to elements top-left corner

Props

PropertyValue TypeDescription
dataGeneric TypeData which is attached to draggable
draggableBooleanTurn on / off draggable functionality
avatarAvatarElement which is rendered when element is dragging
axisAxis ('both', 'horizontal', 'vertical')Axis the dragging is available for
handleStringSelector on which dragging is available (children of element are included)
cancelStringSelectors on which draggins is not available (children of element are included)
draggingClassStringClass which is set on element when dragging (draggable--dragging default)
draggingClassBodyStringClass which is set on body element when dragging (draggable--occurring default)
minDragStartDistancenumberMin distance to start dragStart state (4 default)
touchActionString or nullMakes touch-action property set on element when drag is started (undefined default)
customScroll((startPosition: Point, currentPosition: Point) => void) or booleanAllows to specify customScroll behavior with function or when set with false prevents from custom scroll which is set by default

Methods

Method SignatureDescription
abort() => voidAborts current dragging
destroy() => voidClean up method. Is used on beforeDestroy hook.