@undp/design-system-react
Version:
React based design system for UNDP
357 lines (356 loc) • 11.8 kB
JavaScript
import { t as e } from "./utils-ca9as9Ye.js";
import { i as t, r as n } from "./dist-DxuGUd9a.js";
import { t as r } from "./dist-jqIPNHDe.js";
import { t as i } from "./dist-X_NWu4il.js";
import { n as a, t as o } from "./dist-BKfyhBSH.js";
import { n as s, t as c } from "./dist-CwCVtfik.js";
import { t as l } from "./dist-CnnnGPaT.js";
import { t as u } from "./dist-DfB3OR9K.js";
import { n as d } from "./dist-CMH_aW5P.js";
import { t as f } from "./dist-vWm-kLzq.js";
import { i as p, n as m, r as h, t as g } from "./dist-D8TIRAGv.js";
import * as _ from "react";
import v from "react";
import { jsx as y, jsxs as b } from "react/jsx-runtime";
//#region node_modules/@radix-ui/react-tooltip/dist/index.mjs
var x = Object.defineProperty, S = (e, t) => x(e, "name", {
value: t,
configurable: !0
}), [C, w] = a("Tooltip", [p]), T = p(), E = "TooltipProvider", D = 700, O = "tooltip.open", [k, A] = C(E), j = /* @__PURE__ */ S((e) => {
let { __scopeTooltip: t, delayDuration: n = D, skipDelayDuration: r = 300, disableHoverableContent: i = !1, children: a } = e, o = _.useRef(!0), s = _.useRef(!1), c = _.useRef(0);
return _.useEffect(() => {
let e = c.current;
return () => window.clearTimeout(e);
}, []), /* @__PURE__ */ y(k, {
scope: t,
isOpenDelayedRef: o,
delayDuration: n,
onOpen: _.useCallback(() => {
r <= 0 || (window.clearTimeout(c.current), o.current = !1);
}, [r]),
onClose: _.useCallback(() => {
r <= 0 || (window.clearTimeout(c.current), c.current = window.setTimeout(() => o.current = !0, r));
}, [r]),
isPointerInTransitRef: s,
onPointerInTransitChange: _.useCallback((e) => {
s.current = e;
}, []),
disableHoverableContent: i,
children: a
});
}, "TooltipProvider"), M = "Tooltip", [N, P] = C(M), F = /* @__PURE__ */ S((e) => {
let { __scopeTooltip: t, children: n, open: r, defaultOpen: i, onOpenChange: a, disableHoverableContent: o, delayDuration: s } = e, l = A(M, e.__scopeTooltip), d = T(t), [f, p] = _.useState(null), [m, g] = _.useState(void 0), v = u(), b = _.useRef(0), x = o ?? l.disableHoverableContent, C = s ?? l.delayDuration, w = _.useRef(!1), [E, D] = c({
prop: r,
defaultProp: i ?? !1,
onChange: /* @__PURE__ */ S((e) => {
e ? (l.onOpen(), document.dispatchEvent(new CustomEvent(O))) : l.onClose(), a?.(e);
}, "onChange"),
caller: M
}), k = _.useMemo(() => E ? w.current ? "delayed-open" : "instant-open" : "closed", [E]), j = _.useCallback(() => {
window.clearTimeout(b.current), b.current = 0, w.current = !1, D(!0);
}, [D]), P = _.useCallback(() => {
window.clearTimeout(b.current), b.current = 0, D(!1);
}, [D]), F = _.useCallback(() => {
window.clearTimeout(b.current), b.current = window.setTimeout(() => {
w.current = !0, D(!0), b.current = 0;
}, C);
}, [C, D]);
_.useEffect(() => () => {
b.current &&= (window.clearTimeout(b.current), 0);
}, []);
let I = m ?? v;
return /* @__PURE__ */ y(h, {
...d,
children: /* @__PURE__ */ y(N, {
scope: t,
contentId: I,
setContentId: g,
open: E,
stateAttribute: k,
trigger: f,
onTriggerChange: p,
onTriggerEnter: _.useCallback(() => {
l.isOpenDelayedRef.current ? F() : j();
}, [
l.isOpenDelayedRef,
F,
j
]),
onTriggerLeave: _.useCallback(() => {
x ? P() : (window.clearTimeout(b.current), b.current = 0);
}, [P, x]),
onOpen: j,
onClose: P,
disableHoverableContent: x,
children: n
})
});
}, "Tooltip"), I = "TooltipTrigger", L = /* @__PURE__ */ _.forwardRef(/* @__PURE__ */ S(function(e, n) {
let { __scopeTooltip: i, ...a } = e, o = P(I, i), c = A(I, i), l = T(i), u = t(n, _.useRef(null), o.onTriggerChange), d = _.useRef(!1), f = _.useRef(!1), p = _.useCallback(() => d.current = !1, []);
return _.useEffect(() => () => document.removeEventListener("pointerup", p), [p]), /* @__PURE__ */ y(g, {
asChild: !0,
...l,
children: /* @__PURE__ */ y(r.button, {
"aria-describedby": o.open ? o.contentId : void 0,
"data-state": o.stateAttribute,
...a,
ref: u,
onPointerMove: s(e.onPointerMove, (e) => {
e.pointerType !== "touch" && !f.current && !c.isPointerInTransitRef.current && (o.onTriggerEnter(), f.current = !0);
}),
onPointerLeave: s(e.onPointerLeave, () => {
o.onTriggerLeave(), f.current = !1;
}),
onPointerDown: s(e.onPointerDown, () => {
o.open && o.onClose(), d.current = !0, document.addEventListener("pointerup", p, { once: !0 });
}),
onFocus: s(e.onFocus, () => {
d.current || o.onOpen();
}),
onBlur: s(e.onBlur, o.onClose),
onClick: s(e.onClick, o.onClose)
})
});
}, "TooltipTrigger")), R = "TooltipPortal", [z, B] = C(R, { forceMount: void 0 }), V = /* @__PURE__ */ S((e) => {
let { __scopeTooltip: t, forceMount: n, children: r, container: i } = e, a = P(R, t);
return /* @__PURE__ */ y(z, {
scope: t,
forceMount: n,
children: /* @__PURE__ */ y(l, {
present: n || a.open,
children: /* @__PURE__ */ y(f, {
asChild: !0,
container: i,
children: r
})
})
});
}, "TooltipPortal"), H = "TooltipContent", U = /* @__PURE__ */ _.forwardRef(/* @__PURE__ */ S(function(e, t) {
let n = B(H, e.__scopeTooltip), { forceMount: r = n.forceMount, side: i = "top", ...a } = e, o = P(H, e.__scopeTooltip);
return /* @__PURE__ */ y(l, {
present: r || o.open,
children: o.disableHoverableContent ? /* @__PURE__ */ y(G, {
side: i,
...a,
ref: t
}) : /* @__PURE__ */ y(W, {
side: i,
...a,
ref: t
})
});
}, "TooltipContent")), W = /* @__PURE__ */ _.forwardRef(/* @__PURE__ */ S(function(e, n) {
let r = P(H, e.__scopeTooltip), i = A(H, e.__scopeTooltip), a = _.useRef(null), o = t(n, a), [s, c] = _.useState(null), { trigger: l, onClose: u } = r, d = a.current, { onPointerInTransitChange: f } = i, p = _.useCallback(() => {
c(null), f(!1);
}, [f]), m = _.useCallback((e, t) => {
let n = e.currentTarget, r = {
x: e.clientX,
y: e.clientY
}, i = q(r, K(r, n.getBoundingClientRect())), a = J(t.getBoundingClientRect()), o = X([...i, ...a]);
c(o), f(!0);
}, [f]);
return _.useEffect(() => () => p(), [p]), _.useEffect(() => {
if (l && d) {
let e = /* @__PURE__ */ S((e) => m(e, d), "handleTriggerLeave"), t = /* @__PURE__ */ S((e) => m(e, l), "handleContentLeave");
return l.addEventListener("pointerleave", e), d.addEventListener("pointerleave", t), () => {
l.removeEventListener("pointerleave", e), d.removeEventListener("pointerleave", t);
};
}
}, [
l,
d,
m,
p
]), _.useEffect(() => {
if (s) {
let e = /* @__PURE__ */ S((e) => {
let t = e.target, n = {
x: e.clientX,
y: e.clientY
}, r = l?.contains(t) || d?.contains(t), i = !Y(n, s);
r ? p() : i && (p(), u());
}, "handleTrackPointerGrace");
return document.addEventListener("pointermove", e), () => document.removeEventListener("pointermove", e);
}
}, [
l,
d,
s,
u,
p
]), /* @__PURE__ */ y(G, {
...e,
ref: o
});
}, "TooltipContentHoverable")), ee = n("TooltipContent"), G = /* @__PURE__ */ _.forwardRef(/* @__PURE__ */ S(function(e, t) {
let { __scopeTooltip: n, children: r, "aria-label": a, id: s, onEscapeKeyDown: c, onPointerDownOutside: l, ...u } = e, f = P(H, n), p = T(n), { onClose: h } = f;
_.useEffect(() => (document.addEventListener(O, h), () => document.removeEventListener(O, h)), [h]), _.useEffect(() => {
if (f.trigger) {
let e = /* @__PURE__ */ S((e) => {
e.target instanceof Node && e.target.contains(f.trigger) && h();
}, "handleScroll");
return window.addEventListener("scroll", e, { capture: !0 }), () => window.removeEventListener("scroll", e, { capture: !0 });
}
}, [f.trigger, h]);
let { setContentId: g } = f;
return o(() => (g(s), () => {
g(void 0);
}), [s, g]), /* @__PURE__ */ y(d, {
asChild: !0,
disableOutsidePointerEvents: !1,
onEscapeKeyDown: c,
onPointerDownOutside: l,
onFocusOutside: (e) => e.preventDefault(),
onDismiss: h,
children: /* @__PURE__ */ b(m, {
"data-state": f.stateAttribute,
role: a ? void 0 : "tooltip",
id: a ? void 0 : f.contentId,
...p,
...u,
ref: t,
style: {
...u.style,
"--radix-tooltip-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-tooltip-content-available-width": "var(--radix-popper-available-width)",
"--radix-tooltip-content-available-height": "var(--radix-popper-available-height)",
"--radix-tooltip-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-tooltip-trigger-height": "var(--radix-popper-anchor-height)"
},
children: [/* @__PURE__ */ y(ee, { children: r }), a ? /* @__PURE__ */ y(i, {
id: f.contentId,
role: "tooltip",
children: a
}) : null]
})
});
}, "TooltipContentImpl"));
function K(e, t) {
let n = Math.abs(t.top - e.y), r = Math.abs(t.bottom - e.y), i = Math.abs(t.right - e.x), a = Math.abs(t.left - e.x);
switch (Math.min(n, r, i, a)) {
case a: return "left";
case i: return "right";
case n: return "top";
case r: return "bottom";
default: throw Error("unreachable");
}
}
S(K, "getExitSideFromRect");
function q(e, t, n = 5) {
let r = [];
switch (t) {
case "top":
r.push({
x: e.x - n,
y: e.y + n
}, {
x: e.x + n,
y: e.y + n
});
break;
case "bottom":
r.push({
x: e.x - n,
y: e.y - n
}, {
x: e.x + n,
y: e.y - n
});
break;
case "left":
r.push({
x: e.x + n,
y: e.y - n
}, {
x: e.x + n,
y: e.y + n
});
break;
case "right":
r.push({
x: e.x - n,
y: e.y - n
}, {
x: e.x - n,
y: e.y + n
});
break;
}
return r;
}
S(q, "getPaddedExitPoints");
function J(e) {
let { top: t, right: n, bottom: r, left: i } = e;
return [
{
x: i,
y: t
},
{
x: n,
y: t
},
{
x: n,
y: r
},
{
x: i,
y: r
}
];
}
S(J, "getPointsFromRect");
function Y(e, t) {
let { x: n, y: r } = e, i = !1;
for (let e = 0, a = t.length - 1; e < t.length; a = e++) {
let o = t[e], s = t[a], c = o.x, l = o.y, u = s.x, d = s.y;
l > r != d > r && n < (u - c) * (r - l) / (d - l) + c && (i = !i);
}
return i;
}
S(Y, "isPointInPolygon");
function X(e) {
let t = e.slice();
return t.sort((e, t) => e.x < t.x ? -1 : e.x > t.x ? 1 : e.y < t.y ? -1 : +(e.y > t.y)), Z(t);
}
S(X, "getHull");
function Z(e) {
if (e.length <= 1) return e.slice();
let t = [];
for (let n = 0; n < e.length; n++) {
let r = e[n];
for (; t.length >= 2;) {
let e = t[t.length - 1], n = t[t.length - 2];
if ((e.x - n.x) * (r.y - n.y) >= (e.y - n.y) * (r.x - n.x)) t.pop();
else break;
}
t.push(r);
}
t.pop();
let n = [];
for (let t = e.length - 1; t >= 0; t--) {
let r = e[t];
for (; n.length >= 2;) {
let e = n[n.length - 1], t = n[n.length - 2];
if ((e.x - t.x) * (r.y - t.y) >= (e.y - t.y) * (r.x - t.x)) n.pop();
else break;
}
n.push(r);
}
return n.pop(), t.length === 1 && n.length === 1 && t[0].x === n[0].x && t[0].y === n[0].y ? t : t.concat(n);
}
S(Z, "getHullPresorted");
var te = j, ne = F, re = L, ie = V, Q = U, ae = te, oe = ne, se = re, $ = v.forwardRef(({ className: t, inPortal: n = !1, sideOffset: r = 4, ...i }, a) => {
let o = /* @__PURE__ */ y(Q, {
...i,
ref: a,
sideOffset: r,
className: e("fade-in-0 zoom-in-95 data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 animate-in overflow-hidden border border-stroke bg-surface p-2 text-content-primary text-sm data-[state=closed]:animate-out", t)
});
return n ? /* @__PURE__ */ y(ie, { children: o }) : o;
});
$.displayName = Q.displayName;
//#endregion
export { se as i, $ as n, ae as r, oe as t };
//# sourceMappingURL=tooltip-Njs_wtm6.js.map