1+ import React , { Component } from 'react' ;
2+ import ReactDOM from 'react-dom'
3+ import PropTypes from 'prop-types' ;
4+ import container from 'smooth-dnd' ;
5+ import { dropHandlers } from 'smooth-dnd' ;
6+ import Draggable from './Draggable' ;
7+
8+ container . dropHandler = dropHandlers . reactDropHandler ( ) . handler ;
9+ container . wrapChild = p => p ; // dont wrap children they will already be wrapped
10+
11+ class Container extends Component {
12+ constructor ( props ) {
13+ super ( props ) ;
14+ this . getContainerOptions = this . getContainerOptions . bind ( this ) ;
15+ this . setRef = this . setRef . bind ( this ) ;
16+ this . prevContainer = null ;
17+ }
18+
19+ componentDidMount ( ) {
20+ this . containerDiv = this . containerDiv || ReactDOM . findDOMNode ( this ) ;
21+ this . prevContainer = this . containerDiv ;
22+ this . container = container ( this . containerDiv , this . getContainerOptions ( this . props ) ) ;
23+ }
24+
25+ componentWillUnmount ( ) {
26+ this . container . dispose ( ) ;
27+ this . container = null ;
28+ }
29+
30+ componentDidUpdate ( ) {
31+ this . containerDiv = this . containerDiv || ReactDOM . findDOMNode ( this ) ;
32+ if ( this . containerDiv ) {
33+ if ( this . prevContainer && this . prevContainer !== this . containerDiv ) {
34+ this . container . dispose ( ) ;
35+ this . container = container ( this . containerDiv , this . getContainerOptions ( this . props ) ) ;
36+ this . prevContainer = this . containerDiv ;
37+ }
38+ }
39+ }
40+
41+ render ( ) {
42+ if ( this . props . render ) {
43+ return this . props . render ( this . setRef ) ;
44+ } else {
45+ return (
46+ < div style = { this . props . style } ref = { this . setRef } >
47+ { this . props . children }
48+ </ div >
49+ ) ;
50+ }
51+ }
52+
53+ setRef ( element ) {
54+ this . containerDiv = element ;
55+ }
56+
57+ getContainerOptions ( props ) {
58+ return Object . assign ( { } , props ) ;
59+ }
60+ }
61+
62+ Container . propTypes = {
63+ behaviour : PropTypes . oneOf ( [ "move" , "copy" , "drag-zone" ] ) ,
64+ groupName : PropTypes . string ,
65+ orientation : PropTypes . oneOf ( [ "horizontal" , "vertical" ] ) ,
66+ style : PropTypes . object ,
67+ dragHandleSelector : PropTypes . string ,
68+ nonDragAreaSelector : PropTypes . string ,
69+ dragBeginDelay : PropTypes . number ,
70+ animationDuration : PropTypes . number ,
71+ autoScrollEnabled : PropTypes . string ,
72+ lockAxis : PropTypes . string ,
73+ dragClass : PropTypes . string ,
74+ dropClass : PropTypes . string ,
75+ onDragStart : PropTypes . func ,
76+ onDragEnd : PropTypes . func ,
77+ onDrop : PropTypes . func ,
78+ getChildPayload : PropTypes . func ,
79+ shouldAnimateDrop : PropTypes . func ,
80+ shouldAcceptDrop : PropTypes . func ,
81+ onDragEnter : PropTypes . func ,
82+ onDragLeave : PropTypes . func ,
83+ render : PropTypes . func
84+ } ;
85+
86+ Container . defaultProps = {
87+ behaviour : 'move' ,
88+ orientation : 'vertical'
89+ } ;
90+
91+ export default Container ;
0 commit comments