|
1 | 1 | # react-draggable
|
2 | 2 |
|
3 | 3 | React draggable component
|
| 4 | + |
| 5 | +## Installing |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install react-draggable |
| 9 | +``` |
| 10 | + |
| 11 | +## Demo |
| 12 | + |
| 13 | +http://mzabriskie.github.io/react-draggable/example/ |
| 14 | + |
| 15 | +## Example |
| 16 | + |
| 17 | +```js |
| 18 | +/** @jsx React.DOM */ |
| 19 | +var React = require('react'), |
| 20 | + Draggable = require('react-draggable'); |
| 21 | + |
| 22 | +var App = React.createClass({ |
| 23 | + handleStart: function (event, ui) { |
| 24 | + console.log('Event: ', event); |
| 25 | + console.log('Position: ', ui.position); |
| 26 | + }, |
| 27 | + |
| 28 | + handleDrag: function (event, ui) { |
| 29 | + console.log('Event: ', event); |
| 30 | + console.log('Position: ', ui.position); |
| 31 | + }, |
| 32 | + |
| 33 | + handleStop: function (event, ui) { |
| 34 | + console.log('Event: ', event); |
| 35 | + console.log('Position: ', ui.position); |
| 36 | + }, |
| 37 | + |
| 38 | + render: function () { |
| 39 | + return ( |
| 40 | + // <Draggable/> transparently adds draggable interactivity |
| 41 | + // to whatever element is supplied as `this.props.children`. |
| 42 | + // Only a single element is allowed or an Error will be thrown. |
| 43 | + // |
| 44 | + // `axis` determines which axis the draggable can move. |
| 45 | + // - 'both' allows movement horizontally and vertically (default). |
| 46 | + // - 'x' limits movement to horizontal axis. |
| 47 | + // - 'y' limits movement to vertical axis. |
| 48 | + // |
| 49 | + // `handle` specifies a selector to be used as the handle that initiates drag. |
| 50 | + // |
| 51 | + // `cancel` specifies a selector to be used to prevent drag initialization. |
| 52 | + // |
| 53 | + // `zIndex` specifies the zIndex to use while dragging. |
| 54 | + // |
| 55 | + // `onStart` is called when dragging starts. |
| 56 | + // |
| 57 | + // `onDrag` is called while dragging. |
| 58 | + // |
| 59 | + // `onStop` is called when dragging stops. |
| 60 | + |
| 61 | + <Draggable |
| 62 | + axis="x" |
| 63 | + handle=".handle" |
| 64 | + zIndex={100} |
| 65 | + onStart={this.handleStart} |
| 66 | + onDrag={this.handleDrag} |
| 67 | + onStop={this.handleStop}> |
| 68 | + <div> |
| 69 | + <div className="handle">Drag from here</div> |
| 70 | + <div>Lorem ipsum...</div> |
| 71 | + </div> |
| 72 | + </Draggable> |
| 73 | + ); |
| 74 | + } |
| 75 | +}); |
| 76 | + |
| 77 | +React.renderComponent(<App/>, document.body); |
| 78 | +``` |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +MIT |
0 commit comments