| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.TooltipBoundingBox = void 0;
|
|---|
| 7 | var _react = _interopRequireWildcard(require("react"));
|
|---|
| 8 | var React = _react;
|
|---|
| 9 | var _translate = require("../util/tooltip/translate");
|
|---|
| 10 | function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|---|
| 11 | function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|---|
| 12 | function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|---|
| 13 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|---|
| 14 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 15 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|---|
| 16 | class TooltipBoundingBox extends _react.PureComponent {
|
|---|
| 17 | constructor() {
|
|---|
| 18 | super(...arguments);
|
|---|
| 19 | _defineProperty(this, "state", {
|
|---|
| 20 | dismissed: false,
|
|---|
| 21 | dismissedAtCoordinate: {
|
|---|
| 22 | x: 0,
|
|---|
| 23 | y: 0
|
|---|
| 24 | }
|
|---|
| 25 | });
|
|---|
| 26 | _defineProperty(this, "handleKeyDown", event => {
|
|---|
| 27 | if (event.key === 'Escape') {
|
|---|
| 28 | var _this$props$coordinat, _this$props$coordinat2, _this$props$coordinat3, _this$props$coordinat4;
|
|---|
| 29 | this.setState({
|
|---|
| 30 | dismissed: true,
|
|---|
| 31 | dismissedAtCoordinate: {
|
|---|
| 32 | x: (_this$props$coordinat = (_this$props$coordinat2 = this.props.coordinate) === null || _this$props$coordinat2 === void 0 ? void 0 : _this$props$coordinat2.x) !== null && _this$props$coordinat !== void 0 ? _this$props$coordinat : 0,
|
|---|
| 33 | y: (_this$props$coordinat3 = (_this$props$coordinat4 = this.props.coordinate) === null || _this$props$coordinat4 === void 0 ? void 0 : _this$props$coordinat4.y) !== null && _this$props$coordinat3 !== void 0 ? _this$props$coordinat3 : 0
|
|---|
| 34 | }
|
|---|
| 35 | });
|
|---|
| 36 | }
|
|---|
| 37 | });
|
|---|
| 38 | }
|
|---|
| 39 | componentDidMount() {
|
|---|
| 40 | document.addEventListener('keydown', this.handleKeyDown);
|
|---|
| 41 | }
|
|---|
| 42 | componentWillUnmount() {
|
|---|
| 43 | document.removeEventListener('keydown', this.handleKeyDown);
|
|---|
| 44 | }
|
|---|
| 45 | componentDidUpdate() {
|
|---|
| 46 | var _this$props$coordinat5, _this$props$coordinat6;
|
|---|
| 47 | if (!this.state.dismissed) {
|
|---|
| 48 | return;
|
|---|
| 49 | }
|
|---|
| 50 | if (((_this$props$coordinat5 = this.props.coordinate) === null || _this$props$coordinat5 === void 0 ? void 0 : _this$props$coordinat5.x) !== this.state.dismissedAtCoordinate.x || ((_this$props$coordinat6 = this.props.coordinate) === null || _this$props$coordinat6 === void 0 ? void 0 : _this$props$coordinat6.y) !== this.state.dismissedAtCoordinate.y) {
|
|---|
| 51 | this.state.dismissed = false;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | render() {
|
|---|
| 55 | var {
|
|---|
| 56 | active,
|
|---|
| 57 | allowEscapeViewBox,
|
|---|
| 58 | animationDuration,
|
|---|
| 59 | animationEasing,
|
|---|
| 60 | children,
|
|---|
| 61 | coordinate,
|
|---|
| 62 | hasPayload,
|
|---|
| 63 | isAnimationActive,
|
|---|
| 64 | offset,
|
|---|
| 65 | position,
|
|---|
| 66 | reverseDirection,
|
|---|
| 67 | useTranslate3d,
|
|---|
| 68 | viewBox,
|
|---|
| 69 | wrapperStyle,
|
|---|
| 70 | lastBoundingBox,
|
|---|
| 71 | innerRef,
|
|---|
| 72 | hasPortalFromProps
|
|---|
| 73 | } = this.props;
|
|---|
| 74 | var offsetLeft = typeof offset === 'number' ? offset : offset.x;
|
|---|
| 75 | var offsetTop = typeof offset === 'number' ? offset : offset.y;
|
|---|
| 76 | var {
|
|---|
| 77 | cssClasses,
|
|---|
| 78 | cssProperties
|
|---|
| 79 | } = (0, _translate.getTooltipTranslate)({
|
|---|
| 80 | allowEscapeViewBox,
|
|---|
| 81 | coordinate,
|
|---|
| 82 | offsetLeft,
|
|---|
| 83 | offsetTop,
|
|---|
| 84 | position,
|
|---|
| 85 | reverseDirection,
|
|---|
| 86 | tooltipBox: {
|
|---|
| 87 | height: lastBoundingBox.height,
|
|---|
| 88 | width: lastBoundingBox.width
|
|---|
| 89 | },
|
|---|
| 90 | useTranslate3d,
|
|---|
| 91 | viewBox
|
|---|
| 92 | });
|
|---|
| 93 |
|
|---|
| 94 | // do not use absolute styles if the user has passed a custom portal prop
|
|---|
| 95 | var positionStyles = hasPortalFromProps ? {} : _objectSpread(_objectSpread({
|
|---|
| 96 | transition: isAnimationActive && active ? "transform ".concat(animationDuration, "ms ").concat(animationEasing) : undefined
|
|---|
| 97 | }, cssProperties), {}, {
|
|---|
| 98 | pointerEvents: 'none',
|
|---|
| 99 | visibility: !this.state.dismissed && active && hasPayload ? 'visible' : 'hidden',
|
|---|
| 100 | position: 'absolute',
|
|---|
| 101 | top: 0,
|
|---|
| 102 | left: 0
|
|---|
| 103 | });
|
|---|
| 104 | var outerStyle = _objectSpread(_objectSpread({}, positionStyles), {}, {
|
|---|
| 105 | visibility: !this.state.dismissed && active && hasPayload ? 'visible' : 'hidden'
|
|---|
| 106 | }, wrapperStyle);
|
|---|
| 107 | return (
|
|---|
| 108 | /*#__PURE__*/
|
|---|
| 109 | // This element allow listening to the `Escape` key. See https://github.com/recharts/recharts/pull/2925
|
|---|
| 110 | React.createElement("div", {
|
|---|
| 111 | // @ts-expect-error typescript library does not recognize xmlns attribute, but it's required for an HTML chunk inside SVG.
|
|---|
| 112 | xmlns: "http://www.w3.org/1999/xhtml",
|
|---|
| 113 | tabIndex: -1,
|
|---|
| 114 | className: cssClasses,
|
|---|
| 115 | style: outerStyle,
|
|---|
| 116 | ref: innerRef
|
|---|
| 117 | }, children)
|
|---|
| 118 | );
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | exports.TooltipBoundingBox = TooltipBoundingBox; |
|---|