UNPKG

3.38 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9import isRequiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
10
11import { bsClass, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
12
13var propTypes = {
14 /**
15 * An html id attribute, necessary for accessibility
16 * @type {string|number}
17 * @required
18 */
19 id: isRequiredForA11y(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
20
21 /**
22 * Sets the direction the Tooltip is positioned towards.
23 */
24 placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
25
26 /**
27 * The "top" position value for the Tooltip.
28 */
29 positionTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
30 /**
31 * The "left" position value for the Tooltip.
32 */
33 positionLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
34
35 /**
36 * The "top" position value for the Tooltip arrow.
37 */
38 arrowOffsetTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
39 /**
40 * The "left" position value for the Tooltip arrow.
41 */
42 arrowOffsetLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
43};
44
45var defaultProps = {
46 placement: 'right'
47};
48
49var Tooltip = function (_React$Component) {
50 _inherits(Tooltip, _React$Component);
51
52 function Tooltip() {
53 _classCallCheck(this, Tooltip);
54
55 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
56 }
57
58 Tooltip.prototype.render = function render() {
59 var _extends2;
60
61 var _props = this.props,
62 placement = _props.placement,
63 positionTop = _props.positionTop,
64 positionLeft = _props.positionLeft,
65 arrowOffsetTop = _props.arrowOffsetTop,
66 arrowOffsetLeft = _props.arrowOffsetLeft,
67 className = _props.className,
68 style = _props.style,
69 children = _props.children,
70 props = _objectWithoutProperties(_props, ['placement', 'positionTop', 'positionLeft', 'arrowOffsetTop', 'arrowOffsetLeft', 'className', 'style', 'children']);
71
72 var _splitBsProps = splitBsProps(props),
73 bsProps = _splitBsProps[0],
74 elementProps = _splitBsProps[1];
75
76 var classes = _extends({}, getClassSet(bsProps), (_extends2 = {}, _extends2[placement] = true, _extends2));
77
78 var outerStyle = _extends({
79 top: positionTop,
80 left: positionLeft
81 }, style);
82
83 var arrowStyle = {
84 top: arrowOffsetTop,
85 left: arrowOffsetLeft
86 };
87
88 return React.createElement(
89 'div',
90 _extends({}, elementProps, {
91 role: 'tooltip',
92 className: classNames(className, classes),
93 style: outerStyle
94 }),
95 React.createElement('div', { className: prefix(bsProps, 'arrow'), style: arrowStyle }),
96 React.createElement(
97 'div',
98 { className: prefix(bsProps, 'inner') },
99 children
100 )
101 );
102 };
103
104 return Tooltip;
105}(React.Component);
106
107Tooltip.propTypes = propTypes;
108Tooltip.defaultProps = defaultProps;
109
110export default bsClass('tooltip', Tooltip);
\No newline at end of file