UNPKG

wix-style-react

Version:
189 lines (157 loc) • 6.83 kB
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; 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; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import styles from './TooltipContent.scss'; 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 React.createElement( 'div', { className: styles.root, style: style, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, 'data-hook': dataHook }, React.createElement( 'div', { className: classnames(_defineProperty({}, styles.fadeIn, !showImmediately)) }, React.createElement( 'div', { className: classnames(_defineProperty({}, styles['bounce-' + arrowPlacement], bounce)) }, React.createElement( 'div', { ref: function ref(_ref) { return _this2.tooltip = _ref; }, className: classnames(styles.tooltip, styles[theme], styles[size], contentClassName), style: { maxWidth: maxWidth, minWidth: minWidth, textAlign: textAlign, padding: padding, lineHeight: lineHeight, color: color } }, React.createElement( 'div', { 'data-hook': 'tooltip-content' }, children ) ), showArrow && React.createElement('div', { 'data-hook': 'tooltip-arrow', className: classnames(styles.arrow, styles[theme], styles[arrowPlacement]), style: arrowStyle }) ) ) ); } }]); return TooltipContent; }(Component), _class.propTypes = { dataHook: PropTypes.string, /** className for tooltip content */ contentClassName: PropTypes.string, /** alignment of the tooltip's text */ textAlign: PropTypes.string, /** The tooltip max width */ maxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** The tooltip min width */ minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** * Tooltip content to be rendered */ children: PropTypes.node.isRequired, /** * Specifies tooltip theme */ theme: PropTypes.oneOf(['light', 'dark', 'error']), /** * Specifies on which side the arrow should be shown */ arrowPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']), /** * Custom CSS style object (used to allow setting arrow position) */ arrowStyle: PropTypes.object, /** * Custom CSS style object (used to allow setting the position) */ style: PropTypes.object, /** * Custom padding (not part of style since it is to the internal component) */ padding: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** * Callback triggered when mouse enters the component * Used for showing tooltip when mouse leaves the target element, but hovers the tooltip itself */ onMouseEnter: PropTypes.func, /** * Callback triggered when mouse leaves the component * Used for showing tooltip when mouse leaves the target element, but hovers the tooltip itself */ onMouseLeave: PropTypes.func, /** * Specifies if tooltip content should use bouncing animation. */ bounce: PropTypes.bool, size: PropTypes.oneOf(['normal', 'large']), /** * Specifies the font color of the content of the tooltip */ color: PropTypes.string, lineHeight: PropTypes.string, /** Show Tooltip Immediately - with no delay and no animation */ showImmediately: PropTypes.bool, /** Show an arrow shape */ showArrow: PropTypes.bool }, _class.defaultProps = { theme: 'light', arrowPlacement: 'bottom', maxWidth: '204px', size: 'normal', textAlign: 'center', showArrow: true }, _temp); export default TooltipContent;