-
Notifications
You must be signed in to change notification settings - Fork 981
/
index.js
39 lines (31 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as React from 'react';
import {findDOMNode} from 'react-dom';
import invariant from 'invariant';
import {provideDisplayName} from '../utils';
export default function sortableHandle(
WrappedComponent,
config = {withRef: false},
) {
return class WithSortableHandle extends React.Component {
static displayName = provideDisplayName('sortableHandle', WrappedComponent);
componentDidMount() {
const node = findDOMNode(this);
node.sortableHandle = true;
}
getWrappedInstance() {
invariant(
config.withRef,
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call',
);
return this.wrappedInstance.current;
}
wrappedInstance = React.createRef();
render() {
const ref = config.withRef ? this.wrappedInstance : null;
return <WrappedComponent ref={ref} {...this.props} />;
}
};
}
export function isSortableHandle(node) {
return node.sortableHandle != null;
}