wix-style-react
Version:
108 lines (88 loc) • 4.34 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import { st, classes } from './StatusIndicator.st.css';
import Tooltip from '../Tooltip';
import FormFieldWarningFilled from 'wix-ui-icons-common/system/FormFieldWarningFilled';
import FormFieldErrorFilled from 'wix-ui-icons-common/system/FormFieldErrorFilled';
import Loader from '../Loader';
import { dataHooks, STATUS } from './constants';
/** StatusIndicator */
var StatusIndicator = /*#__PURE__*/function (_React$PureComponent) {
_inherits(StatusIndicator, _React$PureComponent);
var _super = _createSuper(StatusIndicator);
function StatusIndicator() {
var _this;
_classCallCheck(this, StatusIndicator);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "_renderStatus", function () {
switch (_this.props.status) {
case STATUS.WARNING:
return /*#__PURE__*/React.createElement(FormFieldWarningFilled, null);
case STATUS.LOADING:
return /*#__PURE__*/React.createElement(Loader, {
size: "tiny"
});
case STATUS.ERROR:
default:
return /*#__PURE__*/React.createElement(FormFieldErrorFilled, null);
}
});
return _this;
}
_createClass(StatusIndicator, [{
key: "render",
value: function render() {
var _this$props = this.props,
dataHook = _this$props.dataHook,
status = _this$props.status,
message = _this$props.message,
tooltipPlacement = _this$props.tooltipPlacement,
className = _this$props.className;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.root, {
status: status
}, className),
"data-hook": dataHook,
"data-status": status
}, message ? /*#__PURE__*/React.createElement(Tooltip, {
dataHook: dataHooks.tooltip,
appendTo: "window",
placement: tooltipPlacement,
exitDelay: 100,
content: message,
maxWidth: 250
}, this._renderStatus()) : this._renderStatus());
}
}]);
return StatusIndicator;
}(React.PureComponent);
StatusIndicator.displayName = 'StatusIndicator';
StatusIndicator.propTypes = {
/** Applies a data-hook HTML attribute that can be used in tests. */
dataHook: PropTypes.string,
/** Allows you to apply a CSS class to the component’s root element. */
className: PropTypes.string,
/** Sets the indication type. */
status: PropTypes.oneOf(['error', 'warning', 'loading']),
/** Sets the message that’s displayed in a tooltip. If not set, the tooltip won’t appear. */
message: PropTypes.string,
/** Defines which side the tooltip will be placed on. */
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
};
StatusIndicator.defaultProps = {
status: 'error',
tooltipPlacement: 'top'
};
export default StatusIndicator;