laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
135 lines (134 loc) • 4.19 kB
JavaScript
"use client";
import * as D from "react";
import { PureComponent as E } from "react";
import { getTooltipTranslate as S } from "../util/tooltip/translate.js";
function u(i, e) {
var t = Object.keys(i);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(i);
e && (o = o.filter(function(n) {
return Object.getOwnPropertyDescriptor(i, n).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function s(i) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e] != null ? arguments[e] : {};
e % 2 ? u(Object(t), !0).forEach(function(o) {
a(i, o, t[o]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(t)) : u(Object(t)).forEach(function(o) {
Object.defineProperty(i, o, Object.getOwnPropertyDescriptor(t, o));
});
}
return i;
}
function a(i, e, t) {
return (e = B(e)) in i ? Object.defineProperty(i, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : i[e] = t, i;
}
function B(i) {
var e = A(i, "string");
return typeof e == "symbol" ? e : e + "";
}
function A(i, e) {
if (typeof i != "object" || !i) return i;
var t = i[Symbol.toPrimitive];
if (t !== void 0) {
var o = t.call(i, e);
if (typeof o != "object") return o;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (e === "string" ? String : Number)(i);
}
class K extends E {
constructor() {
super(...arguments), a(this, "state", {
dismissed: !1,
dismissedAtCoordinate: {
x: 0,
y: 0
}
}), a(this, "handleKeyDown", (e) => {
if (e.key === "Escape") {
var t, o, n, r;
this.setState({
dismissed: !0,
dismissedAtCoordinate: {
x: (t = (o = this.props.coordinate) === null || o === void 0 ? void 0 : o.x) !== null && t !== void 0 ? t : 0,
y: (n = (r = this.props.coordinate) === null || r === void 0 ? void 0 : r.y) !== null && n !== void 0 ? n : 0
}
});
}
});
}
componentDidMount() {
document.addEventListener("keydown", this.handleKeyDown);
}
componentWillUnmount() {
document.removeEventListener("keydown", this.handleKeyDown);
}
componentDidUpdate() {
var e, t;
this.state.dismissed && (((e = this.props.coordinate) === null || e === void 0 ? void 0 : e.x) !== this.state.dismissedAtCoordinate.x || ((t = this.props.coordinate) === null || t === void 0 ? void 0 : t.y) !== this.state.dismissedAtCoordinate.y) && (this.state.dismissed = !1);
}
render() {
var {
active: e,
allowEscapeViewBox: t,
animationDuration: o,
animationEasing: n,
children: r,
coordinate: c,
hasPayload: d,
isAnimationActive: m,
offset: p,
position: v,
reverseDirection: f,
useTranslate3d: y,
viewBox: h,
wrapperStyle: b,
lastBoundingBox: l,
innerRef: w,
hasPortalFromProps: g
} = this.props, {
cssClasses: P,
cssProperties: O
} = S({
allowEscapeViewBox: t,
coordinate: c,
offsetTopLeft: p,
position: v,
reverseDirection: f,
tooltipBox: {
height: l.height,
width: l.width
},
useTranslate3d: y,
viewBox: h
}), j = g ? {} : s(s({
transition: m && e ? "transform ".concat(o, "ms ").concat(n) : void 0
}, O), {}, {
pointerEvents: "none",
visibility: !this.state.dismissed && e && d ? "visible" : "hidden",
position: "absolute",
top: 0,
left: 0
}), x = s(s({}, j), {}, {
visibility: !this.state.dismissed && e && d ? "visible" : "hidden"
}, b);
return (
// This element allow listening to the `Escape` key. See https://github.com/recharts/recharts/pull/2925
/* @__PURE__ */ D.createElement("div", {
// @ts-expect-error typescript library does not recognize xmlns attribute, but it's required for an HTML chunk inside SVG.
xmlns: "http://www.w3.org/1999/xhtml",
tabIndex: -1,
className: P,
style: x,
ref: w
}, r)
);
}
}
export {
K as TooltipBoundingBox
};