@gearbox-protocol/ui-kit 4.0.0-next.28 → 4.0.0-next.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),J=require("@radix-ui/react-tooltip"),Q=require("react");require("@gearbox-protocol/sdk/onchain");const h=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");const U=require("../../utils/z-index.cjs");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),J=require("@radix-ui/react-tooltip"),Q=require("react");require("@gearbox-protocol/sdk/onchain");const h=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");const U=require("../../utils/z-index.cjs");function L(c){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const i in c)if(i!=="default"){const t=Object.getOwnPropertyDescriptor(c,i);Object.defineProperty(s,i,t.get?t:{enumerable:!0,get:()=>c[i]})}}return s.default=c,Object.freeze(s)}const l=L(J),e=L(Q),N=e.createContext({lockParent:()=>{},unlockParent:()=>{}}),S=e.createContext(!1),I=7,Y=12;function z({children:c,title:s,placement:i="top",trigger:t="hover",triangle:A=!0,delayShow:v=5,maxWidth:P="200px",minWidth:b,type:H="tooltip",open:y,onOpenChange:C,className:M,triggerClassName:T,useTitleAsTrigger:K=!1}){const[W,B]=e.useState(!1),[w,R]=e.useState(!1),m=e.useRef(null),f=e.useRef(null),k=y!==void 0,a=k?y:W,o=e.useCallback(n=>{k?C?.(n):B(n)},[k,C]),u=e.useContext(N),$=e.useMemo(()=>({lockParent:()=>R(!0),unlockParent:()=>R(!1)}),[]),j=e.useRef(!1);j.current=w;const d=e.useRef(null),p=e.useCallback(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null)},[]),G=e.useCallback(n=>{if(t!=="click"){if(n){p(),o(!0),u.lockParent();return}d.current=setTimeout(()=>{d.current=null,!j.current&&(o(!1),u.unlockParent())},100)}},[t,o,u,p]);e.useEffect(()=>p,[p]);const V=e.useCallback(n=>{t==="click"&&(n.stopPropagation(),o(!a))},[t,a,o]),X=e.useCallback(n=>{t==="click"&&(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),n.stopPropagation(),o(!a))},[t,a,o]);e.useEffect(()=>{if(t!=="click"||!a)return;const n=x=>{const g=x.target;m.current&&!m.current.contains(g)&&f.current&&!f.current.contains(g)&&o(!1)},q=x=>{x.key==="Escape"&&o(!1)};return document.addEventListener("pointerdown",n),document.addEventListener("keydown",q),()=>{document.removeEventListener("pointerdown",n),document.removeEventListener("keydown",q)}},[t,a,o]);const O=e.useRef(u.unlockParent);O.current=u.unlockParent,e.useEffect(()=>()=>O.current(),[]);const D=H==="modal-tooltip",E=A&&!D,Z=h.cn(U.Z_INDEX.TOOLTIP,"pointer-events-auto","animate-in fade-in-0 zoom-in-75 duration-150","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-75 data-[state=closed]:duration-150",D?"bg-transparent p-0":"rounded bg-black/85 px-2 py-1 text-[0.85rem] leading-[1.5] font-normal text-center text-white/85 antialiased break-words min-w-0",M),F=e.useContext(S),_=r.jsxs(l.Root,{open:a||w,onOpenChange:G,delayDuration:t==="click"?0:v,children:[r.jsx(l.Trigger,{asChild:!0,children:K?s:t==="click"?r.jsx("button",{ref:f,type:"button",onClick:V,onKeyDown:X,className:h.cn("inline-flex appearance-none border-0 bg-transparent p-0 text-inherit font-inherit cursor-pointer",T),children:s}):r.jsx("span",{ref:f,className:h.cn("inline-flex",T),children:s})}),r.jsx(l.Portal,{children:r.jsxs(l.Content,{ref:m,side:i,sideOffset:E?I-4:8,collisionPadding:8,className:Z,style:{maxWidth:P?`min(${P}, calc(100vw - 16px))`:"calc(100vw - 16px)",minWidth:b?`min(${b}, calc(100vw - 16px))`:void 0},children:[r.jsx(N.Provider,{value:$,children:c}),E&&r.jsx(l.Arrow,{width:Y,height:I,className:"fill-black/85"})]})})]});return F?_:r.jsx(S.Provider,{value:!0,children:r.jsx(l.Provider,{delayDuration:t==="click"?0:v,skipDelayDuration:300,children:_})})}z.displayName="SimpleTooltip";exports.SimpleTooltip=z;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as I, jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import * as a from "@radix-ui/react-tooltip";
|
|
3
3
|
import * as e from "react";
|
|
4
4
|
import "@gearbox-protocol/sdk/onchain";
|
|
@@ -7,63 +7,63 @@ import "sonner";
|
|
|
7
7
|
import "@gearbox-protocol/sdk/common-utils";
|
|
8
8
|
import "luxon";
|
|
9
9
|
import { Z_INDEX as F } from "../../utils/z-index.js";
|
|
10
|
-
const
|
|
10
|
+
const A = e.createContext({ lockParent: () => {
|
|
11
11
|
}, unlockParent: () => {
|
|
12
|
-
} }),
|
|
12
|
+
} }), H = e.createContext(!1), K = 7, J = 12;
|
|
13
13
|
function Q({
|
|
14
|
-
children:
|
|
14
|
+
children: S,
|
|
15
15
|
title: d,
|
|
16
|
-
placement:
|
|
16
|
+
placement: W = "top",
|
|
17
17
|
trigger: n = "hover",
|
|
18
|
-
triangle:
|
|
18
|
+
triangle: _ = !0,
|
|
19
19
|
delayShow: h = 5,
|
|
20
|
-
maxWidth:
|
|
21
|
-
minWidth:
|
|
20
|
+
maxWidth: v = "200px",
|
|
21
|
+
minWidth: C,
|
|
22
22
|
type: j = "tooltip",
|
|
23
|
-
open:
|
|
24
|
-
onOpenChange:
|
|
23
|
+
open: x,
|
|
24
|
+
onOpenChange: P,
|
|
25
25
|
className: z,
|
|
26
|
-
triggerClassName:
|
|
26
|
+
triggerClassName: w,
|
|
27
27
|
useTitleAsTrigger: B = !1
|
|
28
28
|
}) {
|
|
29
|
-
const [M,
|
|
29
|
+
const [M, $] = e.useState(!1), [y, R] = e.useState(!1), f = e.useRef(null), l = e.useRef(null), p = x !== void 0, c = p ? x : M, o = e.useCallback(
|
|
30
30
|
(t) => {
|
|
31
|
-
p ?
|
|
31
|
+
p ? P?.(t) : $(t);
|
|
32
32
|
},
|
|
33
|
-
[p,
|
|
34
|
-
), s = e.useContext(
|
|
33
|
+
[p, P]
|
|
34
|
+
), s = e.useContext(A), g = e.useMemo(
|
|
35
35
|
() => ({
|
|
36
|
-
lockParent: () =>
|
|
37
|
-
unlockParent: () =>
|
|
36
|
+
lockParent: () => R(!0),
|
|
37
|
+
unlockParent: () => R(!1)
|
|
38
38
|
}),
|
|
39
39
|
[]
|
|
40
|
-
),
|
|
41
|
-
|
|
42
|
-
const
|
|
40
|
+
), T = e.useRef(!1);
|
|
41
|
+
T.current = y;
|
|
42
|
+
const i = e.useRef(
|
|
43
43
|
null
|
|
44
44
|
), u = e.useCallback(() => {
|
|
45
|
-
|
|
46
|
-
}, []),
|
|
45
|
+
i.current !== null && (clearTimeout(i.current), i.current = null);
|
|
46
|
+
}, []), G = e.useCallback(
|
|
47
47
|
(t) => {
|
|
48
48
|
if (n !== "click") {
|
|
49
49
|
if (t) {
|
|
50
50
|
u(), o(!0), s.lockParent();
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
i.current = setTimeout(() => {
|
|
54
|
+
i.current = null, !T.current && (o(!1), s.unlockParent());
|
|
55
55
|
}, 100);
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
[n, o, s, u]
|
|
59
59
|
);
|
|
60
60
|
e.useEffect(() => u, [u]);
|
|
61
|
-
const
|
|
61
|
+
const V = e.useCallback(
|
|
62
62
|
(t) => {
|
|
63
63
|
n === "click" && (t.stopPropagation(), o(!c));
|
|
64
64
|
},
|
|
65
65
|
[n, c, o]
|
|
66
|
-
),
|
|
66
|
+
), X = e.useCallback(
|
|
67
67
|
(t) => {
|
|
68
68
|
n === "click" && (t.key === "Enter" || t.key === " ") && (t.preventDefault(), t.stopPropagation(), o(!c));
|
|
69
69
|
},
|
|
@@ -72,71 +72,73 @@ function Q({
|
|
|
72
72
|
e.useEffect(() => {
|
|
73
73
|
if (n !== "click" || !c) return;
|
|
74
74
|
const t = (m) => {
|
|
75
|
-
const
|
|
76
|
-
f.current && !f.current.contains(
|
|
77
|
-
},
|
|
75
|
+
const L = m.target;
|
|
76
|
+
f.current && !f.current.contains(L) && l.current && !l.current.contains(L) && o(!1);
|
|
77
|
+
}, N = (m) => {
|
|
78
78
|
m.key === "Escape" && o(!1);
|
|
79
79
|
};
|
|
80
|
-
return document.addEventListener("pointerdown", t), document.addEventListener("keydown",
|
|
81
|
-
document.removeEventListener("pointerdown", t), document.removeEventListener("keydown",
|
|
80
|
+
return document.addEventListener("pointerdown", t), document.addEventListener("keydown", N), () => {
|
|
81
|
+
document.removeEventListener("pointerdown", t), document.removeEventListener("keydown", N);
|
|
82
82
|
};
|
|
83
83
|
}, [n, c, o]);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
84
|
+
const b = e.useRef(s.unlockParent);
|
|
85
|
+
b.current = s.unlockParent, e.useEffect(() => () => b.current(), []);
|
|
86
|
+
const D = j === "modal-tooltip", E = _ && !D, Z = k(
|
|
87
87
|
F.TOOLTIP,
|
|
88
88
|
"pointer-events-auto",
|
|
89
89
|
"animate-in fade-in-0 zoom-in-75 duration-150",
|
|
90
90
|
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-75 data-[state=closed]:duration-150",
|
|
91
|
-
|
|
91
|
+
D ? "bg-transparent p-0" : "rounded bg-black/85 px-2 py-1 text-[0.85rem] leading-[1.5] font-normal text-center text-white/85 antialiased break-words min-w-0",
|
|
92
92
|
z
|
|
93
|
-
), q = e.useContext(
|
|
93
|
+
), q = e.useContext(H), O = /* @__PURE__ */ I(
|
|
94
94
|
a.Root,
|
|
95
95
|
{
|
|
96
96
|
open: c || y,
|
|
97
|
-
onOpenChange:
|
|
97
|
+
onOpenChange: G,
|
|
98
98
|
delayDuration: n === "click" ? 0 : h,
|
|
99
99
|
children: [
|
|
100
100
|
/* @__PURE__ */ r(a.Trigger, { asChild: !0, children: B ? d : n === "click" ? /* @__PURE__ */ r(
|
|
101
101
|
"button",
|
|
102
102
|
{
|
|
103
|
-
ref:
|
|
103
|
+
ref: l,
|
|
104
104
|
type: "button",
|
|
105
|
-
onClick:
|
|
106
|
-
onKeyDown:
|
|
105
|
+
onClick: V,
|
|
106
|
+
onKeyDown: X,
|
|
107
107
|
className: k(
|
|
108
108
|
"inline-flex appearance-none border-0 bg-transparent p-0 text-inherit font-inherit cursor-pointer",
|
|
109
|
-
|
|
109
|
+
w
|
|
110
110
|
),
|
|
111
111
|
children: d
|
|
112
112
|
}
|
|
113
113
|
) : /* @__PURE__ */ r(
|
|
114
114
|
"span",
|
|
115
115
|
{
|
|
116
|
-
ref:
|
|
117
|
-
className: k("inline-flex",
|
|
116
|
+
ref: l,
|
|
117
|
+
className: k("inline-flex", w),
|
|
118
118
|
children: d
|
|
119
119
|
}
|
|
120
120
|
) }),
|
|
121
|
-
/* @__PURE__ */ r(a.Portal, { children: /* @__PURE__ */
|
|
121
|
+
/* @__PURE__ */ r(a.Portal, { children: /* @__PURE__ */ I(
|
|
122
122
|
a.Content,
|
|
123
123
|
{
|
|
124
124
|
ref: f,
|
|
125
|
-
side:
|
|
126
|
-
sideOffset:
|
|
125
|
+
side: W,
|
|
126
|
+
sideOffset: E ? K - 4 : 8,
|
|
127
127
|
collisionPadding: 8,
|
|
128
|
-
className:
|
|
128
|
+
className: Z,
|
|
129
129
|
style: {
|
|
130
|
-
maxWidth:
|
|
131
|
-
|
|
130
|
+
maxWidth: v ? `min(${v}, calc(100vw - 16px))` : "calc(100vw - 16px)",
|
|
131
|
+
// min-width wins over max-width in CSS; cap it the same way or a
|
|
132
|
+
// 400px breakdown overflows a phone.
|
|
133
|
+
minWidth: C ? `min(${C}, calc(100vw - 16px))` : void 0
|
|
132
134
|
},
|
|
133
135
|
children: [
|
|
134
|
-
/* @__PURE__ */ r(
|
|
135
|
-
|
|
136
|
+
/* @__PURE__ */ r(A.Provider, { value: g, children: S }),
|
|
137
|
+
E && /* @__PURE__ */ r(
|
|
136
138
|
a.Arrow,
|
|
137
139
|
{
|
|
138
140
|
width: J,
|
|
139
|
-
height:
|
|
141
|
+
height: K,
|
|
140
142
|
className: "fill-black/85"
|
|
141
143
|
}
|
|
142
144
|
)
|
|
@@ -146,12 +148,12 @@ function Q({
|
|
|
146
148
|
]
|
|
147
149
|
}
|
|
148
150
|
);
|
|
149
|
-
return q ?
|
|
151
|
+
return q ? O : /* @__PURE__ */ r(H.Provider, { value: !0, children: /* @__PURE__ */ r(
|
|
150
152
|
a.Provider,
|
|
151
153
|
{
|
|
152
154
|
delayDuration: n === "click" ? 0 : h,
|
|
153
155
|
skipDelayDuration: 300,
|
|
154
|
-
children:
|
|
156
|
+
children: O
|
|
155
157
|
}
|
|
156
158
|
) });
|
|
157
159
|
}
|