Skip to content

Commit 8a2deb7

Browse files
committed
README rework
1 parent cb1bf12 commit 8a2deb7

File tree

1 file changed

+76
-58
lines changed

1 file changed

+76
-58
lines changed

README.md

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
# React-Draggable [![Build Status](https://travis-ci.org/mzabriskie/react-draggable.svg?branch=master)](https://travis-ci.org/mzabriskie/react-draggable)
1+
# React-Draggable [![Build Status](https://travis-ci.org/mzabriskie/react-draggable.svg?branch=master)](https://travis-ci.org/mzabriskie/react-draggable) [![npm downloads](https://img.shields.io/npm/dt/react-draggable.svg?maxAge=2592000)]()
22

33
A simple component for making elements draggable.
44

5-
[View the Changelog](CHANGELOG.md)
5+
```js
6+
<Draggable>
7+
<div>I can now be moved around!</div>
8+
</Draggable>
9+
```
10+
11+
- [Demo](http://mzabriskie.github.io/react-draggable/example/)
12+
- [Changelog](CHANGELOG.md)
613

7-
### Demo
14+
------
15+
16+
#### Technical Documentation
17+
18+
- [Installing](#installing)
19+
- [Exports](#exports)
20+
- [Draggable](#draggable)
21+
- [Draggable Usage](#draggable-usage)
22+
- [Draggable API](#draggable-api)
23+
- [Controlled vs. Uncontrolled](#controlled-vs-uncontrolled)
24+
- [DraggableCore](#draggablecore)
25+
- [DraggableCore API](#draggablecore-api)
826

9-
[View Demo](http://mzabriskie.github.io/react-draggable/example/)
1027

1128

1229
### Installing
@@ -49,25 +66,69 @@ positioning (relative, absolute, or static). Elements can also be moved between
4966
If the item you are dragging already has a CSS Transform applied, it will be overwritten by `<Draggable>`. Use
5067
an intermediate wrapper (`<Draggable><span>...</span></Draggable>`) in this case.
5168

69+
### Draggable Usage
70+
71+
View the [Demo](http://mzabriskie.github.io/react-draggable/example/) and its
72+
[source](/example/index.html) for more.
73+
74+
```js
75+
import React from 'react');
76+
import ReactDOM from 'react-dom';
77+
import Draggable from 'react-draggable';
78+
79+
class App extends React.Element {
80+
81+
eventLogger = (e: MouseEvent, data: Object) => {
82+
console.log('Event: ', event);
83+
console.log('Data: ', data);
84+
};
85+
86+
render() {
87+
return (
88+
<Draggable
89+
axis="x"
90+
handle=".handle"
91+
defaultPosition={{x: 0, y: 0}}
92+
position={null}
93+
grid={[25, 25]}
94+
zIndex={100}
95+
onStart={this.handleStart}
96+
onDrag={this.handleDrag}
97+
onStop={this.handleStop}>
98+
<div>
99+
<div className="handle">Drag from here</div>
100+
<div>This readme is really dragging on...</div>
101+
</div>
102+
</Draggable>
103+
);
104+
}
105+
}
106+
107+
ReactDOM.render(<App/>, document.body);
108+
```
52109

53110
### Draggable API
54111

55-
The `<Draggable/>` component transparently adds draggable to whatever element is supplied as `this.props.children`.
56-
**Note**: Only a single element is allowed or an Error will be thrown.
112+
The `<Draggable/>` component transparently adds draggability to its children.
113+
114+
**Note**: Only a single child is allowed or an Error will be thrown.
57115

58116
For the `<Draggable/>` component to correctly attach itself to its child, the child element must provide support
59117
for the following props:
60118
- `style` is used to give the transform css to the child.
61119
- `className` is used to apply the proper classes to the object being dragged.
62120
- `onMouseDown`, `onMouseUp`, `onTouchStart`, and `onTouchEnd` are used to keep track of dragging state.
63121

64-
React.DOM elements support the above six properties by default, so you may use those elements as children without
65-
any changes. If you wish to use a React component you created, you might find
66-
[this React page](https://facebook.github.io/react/docs/transferring-props.html) helpful.
122+
React.DOM elements support the above properties by default, so you may use those elements as children without
123+
any changes. If you wish to use a React component you created, you'll need to be sure to
124+
[transfer prop](https://facebook.github.io/react/docs/transferring-props.html).
67125

68-
Props:
126+
#### `<Draggable>` Props:
69127

70128
```js
129+
//
130+
// Types:
131+
//
71132
type DraggableEventHandler = (e: Event, data: DraggableData) => void | false;
72133
type DraggableData = {
73134
node: HTMLElement,
@@ -76,6 +137,10 @@ type DraggableData = {
76137
deltaX: number, deltaY: number,
77138
lastX: number, lastY: number
78139
};
140+
141+
//
142+
// Props:
143+
//
79144
{
80145
// If set to `true`, will allow dragging on non left-button clicks.
81146
allowAnyClick: boolean,
@@ -119,7 +184,7 @@ handle: string,
119184

120185
// Called whenever the user mouses down. Called regardless of handle or
121186
// disabled status.
122-
onMouseDown: (e: MouseEvent) => boolean,
187+
onMouseDown: (e: MouseEvent) => void,
123188

124189
// Called when dragging starts. If `false` is returned any handler,
125190
// the action will cancel.
@@ -143,53 +208,6 @@ Note that sending `className`, `style`, or `transform` as properties will error
143208
directly.
144209

145210

146-
### Draggable Usage
147-
148-
```js
149-
var React = require('react'),;
150-
var ReactDOM = require('react-dom');
151-
var Draggable = require('react-draggable');
152-
153-
var App = React.createClass({
154-
handleStart: function (event, ui) {
155-
console.log('Event: ', event);
156-
console.log('Position: ', ui.position);
157-
},
158-
159-
handleDrag: function (event, ui) {
160-
console.log('Event: ', event);
161-
console.log('Position: ', ui.position);
162-
},
163-
164-
handleStop: function (event, ui) {
165-
console.log('Event: ', event);
166-
console.log('Position: ', ui.position);
167-
},
168-
169-
render: function () {
170-
return (
171-
<Draggable
172-
axis="x"
173-
handle=".handle"
174-
defaultPosition={{x: 0, y: 0}}
175-
position={null}
176-
grid={[25, 25]}
177-
zIndex={100}
178-
onStart={this.handleStart}
179-
onDrag={this.handleDrag}
180-
onStop={this.handleStop}>
181-
<div>
182-
<div className="handle">Drag from here</div>
183-
<div>This readme is really dragging on...</div>
184-
</div>
185-
</Draggable>
186-
);
187-
}
188-
});
189-
190-
ReactDOM.render(<App/>, document.body);
191-
```
192-
193211
## Controlled vs. Uncontrolled
194212

195213
`<Draggable>` is a 'batteries-included' component that manages its own state. If you want to completely

0 commit comments

Comments
 (0)