-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTarget.js
61 lines (53 loc) · 1.28 KB
/
Target.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react';
import PropTypes from 'prop-types';
export default class Target extends React.Component {
static className = 'react-nested-popper_Target';
/* tracks ref so popperjs can be bound to it. Also provide to user if they want it.
We wouldn't even need this component, but we need to guarantee a ref to the target,
so we enforce this component.
*/
setRef(el) {
const { innerRef, _targetRef } = this.props;
if (innerRef) {
innerRef(el);
}
if (_targetRef) {
_targetRef(el);
}
}
render() {
const {
children,
className,
_onClick,
innerRef,
_targetRef,
...rest
} = this.props;
return (
<div
className={className}
ref={el => this.setRef(el)}
onClick={_onClick}
{...rest}
>
{children}
</div>
);
}
}
// see docs for definitions of each external prop here
Target.propTypes = {
// external props
className: PropTypes.string,
innerRef: PropTypes.func,
// internal props - these can't be required unless you want it to show to end user
_onClick: PropTypes.func,
_targetRef: PropTypes.func,
};
Target.defaultProps = {
className: '',
innerRef: (el) => {},
_onClick: (e) => {},
_targetRef: (el) => {},
};