Skip to content

Commit c15afa1

Browse files
committed
Updating example
1 parent 319106f commit c15afa1

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
display: block;
2020
margin-bottom: 10px;
2121
padding: 3px 5px;
22+
text-align: center;
2223
}
2324

2425
.box {

example/main.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@ var React = require('react'),
33
Draggable = require('../lib/main');
44

55
var App = React.createClass({
6+
getInitialState: function () {
7+
return {
8+
position: {
9+
top: 0, left: 0
10+
}
11+
};
12+
},
13+
614
handleStart: function (e, ui) {
7-
console.log('start');
815
},
916

1017
handleDrag: function (e, ui) {
11-
console.log('drag');
18+
this.setState({
19+
position: ui.position
20+
});
1221
},
1322

14-
handleStop: function () {
15-
console.log('stop');
23+
handleStop: function (e, ui) {
1624
},
1725

1826
render: function () {
@@ -22,44 +30,31 @@ var App = React.createClass({
2230
<p>
2331
<a href="https://github.com/mzabriskie/react-draggable/blob/master/example/main.js">Demo Source</a>
2432
</p>
25-
<Draggable
26-
onStart={this.handleStart}
27-
onDrag={this.handleDrag}
28-
onStop={this.handleStop}>
33+
<Draggable>
2934
<div className="box">I can be dragged anywhere</div>
3035
</Draggable>
31-
<Draggable
32-
axis='x'
33-
onStart={this.handleStart}
34-
onDrag={this.handleDrag}
35-
onStop={this.handleStop}>
36+
<Draggable axis="x">
3637
<div className="box">I can only be dragged horizonally</div>
3738
</Draggable>
38-
<Draggable
39-
axis='y'
40-
onStart={this.handleStart}
41-
onDrag={this.handleDrag}
42-
onStop={this.handleStop}>
39+
<Draggable axis="y">
4340
<div className="box">I can only be dragged vertically</div>
4441
</Draggable>
45-
<Draggable
46-
handle="strong"
47-
onStart={this.handleStart}
48-
onDrag={this.handleDrag}
49-
onStop={this.handleStop}>
42+
<Draggable onDrag={this.handleDrag}>
43+
<div className="box">
44+
<div>I track my position</div>
45+
<div>top: {this.state.position.top}, left: {this.state.position.left}</div>
46+
</div>
47+
</Draggable>
48+
<Draggable handle="strong">
5049
<div className="box">
51-
<strong>Handle</strong>
50+
<strong>Drag here</strong>
5251
<div>You must click my handle to drag me</div>
5352
</div>
5453
</Draggable>
55-
<Draggable
56-
cancel="strong"
57-
onStart={this.handleStart}
58-
onDrag={this.handleDrag}
59-
onStop={this.handleStop}>
54+
<Draggable cancel="strong">
6055
<div className="box">
61-
<strong>Can't drag from here</strong>
62-
<div>Dragging from here works fine</div>
56+
<strong>Can't drag here</strong>
57+
<div>Dragging here works</div>
6358
</div>
6459
</Draggable>
6560
</div>

0 commit comments

Comments
 (0)