UNPKG

3.6 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}
17 * @required
18 */
19 id: isRequiredForA11y(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
20
21 /**
22 * Sets the direction the Popover is positioned towards.
23 */
24 placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
25
26 /**
27 * The "top" position value for the Popover.
28 */
29 positionTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
30 /**
31 * The "left" position value for the Popover.
32 */
33 positionLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
34
35 /**
36 * The "top" position value for the Popover arrow.
37 */
38 arrowOffsetTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
39 /**
40 * The "left" position value for the Popover arrow.
41 */
42 arrowOffsetLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
43
44 /**
45 * Title content
46 */
47 title: PropTypes.node
48};
49
50var defaultProps = {
51 placement: 'right'
52};
53
54var Popover = function (_React$Component) {
55 _inherits(Popover, _React$Component);
56
57 function Popover() {
58 _classCallCheck(this, Popover);
59
60 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
61 }
62
63 Popover.prototype.render = function render() {
64 var _extends2;
65
66 var _props = this.props,
67 placement = _props.placement,
68 positionTop = _props.positionTop,
69 positionLeft = _props.positionLeft,
70 arrowOffsetTop = _props.arrowOffsetTop,
71 arrowOffsetLeft = _props.arrowOffsetLeft,
72 title = _props.title,
73 className = _props.className,
74 style = _props.style,
75 children = _props.children,
76 props = _objectWithoutProperties(_props, ['placement', 'positionTop', 'positionLeft', 'arrowOffsetTop', 'arrowOffsetLeft', 'title', 'className', 'style', 'children']);
77
78 var _splitBsProps = splitBsProps(props),
79 bsProps = _splitBsProps[0],
80 elementProps = _splitBsProps[1];
81
82 var classes = _extends({}, getClassSet(bsProps), (_extends2 = {}, _extends2[placement] = true, _extends2));
83
84 var outerStyle = _extends({
85 display: 'block',
86 top: positionTop,
87 left: positionLeft
88 }, style);
89
90 var arrowStyle = {
91 top: arrowOffsetTop,
92 left: arrowOffsetLeft
93 };
94
95 return React.createElement(
96 'div',
97 _extends({}, elementProps, {
98 role: 'tooltip',
99 className: classNames(className, classes),
100 style: outerStyle
101 }),
102 React.createElement('div', { className: 'arrow', style: arrowStyle }),
103 title && React.createElement(
104 'h3',
105 { className: prefix(bsProps, 'title') },
106 title
107 ),
108 React.createElement(
109 'div',
110 { className: prefix(bsProps, 'content') },
111 children
112 )
113 );
114 };
115
116 return Popover;
117}(React.Component);
118
119Popover.propTypes = propTypes;
120Popover.defaultProps = defaultProps;
121
122export default bsClass('popover', Popover);
\No newline at end of file