@@ -67,46 +67,15 @@ React.DOM elements support the above six properties by default, so you may use t
6767Props:
6868
6969``` 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+ };
7078{
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-
11079// If set to `true`, will allow dragging on non left-button clicks.
11180allowAnyClick: boolean,
11281
@@ -127,11 +96,44 @@ axis: string,
12796// can be moved.
12897bounds: {left: number, top: number, right: number, bottom: number} | string,
12998
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+
130112// Specifies the x and y that dragging should snap to.
131113grid: [number, number],
132114
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}
135137}
136138```
137139
@@ -168,7 +170,8 @@ var App = React.createClass({
168170 < Draggable
169171 axis= " x"
170172 handle= " .handle"
171- start= {{x: 0 , y: 0 }}
173+ defaultPosition= {{x: 0 , y: 0 }}
174+ position= {null }
172175 grid= {[25 , 25 ]}
173176 zIndex= {100 }
174177 onStart= {this .handleStart }
@@ -198,28 +201,39 @@ on itself.
198201
199202### DraggableCore API
200203
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+ ```
202220
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> ` .
207224
208- Drag callbacks are called with the following parameters:
225+ Drag callbacks ( ` onDragStart ` , ` onDrag ` , ` onDragEnd ` ) are called with the following parameters:
209226
210227``` js
211228(
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+ }
223237)
224238```
225239
0 commit comments