prometeo-design-system 2.5.3 → 2.5.4
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/DrawerMobile.es.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
import { j as g } from "./jsx-runtime-DKDX3adD.js";
|
|
2
|
-
import { c as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { createPortal as
|
|
5
|
-
const
|
|
6
|
-
const { children:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, [
|
|
10
|
-
|
|
11
|
-
}, [
|
|
2
|
+
import { c as W } from "./cn-B6yFEsav.js";
|
|
3
|
+
import { forwardRef as K, useState as B, useRef as v, useEffect as F, useCallback as c, useMemo as J, useImperativeHandle as Q } from "react";
|
|
4
|
+
import { createPortal as U } from "react-dom";
|
|
5
|
+
const A = 44, V = "height 0.5s cubic-bezier(0.32, 0.72, 0, 1)", te = K((u, s) => {
|
|
6
|
+
const { children: y, defaultOpen: o = !1, onClose: a, snapPoints: d = ["60%"], setSnap: w, snap: p, attachToParent: O = !1 } = u, [E, x] = B(p || "0%"), [r, C] = B(null), Y = v(a), f = v(w), m = v(r);
|
|
7
|
+
Y.current = a, m.current = r, F(() => {
|
|
8
|
+
o && b();
|
|
9
|
+
}, [o]), F(() => {
|
|
10
|
+
f.current = w;
|
|
11
|
+
}, [w]);
|
|
12
12
|
const M = c(() => {
|
|
13
|
-
|
|
14
|
-
}, []),
|
|
15
|
-
console.log(
|
|
16
|
-
}, [d]), S =
|
|
17
|
-
|
|
18
|
-
open:
|
|
13
|
+
x("0%"), Y.current?.(m.current), setTimeout(() => C(null), 300);
|
|
14
|
+
}, []), b = c((H, N) => {
|
|
15
|
+
console.log(H || d[0] || "60%"), x(H || d[0] || "60%"), C(N ?? null);
|
|
16
|
+
}, [d]), S = J(() => E !== "0%", [E]);
|
|
17
|
+
Q(s, () => ({
|
|
18
|
+
open: b,
|
|
19
19
|
close: M,
|
|
20
20
|
isOpen: S,
|
|
21
|
-
getContext: () =>
|
|
22
|
-
}), [
|
|
23
|
-
const
|
|
24
|
-
return O ? /* @__PURE__ */ g.jsx(
|
|
25
|
-
}),
|
|
26
|
-
const r =
|
|
21
|
+
getContext: () => m.current
|
|
22
|
+
}), [b, M, S]);
|
|
23
|
+
const L = p || E;
|
|
24
|
+
return O ? /* @__PURE__ */ g.jsx(q, { ...u, snap: L, setSnap: x, context: r, children: y }) : U(/* @__PURE__ */ g.jsx(q, { ...u, snap: L, setSnap: x, context: r, children: y }), document.body);
|
|
25
|
+
}), q = ({ children: u, attachToParent: s = !1, className: y, snap: o, snapPoints: a = ["60%"], setSnap: d, hideOnClose: w = !1, header: p, modal: O = !1, closeOnOverlayClick: E = !1, context: x }) => {
|
|
26
|
+
const r = v(null), C = v(null), Y = v(null), f = v(null), m = v(null), M = c(() => {
|
|
27
27
|
if (!r.current) return [];
|
|
28
|
-
console.log(
|
|
29
|
-
const e =
|
|
30
|
-
return
|
|
31
|
-
}, [
|
|
32
|
-
const n =
|
|
28
|
+
console.log(a, "snapPoints");
|
|
29
|
+
const e = s && r.current.parentElement?.offsetHeight || window.innerHeight;
|
|
30
|
+
return a?.map((t) => typeof t == "string" && t.endsWith("%") ? parseFloat(t) > 100 ? e : parseFloat(t) / 100 * e : typeof t == "string" && t.endsWith("px") ? parseFloat(t) : typeof t == "number" && t >= 0 && t <= 1 ? t * e : typeof t == "number" ? t : 0) || [];
|
|
31
|
+
}, [a, s]), b = c((e, t) => {
|
|
32
|
+
const n = M();
|
|
33
33
|
if (n.length === 0) return e;
|
|
34
34
|
if (Math.abs(t) > 0.05)
|
|
35
35
|
if (t > 0) {
|
|
36
36
|
const l = n.filter((i) => i < e);
|
|
37
|
-
return l.length > 0 ? Math.max(...l) :
|
|
37
|
+
return l.length > 0 ? Math.max(...l) : w ? 0 : A;
|
|
38
38
|
} else {
|
|
39
39
|
const l = n.filter((i) => i > e);
|
|
40
40
|
if (l.length > 0)
|
|
41
41
|
return Math.min(...l);
|
|
42
42
|
}
|
|
43
43
|
return n.reduce((l, i) => Math.abs(i - e) < Math.abs(l - e) ? i : l);
|
|
44
|
-
}, [
|
|
45
|
-
if (d &&
|
|
46
|
-
const t =
|
|
44
|
+
}, [M]), S = c((e) => {
|
|
45
|
+
if (d && a) {
|
|
46
|
+
const t = s && r.current?.parentElement?.offsetHeight || window.innerHeight, n = e <= A ? "0%" : `${Math.round(e / t * 100)}%`;
|
|
47
47
|
d(n);
|
|
48
48
|
}
|
|
49
|
-
}, [d,
|
|
50
|
-
r.current && (r.current.style.transition =
|
|
51
|
-
}, [d,
|
|
52
|
-
if (
|
|
53
|
-
const { scrollY: e } =
|
|
54
|
-
document.body.style.position = "", document.body.style.top = "", document.body.style.width = "", window.scrollTo(0, e),
|
|
49
|
+
}, [d, a, s]), L = c((e) => {
|
|
50
|
+
r.current && (r.current.style.transition = V, r.current.style.height = `${e}px`);
|
|
51
|
+
}, [d, a, s]), R = c(() => {
|
|
52
|
+
if (m.current && s) {
|
|
53
|
+
const { scrollY: e } = m.current;
|
|
54
|
+
document.body.style.position = "", document.body.style.top = "", document.body.style.width = "", window.scrollTo(0, e), m.current = null;
|
|
55
55
|
}
|
|
56
|
-
}, [
|
|
56
|
+
}, [s]);
|
|
57
57
|
F(() => () => {
|
|
58
|
-
|
|
59
|
-
}, [
|
|
60
|
-
if (!r.current || !
|
|
61
|
-
console.log(
|
|
62
|
-
const e =
|
|
58
|
+
R();
|
|
59
|
+
}, [R]), F(() => {
|
|
60
|
+
if (!r.current || !o) return;
|
|
61
|
+
console.log(o, "new snap");
|
|
62
|
+
const e = s && r.current.parentElement?.offsetHeight || window.innerHeight;
|
|
63
63
|
let t = 0;
|
|
64
|
-
typeof
|
|
65
|
-
}, [
|
|
66
|
-
const
|
|
64
|
+
typeof o == "string" && o.endsWith("%") ? parseFloat(o) <= 0 ? t = w ? 0 : A : t = parseFloat(o) / 100 * e : typeof o == "string" && o.endsWith("px") ? t = parseFloat(o) : typeof o == "number" && (o >= 0 && o <= 1 ? t = o * e : t = o), L(t);
|
|
65
|
+
}, [o, s]);
|
|
66
|
+
const H = c((e) => {
|
|
67
67
|
if (!r.current) return;
|
|
68
68
|
const t = e.touches[0], n = r.current.offsetHeight;
|
|
69
|
-
|
|
69
|
+
f.current = {
|
|
70
70
|
isDragging: !1,
|
|
71
71
|
startY: t.clientY,
|
|
72
72
|
startHeight: n,
|
|
@@ -74,10 +74,10 @@ const W = 44, U = "height 0.5s cubic-bezier(0.32, 0.72, 0, 1)", ee = J((a, o) =>
|
|
|
74
74
|
lastTime: Date.now(),
|
|
75
75
|
velocity: 0
|
|
76
76
|
};
|
|
77
|
-
}, []),
|
|
77
|
+
}, []), N = c((e) => {
|
|
78
78
|
if (!r.current) return;
|
|
79
79
|
const t = e, n = r.current.offsetHeight;
|
|
80
|
-
|
|
80
|
+
f.current = {
|
|
81
81
|
isDragging: !1,
|
|
82
82
|
startY: t.clientY,
|
|
83
83
|
startHeight: n,
|
|
@@ -85,67 +85,67 @@ const W = 44, U = "height 0.5s cubic-bezier(0.32, 0.72, 0, 1)", ee = J((a, o) =>
|
|
|
85
85
|
lastTime: Date.now(),
|
|
86
86
|
velocity: 0
|
|
87
87
|
};
|
|
88
|
-
}, []),
|
|
89
|
-
if (!
|
|
90
|
-
const t = e.touches[0], n =
|
|
91
|
-
if (!n.isDragging && l && (n.isDragging = !0,
|
|
88
|
+
}, []), I = c((e) => {
|
|
89
|
+
if (!f.current || !r.current) return;
|
|
90
|
+
const t = e.touches[0], n = f.current, D = n.startY - t.clientY, l = n.isDragging || Math.abs(D) > 5;
|
|
91
|
+
if (!n.isDragging && l && (n.isDragging = !0, s)) {
|
|
92
92
|
const i = window.scrollY;
|
|
93
|
-
|
|
93
|
+
m.current = { scrollY: i }, document.body.style.position = "fixed", document.body.style.top = `-${i}px`, document.body.style.width = "100%";
|
|
94
94
|
}
|
|
95
95
|
if (l) {
|
|
96
96
|
e.preventDefault();
|
|
97
97
|
const i = Date.now(), j = i - n.lastTime;
|
|
98
98
|
if (j > 0) {
|
|
99
|
-
const
|
|
100
|
-
n.velocity = n.velocity * 0.8 +
|
|
99
|
+
const G = (t.clientY - n.lastY) / j;
|
|
100
|
+
n.velocity = n.velocity * 0.8 + G * 0.2;
|
|
101
101
|
}
|
|
102
102
|
n.lastY = t.clientY, n.lastTime = i;
|
|
103
|
-
const
|
|
104
|
-
r.current.style.transition = "none", r.current.style.height = `${
|
|
103
|
+
const T = n.startHeight + D, $ = s && r.current.parentElement?.offsetHeight || window.innerHeight, z = Math.max(0, Math.min(T, $));
|
|
104
|
+
r.current.style.transition = "none", r.current.style.height = `${z}px`;
|
|
105
105
|
}
|
|
106
|
-
}, [
|
|
107
|
-
if (!
|
|
108
|
-
const t = e, n =
|
|
109
|
-
if (!n.isDragging && l && (n.isDragging = !0,
|
|
106
|
+
}, [s]), _ = c((e) => {
|
|
107
|
+
if (!f.current || !r.current) return;
|
|
108
|
+
const t = e, n = f.current, D = n.startY - t.clientY, l = n.isDragging || Math.abs(D) > 5;
|
|
109
|
+
if (!n.isDragging && l && (n.isDragging = !0, s)) {
|
|
110
110
|
const i = window.scrollY;
|
|
111
|
-
|
|
111
|
+
m.current = { scrollY: i }, document.body.style.position = "fixed", document.body.style.top = `-${i}px`, document.body.style.width = "100%";
|
|
112
112
|
}
|
|
113
113
|
if (l) {
|
|
114
114
|
e.preventDefault();
|
|
115
115
|
const i = Date.now(), j = i - n.lastTime;
|
|
116
116
|
if (j > 0) {
|
|
117
|
-
const
|
|
118
|
-
n.velocity = n.velocity * 0.8 +
|
|
117
|
+
const G = (t.clientY - n.lastY) / j;
|
|
118
|
+
n.velocity = n.velocity * 0.8 + G * 0.2;
|
|
119
119
|
}
|
|
120
120
|
n.lastY = t.clientY, n.lastTime = i;
|
|
121
|
-
const
|
|
122
|
-
r.current.style.transition = "none", r.current.style.height = `${
|
|
121
|
+
const T = n.startHeight + D, $ = s && r.current.parentElement?.offsetHeight || window.innerHeight, z = Math.max(0, Math.min(T, $));
|
|
122
|
+
r.current.style.transition = "none", r.current.style.height = `${z}px`;
|
|
123
123
|
}
|
|
124
|
-
}, [
|
|
125
|
-
if (!
|
|
126
|
-
const e =
|
|
124
|
+
}, [s]), h = c(() => {
|
|
125
|
+
if (!f.current || !r.current) return;
|
|
126
|
+
const e = f.current;
|
|
127
127
|
if (e.isDragging) {
|
|
128
|
-
|
|
129
|
-
const t = r.current.offsetHeight, n =
|
|
130
|
-
|
|
128
|
+
R();
|
|
129
|
+
const t = r.current.offsetHeight, n = b(t, e.velocity);
|
|
130
|
+
S(n);
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
}, [
|
|
132
|
+
f.current = null;
|
|
133
|
+
}, [b, L, R]);
|
|
134
134
|
F(() => {
|
|
135
135
|
const e = Y.current;
|
|
136
136
|
if (e)
|
|
137
|
-
return e.addEventListener("touchstart",
|
|
138
|
-
e.removeEventListener("touchstart",
|
|
137
|
+
return e.addEventListener("touchstart", H, { passive: !1 }), e.addEventListener("touchmove", I, { passive: !1 }), e.addEventListener("touchend", h), e.addEventListener("touchcancel", h), e.addEventListener("mousedown", N, { passive: !1 }), e.addEventListener("mousemove", _, { passive: !1 }), e.addEventListener("mouseup", h), e.addEventListener("mouseleave", h), () => {
|
|
138
|
+
e.removeEventListener("touchstart", H), e.removeEventListener("touchmove", I), e.removeEventListener("touchend", h), e.removeEventListener("touchcancel", h), e.removeEventListener("mousedown", N), e.removeEventListener("mousemove", _), e.removeEventListener("mouseup", h), e.removeEventListener("mouseleave", h);
|
|
139
139
|
};
|
|
140
|
-
}, [
|
|
141
|
-
const
|
|
140
|
+
}, [H, I, h]);
|
|
141
|
+
const k = J(() => o !== "0%", [o]);
|
|
142
142
|
return /* @__PURE__ */ g.jsxs(g.Fragment, { children: [
|
|
143
143
|
O && /* @__PURE__ */ g.jsx(
|
|
144
144
|
"div",
|
|
145
145
|
{
|
|
146
|
-
className:
|
|
146
|
+
className: W(k ? "fixed inset-0 bg-black/40 z-55 cursor-default" : "hidden"),
|
|
147
147
|
onClick: (e) => {
|
|
148
|
-
e.preventDefault(), e.stopPropagation(), E &&
|
|
148
|
+
e.preventDefault(), e.stopPropagation(), E && S(0);
|
|
149
149
|
},
|
|
150
150
|
"aria-hidden": "true"
|
|
151
151
|
}
|
|
@@ -154,13 +154,13 @@ const W = 44, U = "height 0.5s cubic-bezier(0.32, 0.72, 0, 1)", ee = J((a, o) =>
|
|
|
154
154
|
"div",
|
|
155
155
|
{
|
|
156
156
|
ref: r,
|
|
157
|
-
className:
|
|
158
|
-
|
|
157
|
+
className: W(
|
|
158
|
+
s ? "absolute" : "fixed",
|
|
159
159
|
"z-60 bottom-0 w-full overflow-hidden",
|
|
160
160
|
"bg-neutral-default-default",
|
|
161
161
|
"border-t border-neutral-strong-default rounded-t-[12px]",
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
k ? "" : "border-neutral-weak",
|
|
163
|
+
y,
|
|
164
164
|
"flex flex-col items-center",
|
|
165
165
|
"touch-none select-none"
|
|
166
166
|
),
|
|
@@ -173,41 +173,41 @@ const W = 44, U = "height 0.5s cubic-bezier(0.32, 0.72, 0, 1)", ee = J((a, o) =>
|
|
|
173
173
|
children: /* @__PURE__ */ g.jsx("span", { className: "w-12 h-1 rounded-full bg-neutral-weak-default" })
|
|
174
174
|
}
|
|
175
175
|
),
|
|
176
|
-
typeof
|
|
176
|
+
typeof p == "string" ? /* @__PURE__ */ g.jsx("p", { className: " prometeo-fonts-headline-small text-neutral-default-default w-full h-11 bg-inherit absolute top-11 z-50 px-4", children: p }) : p,
|
|
177
177
|
/* @__PURE__ */ g.jsx(
|
|
178
178
|
"div",
|
|
179
179
|
{
|
|
180
180
|
ref: C,
|
|
181
|
-
className:
|
|
181
|
+
className: W(
|
|
182
182
|
"w-full h-full overflow-y-auto px-4 pb-4 ",
|
|
183
|
-
|
|
183
|
+
p ? "mt-22" : "mt-11"
|
|
184
184
|
),
|
|
185
185
|
style: {
|
|
186
186
|
overscrollBehavior: "contain",
|
|
187
|
-
overflow:
|
|
187
|
+
overflow: k ? "auto" : "hidden"
|
|
188
188
|
},
|
|
189
|
-
children:
|
|
189
|
+
children: typeof u == "function" ? u(x) : u
|
|
190
190
|
}
|
|
191
191
|
)
|
|
192
192
|
]
|
|
193
193
|
}
|
|
194
194
|
)
|
|
195
195
|
] });
|
|
196
|
-
},
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
}, []),
|
|
200
|
-
|
|
201
|
-
}, []),
|
|
196
|
+
}, ne = () => {
|
|
197
|
+
const u = v(null), s = c((d, w) => {
|
|
198
|
+
u.current?.open(d, w);
|
|
199
|
+
}, []), y = c(() => {
|
|
200
|
+
u.current?.close();
|
|
201
|
+
}, []), o = c(() => u.current?.isOpen ?? !1, []), a = c(() => u.current?.getContext() ?? null, []);
|
|
202
202
|
return {
|
|
203
|
-
isOpen:
|
|
204
|
-
open:
|
|
205
|
-
close:
|
|
206
|
-
drawerRef:
|
|
207
|
-
getContext:
|
|
203
|
+
isOpen: o,
|
|
204
|
+
open: s,
|
|
205
|
+
close: y,
|
|
206
|
+
drawerRef: u,
|
|
207
|
+
getContext: a
|
|
208
208
|
};
|
|
209
209
|
};
|
|
210
210
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
te as default,
|
|
212
|
+
ne as useDrawerMobile
|
|
213
213
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
export interface DrawerMobileProps<TContext = unknown> {
|
|
3
|
-
children?: React.ReactNode;
|
|
3
|
+
children?: React.ReactNode | ((context: TContext | null) => React.ReactNode);
|
|
4
4
|
defaultOpen?: boolean;
|
|
5
5
|
onClose?: (context: TContext | null) => void;
|
|
6
6
|
snap?: string | number | null;
|