laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
166 lines (165 loc) • 5.26 kB
JavaScript
"use client";
import * as a from "react";
import { useEffect as M } from "react";
import { createPortal as Q } from "react-dom";
import { DefaultTooltipContent as W } from "./DefaultTooltipContent.js";
import { TooltipBoundingBox as X } from "./TooltipBoundingBox.js";
import { Global as Y } from "../util/Global.js";
import { getUniqPayload as Z } from "../util/payload/getUniqPayload.js";
import { useViewBox as $ } from "../context/chartLayoutContext.js";
import { useAccessibilityLayer as ee } from "../context/accessibilityContext.js";
import { useElementOffset as te } from "../util/useElementOffset.js";
import { Cursor as re } from "./Cursor.js";
import { selectIsTooltipActive as oe, selectTooltipPayload as ie, selectActiveCoordinate as ae, selectActiveLabel as ne } from "../state/selectors/selectors.js";
import { useTooltipPortal as le } from "../context/tooltipPortalContext.js";
import { useAppDispatch as se, useAppSelector as v } from "../state/hooks.js";
import { setTooltipSettingsState as pe } from "../state/tooltipSlice.js";
import { useTooltipChartSynchronisation as ue } from "../synchronisation/useChartSynchronisation.js";
import { useTooltipEventType as ce } from "../state/selectors/selectTooltipEventType.js";
import { resolveDefaultProps as fe } from "../util/resolveDefaultProps.js";
function O(e, t) {
var r = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
t && (o = o.filter(function(d) {
return Object.getOwnPropertyDescriptor(e, d).enumerable;
})), r.push.apply(r, o);
}
return r;
}
function S(e) {
for (var t = 1; t < arguments.length; t++) {
var r = arguments[t] != null ? arguments[t] : {};
t % 2 ? O(Object(r), !0).forEach(function(o) {
me(e, o, r[o]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : O(Object(r)).forEach(function(o) {
Object.defineProperty(e, o, Object.getOwnPropertyDescriptor(r, o));
});
}
return e;
}
function me(e, t, r) {
return (t = ve(t)) in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
}
function ve(e) {
var t = de(e, "string");
return typeof t == "symbol" ? t : t + "";
}
function de(e, t) {
if (typeof e != "object" || !e) return e;
var r = e[Symbol.toPrimitive];
if (r !== void 0) {
var o = r.call(e, t);
if (typeof o != "object") return o;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (t === "string" ? String : Number)(e);
}
function ye(e) {
return e.dataKey;
}
function be(e, t) {
return /* @__PURE__ */ a.isValidElement(e) ? /* @__PURE__ */ a.cloneElement(e, t) : typeof e == "function" ? /* @__PURE__ */ a.createElement(e, t) : /* @__PURE__ */ a.createElement(W, t);
}
var h = [], ge = {
allowEscapeViewBox: {
x: !1,
y: !1
},
animationDuration: 400,
animationEasing: "ease",
axisId: 0,
contentStyle: {},
cursor: !0,
filterNull: !0,
isAnimationActive: !Y.isSsr,
itemSorter: "name",
itemStyle: {},
labelStyle: {},
offset: 10,
reverseDirection: {
x: !1,
y: !1
},
separator: " : ",
trigger: "hover",
useTranslate3d: !1,
wrapperStyle: {}
};
function Re(e) {
var t = fe(e, ge), {
active: r,
allowEscapeViewBox: o,
animationDuration: d,
animationEasing: B,
content: T,
filterNull: j,
isAnimationActive: A,
offset: D,
payloadUniqBy: I,
position: F,
reverseDirection: C,
useTranslate3d: V,
wrapperStyle: L,
cursor: R,
shared: y,
trigger: n,
defaultIndex: b,
portal: f,
axisId: g
} = t, P = se(), s = typeof b == "number" ? String(b) : b;
M(() => {
P(pe({
shared: y,
trigger: n,
axisId: g,
active: r,
defaultIndex: s
}));
}, [P, y, n, g, r, s]);
var _ = $(), q = ee(), l = ce(y), {
activeIndex: x,
isActive: K
} = v((i) => oe(i, l, n, s)), N = v((i) => ie(i, l, n, s)), U = v((i) => ne(i, l, n, s)), m = v((i) => ae(i, l, n, s)), p = N, k = le(), u = r ?? K, [G, H] = te([p, u]), w = l === "axis" ? U : void 0;
ue(l, n, m, w, x, u);
var E = f ?? k;
if (E == null)
return null;
var c = p ?? h;
u || (c = h), j && c.length && (c = Z(p.filter((i) => i.value != null && (i.hide !== !0 || t.includeHidden)), I, ye));
var z = c.length > 0, J = /* @__PURE__ */ a.createElement(X, {
allowEscapeViewBox: o,
animationDuration: d,
animationEasing: B,
isAnimationActive: A,
active: u,
coordinate: m,
hasPayload: z,
offset: D,
position: F,
reverseDirection: C,
useTranslate3d: V,
viewBox: _,
wrapperStyle: L,
lastBoundingBox: G,
innerRef: H,
hasPortalFromProps: !!f
}, be(T, S(S({}, t), {}, {
// @ts-expect-error renderContent method expects the payload to be mutable, TODO make it immutable
payload: c,
label: w,
active: u,
coordinate: m,
accessibilityLayer: q
})));
return /* @__PURE__ */ a.createElement(a.Fragment, null, /* @__PURE__ */ Q(J, E), u && /* @__PURE__ */ a.createElement(re, {
cursor: R,
tooltipEventType: l,
coordinate: m,
payload: p,
index: x
}));
}
export {
Re as Tooltip
};