Skip to content

Commit

Permalink
Make Draggable ready to process children functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Aug 30, 2018
1 parent 02a728b commit e804f80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
17 changes: 12 additions & 5 deletions packages/components/src/draggable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class Draggable extends Component {
constructor() {
super( ...arguments );

deprecated( 'wp.components.Draggable', {
version: 3.7,
alternative: 'wp.components.withDraggable',
} );

this.onDragStart = this.onDragStart.bind( this );
this.onDragOver = this.onDragOver.bind( this );
this.onDragEnd = this.onDragEnd.bind( this );
Expand Down Expand Up @@ -154,6 +149,18 @@ class Draggable extends Component {

render() {
const { children, className } = this.props;
if ( typeof children === 'function' ) {
return children( {
onDraggableStart: this.onDragStart,
onDraggableEnd: this.onDragEnd,
} );
}

deprecated( 'wp.components.Draggable as a DOM node drag handle', {
version: 3.8,
alternative: 'wp.components.Draggable as a wrapper component for a DOM node',
} );

return (
<div
className={ classnames( 'components-draggable', className ) }
Expand Down
26 changes: 18 additions & 8 deletions packages/editor/src/components/block-list/block-draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,36 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { withDraggable } from '@wordpress/components';
import { Draggable } from '@wordpress/components';

class BlockDraggable extends Component {
render() {
const { isDragging, onDragStart, onDragEnd } = this.props;
const { isDragging, elementId, transferData, onDragStart, onDragEnd } = this.props;
const className = classnames( 'editor-block-list__block-draggable', {
'is-visible': isDragging,
} );

return (
<div
className={ className }
<Draggable
elementId={ elementId }
transferData={ transferData }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
draggable
>
<div className="editor-block-list__block-draggable-inner"></div>
</div>
{
( { onDraggableStart, onDraggableEnd } ) => (
<div
className={ className }
onDragStart={ onDraggableStart }
onDragEnd={ onDraggableEnd }
draggable
>
<div className="editor-block-list__block-draggable-inner"></div>
</div> )
}
</Draggable>
);
}
}

export default withDraggable( BlockDraggable );
export default BlockDraggable;

0 comments on commit e804f80

Please sign in to comment.