UNPKG

wix-style-react

Version:
205 lines (166 loc) • 7.79 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _classnames3 = require('classnames'); var _classnames4 = _interopRequireDefault(_classnames3); var _TooltipContent = require('./TooltipContent.scss'); var _TooltipContent2 = _interopRequireDefault(_TooltipContent); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var TooltipContent = (_temp = _class = function (_Component) { _inherits(TooltipContent, _Component); function TooltipContent() { _classCallCheck(this, TooltipContent); return _possibleConstructorReturn(this, (TooltipContent.__proto__ || Object.getPrototypeOf(TooltipContent)).apply(this, arguments)); } _createClass(TooltipContent, [{ key: 'render', value: function render() { var _this2 = this; var _props = this.props, children = _props.children, contentClassName = _props.contentClassName, theme = _props.theme, arrowPlacement = _props.arrowPlacement, arrowStyle = _props.arrowStyle, style = _props.style, onMouseEnter = _props.onMouseEnter, onMouseLeave = _props.onMouseLeave, bounce = _props.bounce, size = _props.size, textAlign = _props.textAlign, maxWidth = _props.maxWidth, minWidth = _props.minWidth, padding = _props.padding, color = _props.color, lineHeight = _props.lineHeight, showImmediately = _props.showImmediately, showArrow = _props.showArrow, dataHook = _props.dataHook; return _react2.default.createElement( 'div', { className: _TooltipContent2.default.root, style: style, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, 'data-hook': dataHook }, _react2.default.createElement( 'div', { className: (0, _classnames4.default)(_defineProperty({}, _TooltipContent2.default.fadeIn, !showImmediately)) }, _react2.default.createElement( 'div', { className: (0, _classnames4.default)(_defineProperty({}, _TooltipContent2.default['bounce-' + arrowPlacement], bounce)) }, _react2.default.createElement( 'div', { ref: function ref(_ref) { return _this2.tooltip = _ref; }, className: (0, _classnames4.default)(_TooltipContent2.default.tooltip, _TooltipContent2.default[theme], _TooltipContent2.default[size], contentClassName), style: { maxWidth: maxWidth, minWidth: minWidth, textAlign: textAlign, padding: padding, lineHeight: lineHeight, color: color } }, _react2.default.createElement( 'div', { 'data-hook': 'tooltip-content' }, children ) ), showArrow && _react2.default.createElement('div', { 'data-hook': 'tooltip-arrow', className: (0, _classnames4.default)(_TooltipContent2.default.arrow, _TooltipContent2.default[theme], _TooltipContent2.default[arrowPlacement]), style: arrowStyle }) ) ) ); } }]); return TooltipContent; }(_react.Component), _class.propTypes = { dataHook: _propTypes2.default.string, /** className for tooltip content */ contentClassName: _propTypes2.default.string, /** alignment of the tooltip's text */ textAlign: _propTypes2.default.string, /** The tooltip max width */ maxWidth: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]), /** The tooltip min width */ minWidth: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]), /** * Tooltip content to be rendered */ children: _propTypes2.default.node.isRequired, /** * Specifies tooltip theme */ theme: _propTypes2.default.oneOf(['light', 'dark', 'error']), /** * Specifies on which side the arrow should be shown */ arrowPlacement: _propTypes2.default.oneOf(['top', 'right', 'bottom', 'left']), /** * Custom CSS style object (used to allow setting arrow position) */ arrowStyle: _propTypes2.default.object, /** * Custom CSS style object (used to allow setting the position) */ style: _propTypes2.default.object, /** * Custom padding (not part of style since it is to the internal component) */ padding: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]), /** * Callback triggered when mouse enters the component * Used for showing tooltip when mouse leaves the target element, but hovers the tooltip itself */ onMouseEnter: _propTypes2.default.func, /** * Callback triggered when mouse leaves the component * Used for showing tooltip when mouse leaves the target element, but hovers the tooltip itself */ onMouseLeave: _propTypes2.default.func, /** * Specifies if tooltip content should use bouncing animation. */ bounce: _propTypes2.default.bool, size: _propTypes2.default.oneOf(['normal', 'large']), /** * Specifies the font color of the content of the tooltip */ color: _propTypes2.default.string, lineHeight: _propTypes2.default.string, /** Show Tooltip Immediately - with no delay and no animation */ showImmediately: _propTypes2.default.bool, /** Show an arrow shape */ showArrow: _propTypes2.default.bool }, _class.defaultProps = { theme: 'light', arrowPlacement: 'bottom', maxWidth: '204px', size: 'normal', textAlign: 'center', showArrow: true }, _temp); exports.default = TooltipContent;