@gearbox-protocol/ui-kit 4.0.0-next.29 → 4.0.0-next.30
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.
- package/dist/cjs/components/base/leverage-input/leverage-input.cjs +1 -1
- package/dist/cjs/components/index.cjs +1 -1
- package/dist/cjs/components/slider/constants.cjs +1 -0
- package/dist/cjs/components/slider/index.cjs +1 -1
- package/dist/cjs/components/slider/slider-track.cjs +1 -1
- package/dist/cjs/components/slider/slider-utils.cjs +1 -1
- package/dist/cjs/components/slider/slider.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/components/base/leverage-input/leverage-input.js +10 -12
- package/dist/esm/components/index.js +199 -196
- package/dist/esm/components/slider/constants.js +6 -0
- package/dist/esm/components/slider/index.js +29 -26
- package/dist/esm/components/slider/slider-track.js +19 -17
- package/dist/esm/components/slider/slider-utils.js +37 -20
- package/dist/esm/components/slider/slider.js +53 -51
- package/dist/esm/index.js +450 -447
- package/dist/types/components/base/leverage-input/leverage-input.d.ts +4 -2
- package/dist/types/components/slider/constants.d.ts +3 -0
- package/dist/types/components/slider/index.d.ts +1 -0
- package/dist/types/components/slider/slider-utils.d.ts +27 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { SliderTest as o } from "./constants.js";
|
|
2
|
+
import { Slider as i } from "./slider.js";
|
|
3
|
+
import { SliderProvider as l, useSliderContext as m } from "./slider-context.js";
|
|
4
|
+
import { SliderMark as d } from "./slider-mark.js";
|
|
5
|
+
import { SliderTrack as n } from "./slider-track.js";
|
|
6
|
+
import { makeMarkerPoints as x, resolveSnap as M, validateMarkerPoints as S } from "./slider-utils.js";
|
|
7
|
+
import { THEME_COLOR_MAP as T, THUMB_HALF as k, THUMB_SIZE as u, getIntervalBounds as P, getThumbInBoundsOffset as c, resolveColor as B } from "./types.js";
|
|
8
|
+
import { decimalsToStep as H, findClosestPoint as I, formatWithDecimals as _, formatWithoutDecimals as h, splitInterval as E, validateMinMax as O } from "../../utils/math.js";
|
|
8
9
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
i as Slider,
|
|
11
|
+
d as SliderMark,
|
|
12
|
+
l as SliderProvider,
|
|
13
|
+
o as SliderTest,
|
|
14
|
+
n as SliderTrack,
|
|
15
|
+
T as THEME_COLOR_MAP,
|
|
16
|
+
k as THUMB_HALF,
|
|
17
|
+
u as THUMB_SIZE,
|
|
18
|
+
H as decimalsToStep,
|
|
19
|
+
I as findClosestPoint,
|
|
20
|
+
_ as formatWithDecimals,
|
|
21
|
+
h as formatWithoutDecimals,
|
|
22
|
+
P as getIntervalBounds,
|
|
23
|
+
c as getThumbInBoundsOffset,
|
|
24
|
+
x as makeMarkerPoints,
|
|
25
|
+
B as resolveColor,
|
|
26
|
+
M as resolveSnap,
|
|
27
|
+
E as splitInterval,
|
|
28
|
+
m as useSliderContext,
|
|
29
|
+
S as validateMarkerPoints,
|
|
30
|
+
O as validateMinMax
|
|
28
31
|
};
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
import { jsx as s, Fragment as m } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { useMemo as d } from "react";
|
|
3
|
+
import { SliderTest as f } from "./constants.js";
|
|
4
|
+
import { useSliderContext as v } from "./slider-context.js";
|
|
5
|
+
import { getIntervalBounds as p, resolveColor as h } from "./types.js";
|
|
6
|
+
function C() {
|
|
7
|
+
const r = v();
|
|
7
8
|
if (!r) return null;
|
|
8
|
-
const { colorIntervals: t, min:
|
|
9
|
+
const { colorIntervals: t, min: o, max: n } = r;
|
|
9
10
|
if (!t?.length) return null;
|
|
10
|
-
const e =
|
|
11
|
-
return e <= 0 ? null : /* @__PURE__ */ s(
|
|
11
|
+
const e = n - o;
|
|
12
|
+
return e <= 0 ? null : /* @__PURE__ */ s(x, { intervals: t, range: e, min: o });
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function x({
|
|
14
15
|
intervals: r,
|
|
15
16
|
range: t,
|
|
16
|
-
min:
|
|
17
|
+
min: o
|
|
17
18
|
}) {
|
|
18
|
-
const
|
|
19
|
+
const n = d(
|
|
19
20
|
() => [...r || []].reverse(),
|
|
20
21
|
[r]
|
|
21
22
|
);
|
|
22
|
-
return /* @__PURE__ */ s(m, { children:
|
|
23
|
-
const { start: l, end:
|
|
23
|
+
return /* @__PURE__ */ s(m, { children: n.map((e, c) => {
|
|
24
|
+
const { start: l, end: i } = p(e), a = (l - o) / t * 100, u = (i - l) / t * 100;
|
|
24
25
|
return /* @__PURE__ */ s(
|
|
25
26
|
"div",
|
|
26
27
|
{
|
|
28
|
+
"data-testid": f.interval,
|
|
27
29
|
className: "absolute h-full",
|
|
28
30
|
style: {
|
|
29
|
-
left: `${
|
|
30
|
-
width: `${
|
|
31
|
+
left: `${a}%`,
|
|
32
|
+
width: `${u}%`,
|
|
31
33
|
backgroundColor: h(e.color) ?? "hsl(var(--success))"
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
|
-
`interval-${
|
|
36
|
+
`interval-${c}-${l}-${i}`
|
|
35
37
|
);
|
|
36
38
|
}) });
|
|
37
39
|
}
|
|
38
40
|
export {
|
|
39
|
-
|
|
41
|
+
C as SliderTrack
|
|
40
42
|
};
|
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
import { splitInterval as
|
|
2
|
-
import { decimalsToStep as
|
|
3
|
-
function
|
|
1
|
+
import { splitInterval as h, findClosestPoint as M, formatWithoutDecimals as m } from "../../utils/math.js";
|
|
2
|
+
import { decimalsToStep as g, formatWithDecimals as D, validateMinMax as P } from "../../utils/math.js";
|
|
3
|
+
function k(t, e, s) {
|
|
4
4
|
if (t.length === 0) return t;
|
|
5
5
|
const o = t.length - 1, r = {
|
|
6
|
-
point: Math.max(t[0].point,
|
|
6
|
+
point: Math.max(t[0].point, e),
|
|
7
7
|
type: t[0].type
|
|
8
|
-
},
|
|
9
|
-
point: Math.min(t[o].point,
|
|
8
|
+
}, c = {
|
|
9
|
+
point: Math.min(t[o].point, s),
|
|
10
10
|
type: t[o].type
|
|
11
|
-
},
|
|
12
|
-
return [r, ...Object.values(
|
|
11
|
+
}, p = t.slice(1, o).reduce((i, n) => (n.point !== r.point && n.point !== c.point && (i[n.point] = n), i), {});
|
|
12
|
+
return [r, ...Object.values(p), c];
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
14
|
+
function u(t, e, s, o, r) {
|
|
15
|
+
const c = m(t, s, 1), i = h(c, e, r).map(
|
|
16
16
|
(n) => ({
|
|
17
|
-
point:
|
|
17
|
+
point: m(n, s, o),
|
|
18
18
|
type: "base"
|
|
19
19
|
})
|
|
20
20
|
);
|
|
21
|
-
return
|
|
21
|
+
return k(i, t, e);
|
|
22
|
+
}
|
|
23
|
+
function y(t, { snapPoints: e, intervals: s, epsilon: o, decimals: r }) {
|
|
24
|
+
const { minDistance: c, minPoint: p } = M(
|
|
25
|
+
t,
|
|
26
|
+
[...e],
|
|
27
|
+
r
|
|
28
|
+
);
|
|
29
|
+
if (c >= o)
|
|
30
|
+
return t;
|
|
31
|
+
let i, n = o;
|
|
32
|
+
for (const a of e) {
|
|
33
|
+
const f = Math.abs(a - t);
|
|
34
|
+
f < n && (i = a, n = f);
|
|
35
|
+
}
|
|
36
|
+
const d = s?.some((a) => p >= a.start && p <= a.end);
|
|
37
|
+
return i !== void 0 && !d ? i : p;
|
|
22
38
|
}
|
|
23
39
|
export {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
g as decimalsToStep,
|
|
41
|
+
M as findClosestPoint,
|
|
42
|
+
D as formatWithDecimals,
|
|
43
|
+
m as formatWithoutDecimals,
|
|
44
|
+
u as makeMarkerPoints,
|
|
45
|
+
y as resolveSnap,
|
|
46
|
+
h as splitInterval,
|
|
47
|
+
k as validateMarkerPoints,
|
|
48
|
+
P as validateMinMax
|
|
32
49
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as o, jsxs as W } from "react/jsx-runtime";
|
|
2
2
|
import { LEVERAGE_DECIMALS as F } from "@gearbox-protocol/sdk/onchain";
|
|
3
3
|
import * as P from "@radix-ui/react-slider";
|
|
4
4
|
import * as H from "react";
|
|
@@ -6,14 +6,14 @@ import { useMemo as m, useRef as w, useCallback as J, useState as K, useLayoutEf
|
|
|
6
6
|
import { cn as y } from "../../utils/cn.js";
|
|
7
7
|
import "sonner";
|
|
8
8
|
import "@gearbox-protocol/sdk/common-utils";
|
|
9
|
-
import {
|
|
9
|
+
import { validateMinMax as X } from "../../utils/math.js";
|
|
10
10
|
import "luxon";
|
|
11
11
|
import "../../utils/z-index.js";
|
|
12
|
-
import { SliderProvider as
|
|
13
|
-
import { SliderMark as
|
|
14
|
-
import { SliderTrack as
|
|
15
|
-
import { makeMarkerPoints as te } from "./slider-utils.js";
|
|
16
|
-
import { getIntervalBounds as ne, getThumbInBoundsOffset as
|
|
12
|
+
import { SliderProvider as Y } from "./slider-context.js";
|
|
13
|
+
import { SliderMark as Z } from "./slider-mark.js";
|
|
14
|
+
import { SliderTrack as I } from "./slider-track.js";
|
|
15
|
+
import { makeMarkerPoints as ee, resolveSnap as te } from "./slider-utils.js";
|
|
16
|
+
import { getIntervalBounds as ne, getThumbInBoundsOffset as D } from "./types.js";
|
|
17
17
|
const M = Number(F), re = H.forwardRef(
|
|
18
18
|
({
|
|
19
19
|
className: O,
|
|
@@ -22,67 +22,69 @@ const M = Number(F), re = H.forwardRef(
|
|
|
22
22
|
value: _,
|
|
23
23
|
onChangeValue: N,
|
|
24
24
|
onSubmitValue: g,
|
|
25
|
-
colorIntervals:
|
|
25
|
+
colorIntervals: n,
|
|
26
26
|
precision: h = 10,
|
|
27
27
|
markerStep: v = 100,
|
|
28
28
|
epsilon: j = 8,
|
|
29
|
-
colorIntervalLabel:
|
|
29
|
+
colorIntervalLabel: L,
|
|
30
30
|
...z
|
|
31
31
|
}, B) => {
|
|
32
|
-
const [
|
|
33
|
-
() =>
|
|
34
|
-
[
|
|
35
|
-
),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
const [r, s] = u > p ? [p, u] : [u, p], d = Array.isArray(h) ? h[0] : h, $ = m(() => M / d, [d]), G = m(
|
|
33
|
+
() => n?.flatMap((e) => [e.start, e.end]) || [],
|
|
34
|
+
[n]
|
|
35
|
+
), C = (e) => X(
|
|
36
|
+
te(e, {
|
|
37
|
+
snapPoints: G,
|
|
38
|
+
intervals: n,
|
|
39
|
+
epsilon: j,
|
|
40
|
+
decimals: M
|
|
41
|
+
}),
|
|
42
|
+
r,
|
|
43
|
+
s
|
|
44
|
+
), U = (e) => {
|
|
45
|
+
e.length > 0 && N(C(e[0]));
|
|
44
46
|
}, V = (e) => {
|
|
45
|
-
g && e.length > 0 && g(
|
|
46
|
-
}, b = m(() => v ?
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
g && e.length > 0 && g(C(e[0]));
|
|
48
|
+
}, b = m(() => v ? ee(
|
|
49
|
+
r,
|
|
50
|
+
s,
|
|
49
51
|
M,
|
|
50
52
|
d,
|
|
51
53
|
v
|
|
52
|
-
).map((t) => t.point) : void 0, [
|
|
54
|
+
).map((t) => t.point) : void 0, [r, s, d, v]), E = w(null), q = J(() => {
|
|
53
55
|
const e = E.current;
|
|
54
56
|
if (!e) return;
|
|
55
57
|
const t = () => {
|
|
56
58
|
e.dataset.dragging = "";
|
|
57
|
-
},
|
|
59
|
+
}, a = () => {
|
|
58
60
|
document.removeEventListener("pointermove", t), delete e.dataset.dragging;
|
|
59
61
|
};
|
|
60
|
-
document.addEventListener("pointermove", t, { once: !0 }), document.addEventListener("pointerup",
|
|
62
|
+
document.addEventListener("pointermove", t, { once: !0 }), document.addEventListener("pointerup", a, { once: !0 });
|
|
61
63
|
}, []), R = w(null), k = w(null), [S, A] = K(void 0), f = m(() => {
|
|
62
|
-
if (!
|
|
63
|
-
const e =
|
|
64
|
-
if (
|
|
65
|
-
const c = (t -
|
|
64
|
+
if (!n?.length) return;
|
|
65
|
+
const e = n[n.length - 1], { start: t, end: a } = ne(e), i = s - r;
|
|
66
|
+
if (i <= 0) return;
|
|
67
|
+
const c = (t - r) / i * 100, l = (a - r) / i * 100, T = D(c), x = D(l);
|
|
66
68
|
return {
|
|
67
69
|
pct: (c + l) / 2,
|
|
68
|
-
offsetPx: (
|
|
70
|
+
offsetPx: (T + x) / 2
|
|
69
71
|
};
|
|
70
|
-
}, [
|
|
72
|
+
}, [n, r, s]);
|
|
71
73
|
return Q(() => {
|
|
72
74
|
const e = R.current, t = k.current;
|
|
73
75
|
if (!f || !e || !t) {
|
|
74
76
|
A(void 0);
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
|
-
const
|
|
79
|
+
const a = () => {
|
|
78
80
|
const c = e.offsetWidth, l = t.offsetWidth, x = f.pct / 100 * c + f.offsetPx - l / 2;
|
|
79
81
|
A(Math.max(0, Math.min(x, c - l)));
|
|
80
82
|
};
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
return
|
|
84
|
-
}, [f]), /* @__PURE__ */
|
|
85
|
-
/* @__PURE__ */
|
|
83
|
+
a();
|
|
84
|
+
const i = new ResizeObserver(a);
|
|
85
|
+
return i.observe(e), () => i.disconnect();
|
|
86
|
+
}, [f]), /* @__PURE__ */ o(Y, { colorIntervals: n, min: r, max: s, children: /* @__PURE__ */ W("div", { className: "relative w-full px-[9px] pb-3", children: [
|
|
87
|
+
/* @__PURE__ */ o(
|
|
86
88
|
"div",
|
|
87
89
|
{
|
|
88
90
|
ref: E,
|
|
@@ -93,7 +95,7 @@ const M = Number(F), re = H.forwardRef(
|
|
|
93
95
|
"[&:not([data-dragging])_span[style]]:[transition-timing-function:cubic-bezier(0.25,0.1,0.25,1)]"
|
|
94
96
|
),
|
|
95
97
|
onPointerDown: q,
|
|
96
|
-
children: /* @__PURE__ */
|
|
98
|
+
children: /* @__PURE__ */ W(
|
|
97
99
|
P.Root,
|
|
98
100
|
{
|
|
99
101
|
ref: B,
|
|
@@ -101,28 +103,28 @@ const M = Number(F), re = H.forwardRef(
|
|
|
101
103
|
"relative flex w-full touch-none select-none items-center",
|
|
102
104
|
O
|
|
103
105
|
),
|
|
104
|
-
min:
|
|
105
|
-
max:
|
|
106
|
+
min: r,
|
|
107
|
+
max: s,
|
|
106
108
|
step: $,
|
|
107
109
|
value: [_],
|
|
108
110
|
onValueChange: U,
|
|
109
111
|
onValueCommit: V,
|
|
110
112
|
...z,
|
|
111
113
|
children: [
|
|
112
|
-
/* @__PURE__ */
|
|
113
|
-
b && b.length > 0 && /* @__PURE__ */
|
|
114
|
-
|
|
114
|
+
/* @__PURE__ */ o(P.Track, { className: "relative h-1 grow overflow-hidden bg-gray-40 mx-[9px] cursor-pointer", children: /* @__PURE__ */ o(I, {}) }),
|
|
115
|
+
b && b.length > 0 && /* @__PURE__ */ o("div", { className: "absolute inset-0 pointer-events-none flex items-center", children: /* @__PURE__ */ o("div", { className: "relative w-full", children: b.map((e) => /* @__PURE__ */ o(
|
|
116
|
+
Z,
|
|
115
117
|
{
|
|
116
118
|
value: e,
|
|
117
|
-
min:
|
|
118
|
-
max:
|
|
119
|
+
min: r,
|
|
120
|
+
max: s,
|
|
119
121
|
onSelect: (t) => {
|
|
120
122
|
N(t), g?.(t);
|
|
121
123
|
}
|
|
122
124
|
},
|
|
123
125
|
`mark-${e}`
|
|
124
126
|
)) }) }),
|
|
125
|
-
/* @__PURE__ */
|
|
127
|
+
/* @__PURE__ */ o(
|
|
126
128
|
P.Thumb,
|
|
127
129
|
{
|
|
128
130
|
className: y(
|
|
@@ -140,13 +142,13 @@ const M = Number(F), re = H.forwardRef(
|
|
|
140
142
|
)
|
|
141
143
|
}
|
|
142
144
|
),
|
|
143
|
-
|
|
145
|
+
L && n && n.length > 0 && /* @__PURE__ */ o("div", { ref: R, className: "relative h-[14px] mt-2.5", children: /* @__PURE__ */ o(
|
|
144
146
|
"div",
|
|
145
147
|
{
|
|
146
148
|
ref: k,
|
|
147
149
|
className: "absolute text-[11px] font-medium leading-[126%] text-success whitespace-nowrap",
|
|
148
150
|
style: S !== void 0 ? { left: `${S}px` } : void 0,
|
|
149
|
-
children:
|
|
151
|
+
children: L
|
|
150
152
|
}
|
|
151
153
|
) })
|
|
152
154
|
] }) });
|