6.0.0 • Published 7 years ago
react-draggable-component v6.0.0
react-draggable-component
A wrapper React component that adds draggable functionality to an element using transform3d. Works with touch devices.
to install
npm i react-draggable-componentto run demo
npm startor
yarn startThen navigate to http://localhost:3000/demo.html
to run tests
npm testor
yarn testto build
npm run buildor
yarn run buildrequirements
react
prop-types
usage
import React from 'react';
import Draggable from 'react-draggable-component';
<Draggable>
<div className='draggable-content'>DRAG</div>
</Draggable>props
additionalClass {String} // A string of additional classnames to add to the elementbounds {Object} // An array of coordinates, forming a square, that the user cannot drag the component outside of, in the format {x1: Number, y1: Number, x2: Number, y2: Number}contentPosition {String} // The css positioning for for the element (i.e. 'absolute' or 'fixed', defaults to 'absolute')disabled {Boolean} // If the component is disableddragCallback {Function} // A callback function while the user is draggingdragStartCallback {Function} // A callback function for when the user starts draggingdragStopCallback {Function} // A callback function for when the user stops draggingdragLeaveCallback {Function} // A callback function for when the user is dragging and the mouse/touch leaves the draggable componentlock {String} // An axis to lock element to when dragging, either 'x' or 'y'position {Object} // An object with x and y values for the contentpreventDefaultEvents {Boolean} // Whether to prevent default mouse/touch eventstouchScrollLock {String} // If set to true, prevents the content from being dragged if the user is scrolling in the opposite direction on a touch device