wix-style-react
Version:
wix-style-react
103 lines (83 loc) • 4.58 kB
JavaScript
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 _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
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 from 'react';
import PropTypes from 'prop-types';
import Tooltip from '../Tooltip';
import InputHelpSuffix from './InputHelpSuffix';
import InfoCircle from '../new-icons/InfoCircle';
import styles from './Input.scss';
var placementToMoveBy = {
right: { x: 10, y: -10 },
left: { x: -10, y: -10 },
top: { x: 0, y: -5 },
bottom: { x: 0, y: -15 }
};
var AmaterialHelpSuffix = function AmaterialHelpSuffix(_ref) {
var help = _ref.help,
helpMessage = _ref.helpMessage,
placement = _ref.placement,
onShow = _ref.onShow;
return React.createElement(
Tooltip,
{
dataHook: 'input-tooltip',
disabled: !help || helpMessage.length === 0,
maxWidth: '230px',
placement: placement,
moveBy: placementToMoveBy[placement],
alignment: 'center',
hideDelay: 100,
content: helpMessage,
textAlign: 'left',
overlay: '',
onShow: onShow
},
React.createElement(
'div',
{ className: styles.amaterialHelp },
React.createElement(InfoCircle, { height: '30', width: '30' })
)
);
};
AmaterialHelpSuffix.propTypes = {
help: PropTypes.bool,
helpMessage: PropTypes.node,
placement: PropTypes.oneOf(['left', 'right', 'top', 'bottom']),
onShow: PropTypes.func
};
AmaterialHelpSuffix.defaultProps = {
placement: 'right'
};
var ThemedInputHelpSuffix = function (_InputHelpSuffix) {
_inherits(ThemedInputHelpSuffix, _InputHelpSuffix);
function ThemedInputHelpSuffix() {
_classCallCheck(this, ThemedInputHelpSuffix);
return _possibleConstructorReturn(this, (ThemedInputHelpSuffix.__proto__ || Object.getPrototypeOf(ThemedInputHelpSuffix)).apply(this, arguments));
}
_createClass(ThemedInputHelpSuffix, [{
key: 'render',
value: function render() {
var _props = this.props,
theme = _props.theme,
help = _props.help,
helpMessage = _props.helpMessage,
tooltipPlacement = _props.tooltipPlacement,
onTooltipShow = _props.onTooltipShow;
return theme === 'amaterial' ? React.createElement(AmaterialHelpSuffix, {
help: help,
helpMessage: helpMessage,
placement: tooltipPlacement,
onShow: onTooltipShow
}) : _get(ThemedInputHelpSuffix.prototype.__proto__ || Object.getPrototypeOf(ThemedInputHelpSuffix.prototype), 'render', this).call(this);
}
}]);
return ThemedInputHelpSuffix;
}(InputHelpSuffix);
ThemedInputHelpSuffix.propTypes = {
tooltipPlacement: PropTypes.oneOf(['left', 'right', 'top', 'bottom']),
onTooltipShow: PropTypes.func
};
export default ThemedInputHelpSuffix;