Skip to content

Commit 90b7bbe

Browse files
committed
Add onDragStart and onDragEnd props
1 parent 609cda0 commit 90b7bbe

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ Calls back with (`id: number or string`, `direction: string`)
152152

153153
#### `onResize`: PropTypes.func
154154

155-
Calls when Pane component resize.
156-
Calls back with (`id: number or string`, `direction: string`, `coputedSize: object`, `clientSize: object`)
155+
Calls when Pane component resizes.
156+
Calls back with (`id: number or string`, `direction: string`, `computedSize: object`, `clientSize: object`)
157157

158158
- id: pane id
159159
- direction: `x` or `y` or `xy`
@@ -166,8 +166,8 @@ For example, when `<Resizable width={100} height={200} style={{ padding: '20px'}
166166

167167
#### `onResizeStop`: PropTypes.func
168168

169-
Calls when Pane component resizeStop.
170-
Calls back with (`id: number or string`, `direction: string`, `coputedSize: object`, `clientSize: object`)
169+
Calls when Pane component resize stops.
170+
Calls back with (`id: number or string`, `direction: string`, `computedSize: object`, `clientSize: object`)
171171

172172
- id: pane id
173173
- direction: `x` or `y` or `xy`
@@ -178,6 +178,20 @@ Calls back with (`id: number or string`, `direction: string`, `coputedSize: obje
178178

179179
For example, when `<Resizable width={100} height={200} style={{ padding: '20px'}} onResize={...} />` mounted and resize 'x', this callback is called with `('x', { width: 100, height: 200 }, { width: 140, height: 240 })`
180180

181+
#### `onDragStart`: PropTypes.function
182+
183+
Calls when a Pane component is clicked (e.g. to sort it). It will not be executed if `isSortable` is `false`.
184+
Calls back with (`id: number or string`)
185+
186+
- id: pane id
187+
188+
#### `onDragEnd`: PropTypes.function
189+
190+
Calls when a Pane component is released (finished sorting). It will not be executed if `isSortable` is `false`.
191+
Calls back with (`id: number or string`)
192+
193+
- id: pane id
194+
181195
## Pane Component
182196

183197
#### `id`: PropTypes.oneOfType([PropTypes.string, PropTypes.number ]).isRequired
@@ -210,6 +224,16 @@ The `maxWidth` property is used to set the maximum width of a Pane component.
210224

211225
The `maxHeight` property is used to set the maximum height of a Pane component.
212226

227+
#### `onDragStart`: PropTypes.function
228+
229+
If provided, an `onDragStart` function will be executed when the mouse is pressed
230+
down on the pane to drag it. It will not be executed if `isSortable` is `false`.
231+
232+
#### `onDragEnd`: PropTypes.function
233+
234+
If provided, an `onDragEnd` function will be executed when the mouse is released
235+
after clicking a pane. It will not be executed if `isSortable` is `false`.
236+
213237
#### `className`: PropTypes.string
214238

215239
The `className` property is used to set the css class name of a Pane component.

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class SortablePane extends Component {
2626
onResizeStart: PropTypes.func,
2727
onResize: PropTypes.func,
2828
onResizeStop: PropTypes.func,
29-
disableEffect: PropTypes.bool,
29+
onDragStart: PropTypes.func,
30+
onDragEnd: PropTypes.func,
3031
onOrderChange: PropTypes.func,
3132
className: PropTypes.string,
33+
disableEffect: PropTypes.bool,
3234
isResizable: PropTypes.shape({
3335
x: React.PropTypes.bool,
3436
y: React.PropTypes.bool,
@@ -46,6 +48,8 @@ class SortablePane extends Component {
4648
onResizeStart: () => null,
4749
onResize: () => null,
4850
onResizeStop: () => null,
51+
onDragStart: () => null,
52+
onDragEnd: () => null,
4953
onOrderChange: () => null,
5054
customStyle: {},
5155
className: '',
@@ -310,6 +314,8 @@ class SortablePane extends Component {
310314
isPressed: true,
311315
lastPressed: pos,
312316
});
317+
this.props.children[pos].props.onDragStart();
318+
this.props.onDragStart(pos);
313319
}
314320

315321
handleMouseMove({ pageX, pageY }) {
@@ -338,6 +344,8 @@ class SortablePane extends Component {
338344

339345
handleMouseUp() {
340346
this.setState({ isPressed: false, delta: 0 });
347+
this.props.children[this.state.lastPressed].props.onDragEnd();
348+
this.props.onDragEnd(this.state.lastPressed);
341349
}
342350

343351
renderPanes() {

src/pane.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ export default class Pane extends Component {
1818
maxWidth: PropTypes.number,
1919
minHeight: PropTypes.number,
2020
maxHeight: PropTypes.number,
21+
onDragStart: PropTypes.func,
22+
onDragEnd: PropTypes.func,
2123
style: PropTypes.object,
2224
className: PropTypes.string,
2325
children: PropTypes.any,
2426
};
2527

2628
static defaultProps = {
29+
onDragStart: () => null,
30+
onDragEnd: () => null,
2731
style: {},
2832
className: '',
2933
};

0 commit comments

Comments
 (0)