@@ -67,46 +67,15 @@ React.DOM elements support the above six properties by default, so you may use t
67
67
Props:
68
68
69
69
``` js
70
+ type DraggableEventHandler = (e : Event , data : DraggableData ) => void | false ;
71
+ type DraggableData = {
72
+ node: HTMLElement ,
73
+ // lastX + deltaX === x
74
+ x: number, y: number,
75
+ deltaX: number, deltaY: number,
76
+ lastX: number, lastY: number
77
+ };
70
78
{
71
- // Called when dragging starts. If `false` is returned from this method,
72
- // dragging will cancel.
73
- // These callbacks are called with the arity:
74
- // (event: Event,
75
- // {
76
- // position: {left: number, top: number},
77
- // deltaX: number,
78
- // deltaY: number
79
- // }
80
- // )
81
- onStart: Function ,
82
-
83
- // Called while dragging.
84
- onDrag: Function ,
85
-
86
- // Called when dragging stops.
87
- onStop: Function ,
88
-
89
- // Called whenever the user mouses down. Called regardless of handle or
90
- // disabled status.
91
- onMouseDown: Function ,
92
-
93
- // Specifies the `x` and `y` that the dragged item should start at.
94
- // This is generally not necessary to use (you can use absolute or relative
95
- // positioning of the child directly), but can be helpful for uniformity in
96
- // your callbacks and with css transforms.
97
- start: {x: number, y: number},
98
-
99
- // If true, will not call any drag handlers.
100
- disabled: boolean,
101
-
102
- // Specifies a selector to be used to prevent drag initialization.
103
- // Example: '.body'
104
- cancel: string,
105
-
106
- // Specifies a selector to be used as the handle that initiates drag.
107
- // Example: '.handle'
108
- handle: string,
109
-
110
79
// If set to `true`, will allow dragging on non left-button clicks.
111
80
allowAnyClick: boolean,
112
81
@@ -127,11 +96,44 @@ axis: string,
127
96
// can be moved.
128
97
bounds: {left: number, top: number, right: number, bottom: number} | string,
129
98
99
+ // Specifies a selector to be used to prevent drag initialization.
100
+ // Example: '.body'
101
+ cancel: string,
102
+
103
+ // Specifies the `x` and `y` that the dragged item should start at.
104
+ // This is generally not necessary to use (you can use absolute or relative
105
+ // positioning of the child directly), but can be helpful for uniformity in
106
+ // your callbacks and with css transforms.
107
+ defaultPosition: {x: number, y: number},
108
+
109
+ // If true, will not call any drag handlers.
110
+ disabled: boolean,
111
+
130
112
// Specifies the x and y that dragging should snap to.
131
113
grid: [number, number],
132
114
133
- // Specifies the zIndex to use while dragging.
134
- zIndex: number
115
+ // Specifies a selector to be used as the handle that initiates drag.
116
+ // Example: '.handle'
117
+ handle: string,
118
+
119
+ // Called whenever the user mouses down. Called regardless of handle or
120
+ // disabled status.
121
+ onMouseDown : (e : MouseEvent ) => boolean,
122
+
123
+ // Called when dragging starts. If `false` is returned any handler,
124
+ // the action will cancel.
125
+ onStart: DraggableEventHandler,
126
+
127
+ // Called while dragging.
128
+ onDrag: DraggableEventHandler,
129
+
130
+ // Called when dragging stops.
131
+ onStop: DraggableEventHandler,
132
+
133
+ // Much like React form elements, if this property is present, the item
134
+ // becomes 'controlled' and is not responsive to user input. Use `position`
135
+ // if you need to have direct control of the element.
136
+ position: {x: number, y: number}
135
137
}
136
138
```
137
139
@@ -168,7 +170,8 @@ var App = React.createClass({
168
170
< Draggable
169
171
axis= " x"
170
172
handle= " .handle"
171
- start= {{x: 0 , y: 0 }}
173
+ defaultPosition= {{x: 0 , y: 0 }}
174
+ position= {null }
172
175
grid= {[25 , 25 ]}
173
176
zIndex= {100 }
174
177
onStart= {this .handleStart }
@@ -198,28 +201,39 @@ on itself.
198
201
199
202
### DraggableCore API
200
203
201
- ` <DraggableCore> ` takes all of the above ` <Draggable> ` options, with the exception of:
204
+ ` <DraggableCore> ` takes a limited subset of options:
205
+
206
+ ``` js
207
+ {
208
+ allowAnyClick: boolean,
209
+ cancel: string,
210
+ disabled: boolean,
211
+ enableUserSelectHack: boolean,
212
+ grid: [number, number],
213
+ handle: string,
214
+ onStart: DraggableEventHandler,
215
+ onDrag: DraggableEventHandler,
216
+ onStop: DraggableEventHandler
217
+ onMouseDown : (e : MouseEvent ) => void
218
+ }
219
+ ```
202
220
203
- * ` axis `
204
- * ` bounds `
205
- * ` start `
206
- * ` zIndex `
221
+ Note that there is no start position. ` <DraggableCore> ` simply calls ` drag ` handlers with the below parameters,
222
+ indicating its position (as inferred from the underlying MouseEvent) and deltas. It is up to the parent
223
+ to set actual positions on ` <DraggableCore> ` .
207
224
208
- Drag callbacks are called with the following parameters:
225
+ Drag callbacks ( ` onDragStart ` , ` onDrag ` , ` onDragEnd ` ) are called with the following parameters:
209
226
210
227
``` js
211
228
(
212
- event : Event ,
213
- ui: {
214
- node: Node
215
- position:
216
- {
217
- // lastX + deltaX === clientX
218
- deltaX: number, deltaY: number,
219
- lastX: number, lastY: number,
220
- clientX: number, clientY: number
221
- }
222
- }
229
+ event : Event ,
230
+ data: {
231
+ node: HTMLElement ,
232
+ // lastX + deltaX === x
233
+ x: number, y: number,
234
+ deltaX: number, deltaY: number,
235
+ lastX: number, lastY: number
236
+ }
223
237
)
224
238
```
225
239
0 commit comments