0.1.6 • Published 4 years ago

@dragndrop/draggable v0.1.6

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

Draggable

Draggable uses the JavaScript to provide draggable functionality to HTML elements.

Design & API Documentation

Installation

npm install @dragndrop/draggable

Usage

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

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.

Draggable

The Draggable JavaScript component allows for programmatic turn on / off the draggabillity to element.

const draggableElement = document.querySelector('.draggable');
const draggable = new Draggable(draggableElement);

You can also use attachTo() as an alias;

Draggable.attachTo(document.querySelector('.draggable'));
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
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
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
Method SignatureDescription
abort() => voidProxies to the foundation's abort method
destroy() => voidProxies to the foundation's destroy method

DraggableFoundation

Method SignatureDescription
abort() => voidAbort current draggable.
destroy() => voidDestroy all event listeners and clean up component.