wix-style-react
Version:
86 lines (74 loc) • 3.38 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
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, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Tooltip from '../../Tooltip';
import Heading from '../../Heading';
import { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable/FocusableHOC";
import { st, classes } from './FunnelBadge.st.css';
import { dataHooks } from '../constants';
var Badge = /*#__PURE__*/function (_PureComponent) {
_inherits(Badge, _PureComponent);
var _super = _createSuper(Badge);
function Badge() {
_classCallCheck(this, Badge);
return _super.apply(this, arguments);
}
_createClass(Badge, [{
key: "render",
value: function render() {
var _this$props = this.props,
value = _this$props.value,
className = _this$props.className,
focusableOnBlur = _this$props.focusableOnBlur,
focusableOnFocus = _this$props.focusableOnFocus,
dataHook = _this$props.dataHook;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.badge, className),
"data-hook": dataHook,
tabIndex: 0,
onBlur: focusableOnBlur,
onFocus: focusableOnFocus
}, /*#__PURE__*/React.createElement("span", {
className: classes.badgeContent
}, /*#__PURE__*/React.createElement(Heading, {
appearance: "H6",
dataHook: dataHooks.badgeValue,
light: true
}, value)));
}
}]);
return Badge;
}(PureComponent);
var FocusedBadge = withFocusable(Badge);
export var FunnelBadge = function FunnelBadge(props) {
var tooltipContent = props.tooltipContent,
onTooltipShow = props.onTooltipShow,
value = props.value;
return /*#__PURE__*/React.createElement(Tooltip, {
dataHook: dataHooks.badgeTooltip,
disabled: !tooltipContent,
content: tooltipContent,
onShow: onTooltipShow,
moveBy: {
y: 2
},
textAlign: "start"
}, /*#__PURE__*/React.createElement(FocusedBadge, {
value: value,
dataHook: dataHooks.badge
}));
};
FunnelBadge.propTypes = {
/** Badge's value */
value: PropTypes.string.isRequired,
/** Tooltip content. Can be either string or renderable node */
tooltipContent: PropTypes.node,
/** Callback on tooltip content show event */
onTooltipShow: PropTypes.func
};