wix-style-react
Version:
wix-style-react
92 lines (74 loc) • 4.19 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
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, _temp2;
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 { bool, node } from 'prop-types';
import styles from './FieldLabelAttributes.scss';
import WixComponent from '../BaseComponents/WixComponent';
import Tooltip from '../Tooltip';
import InfoCircle from '../new-icons/InfoCircle';
var FieldLabelAttributes = (_temp2 = _class = function (_WixComponent) {
_inherits(FieldLabelAttributes, _WixComponent);
function FieldLabelAttributes() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, FieldLabelAttributes);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = FieldLabelAttributes.__proto__ || Object.getPrototypeOf(FieldLabelAttributes)).call.apply(_ref, [this].concat(args))), _this), _this.infoIcon = React.createElement(
'span',
{ 'data-hook': 'info', className: styles.icon },
React.createElement(InfoCircle, null)
), _this.getTooltip = function () {
if (_this.props.info) {
return React.createElement(Tooltip, _extends({}, _this.tooltipDefaultProps, {
appendToParent: _this.props.appendToParent,
content: _this.props.info,
children: _this.infoIcon
}));
} else if (_this.props.tooltip) {
return React.cloneElement(_this.props.tooltip, _extends({}, _this.tooltipDefaultProps, {
children: _this.props.tooltip.props.children || _this.infoIcon
}));
} else {
return null;
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(FieldLabelAttributes, [{
key: 'render',
value: function render() {
return React.createElement(
'div',
{ className: styles.root, 'data-hook': 'field-label-attributes' },
this.props.required && React.createElement(
'span',
{ 'data-hook': 'required', className: styles.required },
'*'
),
this.getTooltip()
);
}
}]);
return FieldLabelAttributes;
}(WixComponent), _class.tooltipDefaultProps = {
moveBy: { x: 0, y: -1 },
minWidth: '150px'
}, _temp2);
FieldLabelAttributes.defaultProps = {
required: false,
info: '',
appendToParent: true,
tooltip: null
};
FieldLabelAttributes.propTypes = {
required: bool,
info: node,
appendToParent: bool,
tooltip: node
};
export default FieldLabelAttributes;