forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTooltip.js
More file actions
106 lines (91 loc) · 2.31 KB
/
Copy pathTooltip.js
File metadata and controls
106 lines (91 loc) · 2.31 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import classNames from 'classnames';
import React from 'react';
import isRequiredForA11y from 'react-prop-types/lib/isRequiredForA11y';
import { bsClass, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
const propTypes = {
/**
* An html id attribute, necessary for accessibility
* @type {string|number}
* @required
*/
id: isRequiredForA11y(React.PropTypes.oneOfType([
React.PropTypes.string, React.PropTypes.number,
])),
/**
* Sets the direction the Tooltip is positioned towards.
*/
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
/**
* The "top" position value for the Tooltip.
*/
positionTop: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string,
]),
/**
* The "left" position value for the Tooltip.
*/
positionLeft: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string,
]),
/**
* The "top" position value for the Tooltip arrow.
*/
arrowOffsetTop: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string,
]),
/**
* The "left" position value for the Tooltip arrow.
*/
arrowOffsetLeft: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string,
]),
};
const defaultProps = {
placement: 'right',
};
class Tooltip extends React.Component {
render() {
const {
placement,
positionTop,
positionLeft,
arrowOffsetTop,
arrowOffsetLeft,
className,
style,
children,
...props
} = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
[placement]: true,
};
const outerStyle = {
top: positionTop,
left: positionLeft,
...style,
};
const arrowStyle = {
top: arrowOffsetTop,
left: arrowOffsetLeft,
};
return (
<div
{...elementProps}
role="tooltip"
className={classNames(className, classes)}
style={outerStyle}
>
<div className={prefix(bsProps, 'arrow')} style={arrowStyle} />
<div className={prefix(bsProps, 'inner')}>
{children}
</div>
</div>
);
}
}
Tooltip.propTypes = propTypes;
Tooltip.defaultProps = defaultProps;
export default bsClass('tooltip', Tooltip);