motile-ui 1.2.1 → 1.2.2
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,14 +1,14 @@
|
|
|
1
1
|
import { jsx as d, jsxs as $ } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback as k, useState as
|
|
2
|
+
import { useCallback as k, useState as v, useEffect as b, useId as A, useRef as I, useMemo as F, createContext as N, useContext as T } from "react";
|
|
3
3
|
import { createPortal as w } from "react-dom";
|
|
4
4
|
import { useEscapeKey as K } from "../../hooks/useEscapeKey.js";
|
|
5
5
|
import { useHistoryClose as H } from "../../hooks/useHistoryClose.js";
|
|
6
6
|
import { useScrollLock as P } from "../../hooks/useScrollLock.js";
|
|
7
7
|
import { Slot as O } from "../../utils/Slot.js";
|
|
8
8
|
import './Sheet.css';/* empty css */
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
const e = T(
|
|
9
|
+
const R = N(null);
|
|
10
|
+
function _() {
|
|
11
|
+
const e = T(R);
|
|
12
12
|
if (!e)
|
|
13
13
|
throw new Error("Sheet components must be used within Sheet.Root");
|
|
14
14
|
return e;
|
|
@@ -18,7 +18,7 @@ function V({
|
|
|
18
18
|
defaultValue: n = !1,
|
|
19
19
|
onChange: o
|
|
20
20
|
}) {
|
|
21
|
-
const t = e !== void 0, [i, l] =
|
|
21
|
+
const t = e !== void 0, [i, l] = v(n), s = t ? e : i, r = k(
|
|
22
22
|
(a) => {
|
|
23
23
|
const f = typeof a == "function" ? a(s) : a;
|
|
24
24
|
t || l(f), o == null || o(f);
|
|
@@ -38,18 +38,18 @@ function q({
|
|
|
38
38
|
onOpenChange: r,
|
|
39
39
|
enableHistoryClose: a = !0
|
|
40
40
|
}) {
|
|
41
|
-
const f = A().replace(/:/g, ""),
|
|
41
|
+
const f = A().replace(/:/g, ""), p = I(null), m = I(null), [c, h] = V({
|
|
42
42
|
value: l,
|
|
43
43
|
defaultValue: s,
|
|
44
44
|
onChange: r
|
|
45
|
-
}), { isClosingFromHistory: y,
|
|
45
|
+
}), { isClosingFromHistory: y, close: u, navigateAndClose: S } = H({
|
|
46
46
|
isOpen: c,
|
|
47
|
-
onClose: () =>
|
|
47
|
+
onClose: () => h(!1),
|
|
48
48
|
enabled: a
|
|
49
|
-
}),
|
|
49
|
+
}), C = F(
|
|
50
50
|
() => ({
|
|
51
51
|
open: c,
|
|
52
|
-
setOpen:
|
|
52
|
+
setOpen: h,
|
|
53
53
|
position: n,
|
|
54
54
|
closeOnBackdrop: o,
|
|
55
55
|
maxWidth: t,
|
|
@@ -57,30 +57,32 @@ function q({
|
|
|
57
57
|
onOpenChange: r,
|
|
58
58
|
triggerId: `${f}-trigger`,
|
|
59
59
|
contentId: `${f}-content`,
|
|
60
|
-
overlayRef:
|
|
60
|
+
overlayRef: p,
|
|
61
61
|
sheetRef: m,
|
|
62
62
|
isClosingFromHistory: y,
|
|
63
|
-
|
|
63
|
+
close: u,
|
|
64
|
+
navigateAndClose: S
|
|
64
65
|
}),
|
|
65
66
|
[
|
|
66
67
|
c,
|
|
67
|
-
|
|
68
|
+
h,
|
|
68
69
|
n,
|
|
69
70
|
o,
|
|
70
71
|
t,
|
|
71
72
|
i,
|
|
72
73
|
r,
|
|
73
74
|
f,
|
|
74
|
-
|
|
75
|
+
p,
|
|
75
76
|
m,
|
|
76
77
|
y,
|
|
77
|
-
u
|
|
78
|
+
u,
|
|
79
|
+
S
|
|
78
80
|
]
|
|
79
81
|
);
|
|
80
|
-
return /* @__PURE__ */ d(
|
|
82
|
+
return /* @__PURE__ */ d(R.Provider, { value: C, children: e });
|
|
81
83
|
}
|
|
82
84
|
function z({ children: e, asChild: n = !1 }) {
|
|
83
|
-
const { open: o, setOpen: t, triggerId: i, contentId: l } =
|
|
85
|
+
const { open: o, setOpen: t, triggerId: i, contentId: l } = _(), s = k(() => {
|
|
84
86
|
t((r) => !r);
|
|
85
87
|
}, [t]);
|
|
86
88
|
return n ? /* @__PURE__ */ d(
|
|
@@ -105,13 +107,13 @@ function z({ children: e, asChild: n = !1 }) {
|
|
|
105
107
|
);
|
|
106
108
|
}
|
|
107
109
|
function B({ children: e, container: n }) {
|
|
108
|
-
const { open: o } =
|
|
110
|
+
const { open: o } = _(), [t, i] = v(!1);
|
|
109
111
|
return b(() => {
|
|
110
112
|
i(!0);
|
|
111
113
|
}, []), !t || !o ? null : w(e, n || document.body);
|
|
112
114
|
}
|
|
113
115
|
function j({ className: e = "", style: n }) {
|
|
114
|
-
const { open: o,
|
|
116
|
+
const { open: o, close: t, position: i, closeOnBackdrop: l, zIndex: s, overlayRef: r } = _(), [a, f] = v(!1), [p, m] = v(!1), c = typeof l == "boolean" ? { clickOutside: l } : {
|
|
115
117
|
escapeKey: l.escapeKey ?? !1,
|
|
116
118
|
clickOutside: l.clickOutside ?? !1
|
|
117
119
|
};
|
|
@@ -128,16 +130,16 @@ function j({ className: e = "", style: n }) {
|
|
|
128
130
|
}, [o, a]), b(() => {
|
|
129
131
|
if (!a || !o) return;
|
|
130
132
|
const u = requestAnimationFrame(() => {
|
|
131
|
-
const
|
|
133
|
+
const S = requestAnimationFrame(() => {
|
|
132
134
|
m(!0);
|
|
133
135
|
});
|
|
134
|
-
return () => cancelAnimationFrame(
|
|
136
|
+
return () => cancelAnimationFrame(S);
|
|
135
137
|
});
|
|
136
138
|
return () => cancelAnimationFrame(u);
|
|
137
139
|
}, [a, o]);
|
|
138
|
-
const
|
|
140
|
+
const h = k(
|
|
139
141
|
(u) => {
|
|
140
|
-
c.clickOutside && u.target === r.current && (u.stopPropagation(), t(
|
|
142
|
+
c.clickOutside && u.target === r.current && (u.stopPropagation(), t());
|
|
141
143
|
},
|
|
142
144
|
[c.clickOutside, t, r]
|
|
143
145
|
);
|
|
@@ -151,9 +153,9 @@ function j({ className: e = "", style: n }) {
|
|
|
151
153
|
"div",
|
|
152
154
|
{
|
|
153
155
|
ref: r,
|
|
154
|
-
className: `motile-sheet__overlay ${
|
|
156
|
+
className: `motile-sheet__overlay ${p ? "motile-sheet__overlay--visible" : ""} motile-sheet__overlay--${i} ${e}`,
|
|
155
157
|
style: y,
|
|
156
|
-
onClick:
|
|
158
|
+
onClick: h,
|
|
157
159
|
role: "presentation"
|
|
158
160
|
}
|
|
159
161
|
);
|
|
@@ -161,15 +163,15 @@ function j({ className: e = "", style: n }) {
|
|
|
161
163
|
function E({ children: e, className: n = "", style: o }) {
|
|
162
164
|
const {
|
|
163
165
|
open: t,
|
|
164
|
-
|
|
166
|
+
close: i,
|
|
165
167
|
position: l,
|
|
166
168
|
closeOnBackdrop: s,
|
|
167
169
|
maxWidth: r,
|
|
168
170
|
zIndex: a,
|
|
169
171
|
contentId: f,
|
|
170
|
-
sheetRef:
|
|
172
|
+
sheetRef: p,
|
|
171
173
|
isClosingFromHistory: m
|
|
172
|
-
} =
|
|
174
|
+
} = _(), [c, h] = v(!1), [y, u] = v(!1), S = typeof s == "boolean" ? { escapeKey: s } : {
|
|
173
175
|
escapeKey: s.escapeKey ?? !1,
|
|
174
176
|
clickOutside: s.clickOutside ?? !1
|
|
175
177
|
};
|
|
@@ -177,30 +179,30 @@ function E({ children: e, className: n = "", style: o }) {
|
|
|
177
179
|
enabled: t,
|
|
178
180
|
allowedSelectors: [".motile-sheet__body"]
|
|
179
181
|
}), K({
|
|
180
|
-
handler:
|
|
181
|
-
enabled: t &&
|
|
182
|
+
handler: i,
|
|
183
|
+
enabled: t && S.escapeKey
|
|
182
184
|
}), b(() => {
|
|
183
185
|
if (t)
|
|
184
|
-
|
|
186
|
+
h(!0);
|
|
185
187
|
else if (c) {
|
|
186
188
|
u(!1);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
+
const x = setTimeout(() => {
|
|
190
|
+
h(!1);
|
|
189
191
|
}, m ? 0 : 300);
|
|
190
|
-
return () => clearTimeout(
|
|
192
|
+
return () => clearTimeout(x);
|
|
191
193
|
}
|
|
192
194
|
}, [t, c, m]), b(() => {
|
|
193
195
|
if (!c || !t || m) return;
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
+
const g = requestAnimationFrame(() => {
|
|
197
|
+
const x = requestAnimationFrame(() => {
|
|
196
198
|
u(!0);
|
|
197
199
|
});
|
|
198
|
-
return () => cancelAnimationFrame(
|
|
200
|
+
return () => cancelAnimationFrame(x);
|
|
199
201
|
});
|
|
200
|
-
return () => cancelAnimationFrame(
|
|
202
|
+
return () => cancelAnimationFrame(g);
|
|
201
203
|
}, [c, t, m]), !c)
|
|
202
204
|
return null;
|
|
203
|
-
const
|
|
205
|
+
const C = {
|
|
204
206
|
...r !== "600px" && { "--sheet-max-width": r },
|
|
205
207
|
zIndex: a + 1,
|
|
206
208
|
...o
|
|
@@ -208,10 +210,10 @@ function E({ children: e, className: n = "", style: o }) {
|
|
|
208
210
|
return /* @__PURE__ */ d(
|
|
209
211
|
"div",
|
|
210
212
|
{
|
|
211
|
-
ref:
|
|
213
|
+
ref: p,
|
|
212
214
|
id: f,
|
|
213
215
|
className: `motile-sheet__content motile-sheet__content--${l} ${y ? "motile-sheet__content--visible" : ""} ${n}`,
|
|
214
|
-
style:
|
|
216
|
+
style: C,
|
|
215
217
|
role: "dialog",
|
|
216
218
|
"aria-modal": "true",
|
|
217
219
|
children: e
|
|
@@ -228,8 +230,8 @@ function M({ children: e, className: n = "" }) {
|
|
|
228
230
|
return /* @__PURE__ */ d("div", { className: `motile-sheet__body ${n}`, children: e });
|
|
229
231
|
}
|
|
230
232
|
function W({ children: e, asChild: n = !1 }) {
|
|
231
|
-
const {
|
|
232
|
-
o(
|
|
233
|
+
const { close: o } = _(), t = k(() => {
|
|
234
|
+
o();
|
|
233
235
|
}, [o]);
|
|
234
236
|
return n ? /* @__PURE__ */ d(
|
|
235
237
|
O,
|
|
@@ -267,7 +269,7 @@ function W({ children: e, asChild: n = !1 }) {
|
|
|
267
269
|
);
|
|
268
270
|
}
|
|
269
271
|
function te() {
|
|
270
|
-
const { navigateAndClose: e } =
|
|
272
|
+
const { navigateAndClose: e } = _();
|
|
271
273
|
return e;
|
|
272
274
|
}
|
|
273
275
|
const oe = {
|
|
@@ -40,6 +40,25 @@ export interface UseHistoryCloseReturn {
|
|
|
40
40
|
* 히스토리 기반 닫기 여부
|
|
41
41
|
*/
|
|
42
42
|
isClosingFromHistory: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Sheet/Modal을 닫는 함수
|
|
45
|
+
* 히스토리 기반 닫기가 활성화된 경우 history.back()을 통해 닫아
|
|
46
|
+
* 더미 히스토리를 확실하게 제거합니다.
|
|
47
|
+
*
|
|
48
|
+
* @description
|
|
49
|
+
* - enableHistoryClose=true: history.back() → popstate → onClose
|
|
50
|
+
* - enableHistoryClose=false: 직접 onClose() 호출
|
|
51
|
+
*
|
|
52
|
+
* Sheet.Close, 닫기 버튼 등에서 사용하세요.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* const { close } = useHistoryClose({ isOpen, onClose });
|
|
57
|
+
*
|
|
58
|
+
* <button onClick={close}>닫기</button>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
close: () => void;
|
|
43
62
|
/**
|
|
44
63
|
* Sheet을 닫으면서 페이지 네비게이션을 수행하는 함수
|
|
45
64
|
* 히스토리를 깔끔하게 유지하면서 네비게이션을 처리합니다.
|
|
@@ -1,47 +1,56 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
function
|
|
3
|
-
onClose:
|
|
4
|
-
isOpen:
|
|
5
|
-
enabled:
|
|
1
|
+
import { useRef as s, useState as g, useEffect as a, useCallback as d } from "react";
|
|
2
|
+
function L({
|
|
3
|
+
onClose: u,
|
|
4
|
+
isOpen: i,
|
|
5
|
+
enabled: e = !0
|
|
6
6
|
}) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}, [
|
|
11
|
-
if (!
|
|
12
|
-
const t = (
|
|
13
|
-
l(!0),
|
|
7
|
+
const r = s(u), n = s(!1), [c, l] = g(!1), f = s(0), o = s(null);
|
|
8
|
+
a(() => {
|
|
9
|
+
r.current = u;
|
|
10
|
+
}, [u]), a(() => {
|
|
11
|
+
if (!e || !i) return;
|
|
12
|
+
const t = (w) => {
|
|
13
|
+
l(!0), r.current();
|
|
14
14
|
};
|
|
15
|
-
return
|
|
15
|
+
return n.current || (f.current = window.history.length, window.history.pushState({ modal: !0 }, ""), n.current = !0), window.addEventListener("popstate", t), () => {
|
|
16
16
|
window.removeEventListener("popstate", t);
|
|
17
17
|
};
|
|
18
|
-
}, [
|
|
19
|
-
if (!
|
|
18
|
+
}, [i, e]), a(() => {
|
|
19
|
+
if (!e || i || !n.current) return;
|
|
20
20
|
let t = null;
|
|
21
|
-
if (!
|
|
22
|
-
const
|
|
23
|
-
if (window.history.length !==
|
|
24
|
-
|
|
25
|
-
else if (
|
|
26
|
-
const
|
|
27
|
-
|
|
21
|
+
if (!c) {
|
|
22
|
+
const w = f.current + 1;
|
|
23
|
+
if (window.history.length !== w)
|
|
24
|
+
o.current = null;
|
|
25
|
+
else if (o.current) {
|
|
26
|
+
const v = o.current;
|
|
27
|
+
o.current = null, t = () => {
|
|
28
28
|
window.removeEventListener("popstate", t), t = null, setTimeout(() => {
|
|
29
|
-
|
|
29
|
+
v();
|
|
30
30
|
}, 0);
|
|
31
31
|
}, window.addEventListener("popstate", t), window.history.back();
|
|
32
32
|
} else
|
|
33
33
|
window.history.back();
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return n.current = !1, l(!1), () => {
|
|
36
36
|
t && window.removeEventListener("popstate", t);
|
|
37
37
|
};
|
|
38
|
-
}, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
}, [i, c, e]);
|
|
39
|
+
const h = d(() => {
|
|
40
|
+
if (!e) {
|
|
41
|
+
r.current();
|
|
42
|
+
return;
|
|
42
43
|
}
|
|
44
|
+
n.current ? window.history.back() : r.current();
|
|
45
|
+
}, [e]), p = d((t) => {
|
|
46
|
+
o.current = t, r.current();
|
|
47
|
+
}, []);
|
|
48
|
+
return {
|
|
49
|
+
isClosingFromHistory: c,
|
|
50
|
+
close: h,
|
|
51
|
+
navigateAndClose: p
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
export {
|
|
46
|
-
|
|
55
|
+
L as useHistoryClose
|
|
47
56
|
};
|