UNPKG

wix-style-react

Version:
110 lines (90 loc) 4.88 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 _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 classNames from 'classnames'; import InputErrorSuffix from './InputErrorSuffix'; import Tooltip from '../Tooltip'; import FormFieldErrorFilled from '../new-icons/system/FormFieldErrorFilled'; import styles from './Input.scss'; var placementToMoveBy = { right: { x: 2, y: -10 }, left: { x: -2, y: -10 }, top: { x: 0, y: -10 }, bottom: { x: 0, y: -8 } }; var AmaterialErrorSuffix = function AmaterialErrorSuffix(_ref) { var focused = _ref.focused, error = _ref.error, errorMessage = _ref.errorMessage, placement = _ref.placement, onShow = _ref.onShow; return focused ? null : React.createElement( Tooltip, { dataHook: 'input-tooltip', disabled: !error && !errorMessage, placement: placement, maxWidth: '230px', hideDelay: 5, showDelay: 5, active: focused, moveBy: placementToMoveBy[placement], alignment: 'center', content: errorMessage, overlay: '', textAlign: 'left', onShow: onShow }, React.createElement( 'div', { className: classNames(styles.errorIcon, styles.suffix) }, React.createElement(FormFieldErrorFilled, { size: '1.5em' }) ) ); }; AmaterialErrorSuffix.propTypes = { errorMessage: PropTypes.node.isRequired, error: PropTypes.bool, focused: PropTypes.bool, placement: PropTypes.oneOf(['left', 'right', 'top', 'bottom']), onShow: PropTypes.func }; AmaterialErrorSuffix.defaultProps = { placement: 'right' }; var ThemedInputErrorSuffix = function (_InputErrorSuffix) { _inherits(ThemedInputErrorSuffix, _InputErrorSuffix); function ThemedInputErrorSuffix() { _classCallCheck(this, ThemedInputErrorSuffix); return _possibleConstructorReturn(this, (ThemedInputErrorSuffix.__proto__ || Object.getPrototypeOf(ThemedInputErrorSuffix)).apply(this, arguments)); } _createClass(ThemedInputErrorSuffix, [{ key: 'render', value: function render() { var _props = this.props, theme = _props.theme, focused = _props.focused, error = _props.error, errorMessage = _props.errorMessage, tooltipPlacement = _props.tooltipPlacement, onTooltipShow = _props.onTooltipShow; return theme === 'amaterial' ? React.createElement(AmaterialErrorSuffix, { focused: focused, error: error, errorMessage: errorMessage, placement: tooltipPlacement, onShow: onTooltipShow }) : _get(ThemedInputErrorSuffix.prototype.__proto__ || Object.getPrototypeOf(ThemedInputErrorSuffix.prototype), 'render', this).call(this); } }]); return ThemedInputErrorSuffix; }(InputErrorSuffix); ThemedInputErrorSuffix.propTypes = { tooltipPlacement: PropTypes.oneOf(['left', 'right', 'top', 'bottom']), onTooltipShow: PropTypes.func }; export default ThemedInputErrorSuffix;