motile-ui 1.2.0 → 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.
- package/dist/components/Sheet/Sheet.js +46 -44
- package/dist/components/TimePicker/TimePicker.css +1 -1
- package/dist/components/TimePicker/TimePicker.d.ts +0 -1
- package/dist/components/TimePicker/TimePicker.js +122 -123
- package/dist/hooks/useHistoryClose.d.ts +19 -0
- package/dist/hooks/useHistoryClose.js +38 -29
- package/package.json +1 -1
|
@@ -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 = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.motile-timepicker{display:flex;position:relative;user-select:none;-webkit-user-select:none;overflow:hidden}.motile-timepicker--disabled{pointer-events:none}.motile-
|
|
1
|
+
.motile-timepicker{display:flex;position:relative;user-select:none;-webkit-user-select:none;overflow:hidden;width:200px;height:120px}.motile-timepicker--disabled{pointer-events:none}.motile-timepicker__column{flex:1;overflow-y:scroll;overflow-x:hidden;scroll-snap-type:none;scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;touch-action:pan-y;cursor:grab}@media (hover: none) and (pointer: coarse){.motile-timepicker__column{scroll-snap-type:y mandatory;cursor:default}}.motile-timepicker__column::-webkit-scrollbar{display:none}.motile-timepicker__item{display:flex;align-items:center;justify-content:center;scroll-snap-align:center;font-variant-numeric:tabular-nums;color:#d1d5db}.motile-timepicker__item--selected{color:inherit}.motile-timepicker__spacer{flex-shrink:0;pointer-events:none}.motile-timepicker__highlight{position:absolute;left:0;right:0;top:50%;transform:translateY(-50%);pointer-events:none;background-color:#0000000d;border-radius:8px;z-index:0}.motile-timepicker__column{position:relative;z-index:1}@media (prefers-reduced-motion: reduce){.motile-timepicker__column{scroll-behavior:auto}}
|
|
@@ -15,7 +15,6 @@ export interface TimePickerRootProps extends Omit<React.HTMLAttributes<HTMLDivEl
|
|
|
15
15
|
minuteStep?: MinuteStep;
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
itemHeight?: number;
|
|
18
|
-
fullWidth?: boolean;
|
|
19
18
|
children: React.ReactNode;
|
|
20
19
|
}
|
|
21
20
|
export declare const TimePickerRoot: React.ForwardRefExoticComponent<TimePickerRootProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -11,188 +11,187 @@ const W = ee(null), q = () => {
|
|
|
11
11
|
}, z = U(
|
|
12
12
|
({
|
|
13
13
|
value: t,
|
|
14
|
-
defaultValue:
|
|
14
|
+
defaultValue: R,
|
|
15
15
|
onChange: v,
|
|
16
|
-
format:
|
|
17
|
-
minuteStep:
|
|
16
|
+
format: s = "12",
|
|
17
|
+
minuteStep: l = 5,
|
|
18
18
|
disabled: p = !1,
|
|
19
|
-
itemHeight:
|
|
20
|
-
|
|
21
|
-
children: $,
|
|
19
|
+
itemHeight: o = 40,
|
|
20
|
+
children: g,
|
|
22
21
|
className: D,
|
|
23
22
|
style: I,
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
const [
|
|
27
|
-
hour:
|
|
23
|
+
...$
|
|
24
|
+
}, a) => {
|
|
25
|
+
const [x, w] = Z(() => t || R || {
|
|
26
|
+
hour: s === "12" ? 12 : 0,
|
|
28
27
|
minute: 0,
|
|
29
|
-
period:
|
|
30
|
-
}),
|
|
31
|
-
const
|
|
32
|
-
return Array.from({ length:
|
|
33
|
-
}, [
|
|
34
|
-
(
|
|
35
|
-
const
|
|
36
|
-
|
|
28
|
+
period: s === "12" ? "AM" : void 0
|
|
29
|
+
}), M = t !== void 0, k = M ? t : x, E = O(() => s === "12" ? Array.from({ length: 12 }, (n, h) => h + 1) : Array.from({ length: 24 }, (n, h) => h), [s]), L = O(() => {
|
|
30
|
+
const n = 60 / l;
|
|
31
|
+
return Array.from({ length: n }, (h, u) => u * l);
|
|
32
|
+
}, [l]), b = O(() => ["AM", "PM"], []), V = T(
|
|
33
|
+
(n, h) => {
|
|
34
|
+
const u = { ...k };
|
|
35
|
+
n === "hour" ? u.hour = h : n === "minute" ? u.minute = h : u.period = h, M || w(u), v == null || v(u);
|
|
37
36
|
},
|
|
38
|
-
[
|
|
39
|
-
),
|
|
40
|
-
value:
|
|
41
|
-
format:
|
|
42
|
-
minuteStep:
|
|
37
|
+
[k, M, v]
|
|
38
|
+
), A = {
|
|
39
|
+
value: k,
|
|
40
|
+
format: s,
|
|
41
|
+
minuteStep: l,
|
|
43
42
|
disabled: p,
|
|
44
|
-
itemHeight:
|
|
45
|
-
updateValue:
|
|
46
|
-
hourOptions:
|
|
47
|
-
minuteOptions:
|
|
48
|
-
periodOptions:
|
|
49
|
-
},
|
|
50
|
-
"--timepicker-item-height": `${
|
|
43
|
+
itemHeight: o,
|
|
44
|
+
updateValue: V,
|
|
45
|
+
hourOptions: E,
|
|
46
|
+
minuteOptions: L,
|
|
47
|
+
periodOptions: b
|
|
48
|
+
}, i = {
|
|
49
|
+
"--timepicker-item-height": `${o}px`,
|
|
51
50
|
...I
|
|
52
51
|
};
|
|
53
|
-
return /* @__PURE__ */ S(W.Provider, { value:
|
|
52
|
+
return /* @__PURE__ */ S(W.Provider, { value: A, children: /* @__PURE__ */ S(
|
|
54
53
|
"div",
|
|
55
54
|
{
|
|
56
|
-
ref:
|
|
57
|
-
className: `motile-timepicker ${p ? "motile-timepicker--disabled" : ""} ${
|
|
58
|
-
style:
|
|
55
|
+
ref: a,
|
|
56
|
+
className: `motile-timepicker ${p ? "motile-timepicker--disabled" : ""} ${D || ""}`,
|
|
57
|
+
style: i,
|
|
59
58
|
"aria-disabled": p,
|
|
60
59
|
role: "group",
|
|
61
60
|
"aria-label": "시간 선택",
|
|
62
|
-
|
|
63
|
-
children:
|
|
61
|
+
...$,
|
|
62
|
+
children: g
|
|
64
63
|
}
|
|
65
64
|
) });
|
|
66
65
|
}
|
|
67
66
|
);
|
|
68
67
|
z.displayName = "TimePicker.Root";
|
|
69
|
-
const B = U(({ type: t, className:
|
|
68
|
+
const B = U(({ type: t, className: R, ...v }, s) => {
|
|
70
69
|
const {
|
|
71
|
-
value:
|
|
70
|
+
value: l,
|
|
72
71
|
disabled: p,
|
|
73
|
-
itemHeight:
|
|
72
|
+
itemHeight: o,
|
|
74
73
|
updateValue: g,
|
|
75
|
-
hourOptions:
|
|
76
|
-
minuteOptions:
|
|
77
|
-
periodOptions:
|
|
78
|
-
} = q(),
|
|
74
|
+
hourOptions: D,
|
|
75
|
+
minuteOptions: I,
|
|
76
|
+
periodOptions: $
|
|
77
|
+
} = q(), a = f(null), x = f(null), w = f(!1), M = f(!1), k = f(0), E = f(null), L = f(!0), b = f(!1), V = f(0), A = f(0), i = O(() => {
|
|
79
78
|
switch (t) {
|
|
80
79
|
case "hour":
|
|
81
|
-
return $;
|
|
82
|
-
case "minute":
|
|
83
80
|
return D;
|
|
84
|
-
case "
|
|
81
|
+
case "minute":
|
|
85
82
|
return I;
|
|
83
|
+
case "period":
|
|
84
|
+
return $;
|
|
86
85
|
default:
|
|
87
86
|
return [];
|
|
88
87
|
}
|
|
89
|
-
}, [t,
|
|
88
|
+
}, [t, D, I, $]), n = O(() => {
|
|
90
89
|
switch (t) {
|
|
91
90
|
case "hour":
|
|
92
|
-
return
|
|
91
|
+
return l.hour;
|
|
93
92
|
case "minute":
|
|
94
|
-
return
|
|
93
|
+
return l.minute;
|
|
95
94
|
case "period":
|
|
96
|
-
return
|
|
95
|
+
return l.period;
|
|
97
96
|
default:
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
|
-
}, [t,
|
|
99
|
+
}, [t, l]), h = T(
|
|
101
100
|
(e) => t === "period" ? e : e.toString().padStart(2, "0"),
|
|
102
101
|
[t]
|
|
103
102
|
), u = T(
|
|
104
103
|
(e, r = !0) => {
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
top:
|
|
104
|
+
const c = a.current;
|
|
105
|
+
if (!c || e === void 0) return;
|
|
106
|
+
const m = i.indexOf(e);
|
|
107
|
+
if (m === -1) return;
|
|
108
|
+
const _ = m * o;
|
|
109
|
+
c.scrollTo({
|
|
110
|
+
top: _,
|
|
112
111
|
behavior: r ? "smooth" : "auto"
|
|
113
112
|
});
|
|
114
113
|
},
|
|
115
|
-
[
|
|
116
|
-
),
|
|
114
|
+
[i, o]
|
|
115
|
+
), P = T(() => typeof window < "u" && window.matchMedia("(hover: none) and (pointer: coarse)").matches, []), Y = T(
|
|
117
116
|
(e) => {
|
|
118
|
-
if (
|
|
117
|
+
if (P()) return;
|
|
119
118
|
e.preventDefault();
|
|
120
|
-
const r =
|
|
121
|
-
r && (k.current += e.deltaY,
|
|
122
|
-
const
|
|
123
|
-
let
|
|
124
|
-
if (Math.abs(
|
|
125
|
-
const H =
|
|
119
|
+
const r = a.current;
|
|
120
|
+
r && (k.current += e.deltaY, E.current && clearTimeout(E.current), M.current = !0, E.current = setTimeout(() => {
|
|
121
|
+
const c = k.current, m = 20, _ = 80;
|
|
122
|
+
let d = 0;
|
|
123
|
+
if (Math.abs(c) >= m && (d = Math.sign(c) * Math.max(1, Math.round(Math.abs(c) / _))), d !== 0) {
|
|
124
|
+
const H = i.indexOf(n), j = Math.max(
|
|
126
125
|
0,
|
|
127
|
-
Math.min(H +
|
|
126
|
+
Math.min(H + d, i.length - 1)
|
|
128
127
|
);
|
|
129
128
|
if (j !== H) {
|
|
130
|
-
const K =
|
|
129
|
+
const K = i[j], Q = j * o;
|
|
131
130
|
r.scrollTo({ top: Q, behavior: "smooth" }), g(t, K);
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
k.current = 0, setTimeout(() => {
|
|
135
|
-
|
|
134
|
+
M.current = !1;
|
|
136
135
|
}, 150);
|
|
137
136
|
}, 50));
|
|
138
137
|
},
|
|
139
|
-
[o, n,
|
|
138
|
+
[i, o, n, g, t, P]
|
|
140
139
|
), G = T(
|
|
141
140
|
(e) => {
|
|
142
|
-
if (
|
|
143
|
-
const r =
|
|
144
|
-
r && (
|
|
141
|
+
if (P() || p) return;
|
|
142
|
+
const r = a.current;
|
|
143
|
+
r && (b.current = !0, V.current = e.clientY, A.current = r.scrollTop, r.style.cursor = "grabbing", e.preventDefault());
|
|
145
144
|
},
|
|
146
|
-
[
|
|
145
|
+
[P, p]
|
|
147
146
|
), y = T((e) => {
|
|
148
|
-
if (!
|
|
149
|
-
const r =
|
|
147
|
+
if (!b.current) return;
|
|
148
|
+
const r = a.current;
|
|
150
149
|
if (!r) return;
|
|
151
|
-
const
|
|
152
|
-
r.scrollTop = A.current +
|
|
150
|
+
const c = V.current - e.clientY;
|
|
151
|
+
r.scrollTop = A.current + c;
|
|
153
152
|
}, []), C = T(() => {
|
|
154
|
-
if (!
|
|
155
|
-
|
|
156
|
-
const e =
|
|
153
|
+
if (!b.current) return;
|
|
154
|
+
b.current = !1;
|
|
155
|
+
const e = a.current;
|
|
157
156
|
if (!e) return;
|
|
158
157
|
e.style.cursor = "grab";
|
|
159
|
-
const r = e.scrollTop,
|
|
160
|
-
e.scrollTo({ top:
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
}, [o, n,
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
const e =
|
|
167
|
-
|
|
168
|
-
const r =
|
|
158
|
+
const r = e.scrollTop, c = Math.round(r / o), m = Math.max(0, Math.min(c, i.length - 1)), _ = m * o;
|
|
159
|
+
e.scrollTo({ top: _, behavior: "smooth" });
|
|
160
|
+
const d = i[m];
|
|
161
|
+
d !== void 0 && d !== n && g(t, d);
|
|
162
|
+
}, [i, o, n, g, t]), J = T(() => {
|
|
163
|
+
if (M.current || b.current) return;
|
|
164
|
+
x.current && clearTimeout(x.current);
|
|
165
|
+
const e = P() ? 50 : 100;
|
|
166
|
+
x.current = setTimeout(() => {
|
|
167
|
+
const r = a.current;
|
|
169
168
|
if (!r) return;
|
|
170
|
-
if (
|
|
171
|
-
|
|
169
|
+
if (w.current) {
|
|
170
|
+
w.current = !1;
|
|
172
171
|
return;
|
|
173
172
|
}
|
|
174
|
-
const
|
|
175
|
-
|
|
173
|
+
const c = r.scrollTop, m = Math.round(c / o), _ = Math.max(0, Math.min(m, i.length - 1)), d = i[_];
|
|
174
|
+
d !== void 0 && d !== n && g(t, d);
|
|
176
175
|
}, e);
|
|
177
|
-
}, [o, n,
|
|
176
|
+
}, [i, o, n, g, t, P]);
|
|
178
177
|
return N(() => {
|
|
179
178
|
if (!L.current) return;
|
|
180
179
|
L.current = !1;
|
|
181
180
|
const e = setTimeout(() => {
|
|
182
|
-
u(
|
|
181
|
+
u(n, !1);
|
|
183
182
|
}, 0);
|
|
184
183
|
return () => clearTimeout(e);
|
|
185
|
-
}, [u,
|
|
186
|
-
const e =
|
|
187
|
-
if (!e ||
|
|
188
|
-
const r =
|
|
184
|
+
}, [u, n]), N(() => {
|
|
185
|
+
const e = a.current;
|
|
186
|
+
if (!e || n === void 0) return;
|
|
187
|
+
const r = i.indexOf(n);
|
|
189
188
|
if (r === -1) return;
|
|
190
|
-
const
|
|
191
|
-
Math.abs(
|
|
192
|
-
|
|
189
|
+
const c = r * o, m = e.scrollTop;
|
|
190
|
+
Math.abs(m - c) > 1 && (w.current = !0, u(n, !0), setTimeout(() => {
|
|
191
|
+
w.current = !1;
|
|
193
192
|
}, 200));
|
|
194
|
-
}, [
|
|
195
|
-
const e =
|
|
193
|
+
}, [n, u, i, o]), N(() => {
|
|
194
|
+
const e = a.current;
|
|
196
195
|
if (e)
|
|
197
196
|
return e.addEventListener("wheel", Y, { passive: !1 }), () => {
|
|
198
197
|
e.removeEventListener("wheel", Y);
|
|
@@ -200,14 +199,14 @@ const B = U(({ type: t, className: w, ...v }, l) => {
|
|
|
200
199
|
}, [Y]), N(() => (document.addEventListener("mousemove", y), document.addEventListener("mouseup", C), () => {
|
|
201
200
|
document.removeEventListener("mousemove", y), document.removeEventListener("mouseup", C);
|
|
202
201
|
}), [y, C]), N(() => () => {
|
|
203
|
-
|
|
202
|
+
x.current !== null && clearTimeout(x.current);
|
|
204
203
|
}, []), /* @__PURE__ */ X(
|
|
205
204
|
"div",
|
|
206
205
|
{
|
|
207
206
|
ref: (e) => {
|
|
208
|
-
typeof
|
|
207
|
+
typeof s == "function" ? s(e) : s && (s.current = e), a.current = e;
|
|
209
208
|
},
|
|
210
|
-
className: `motile-timepicker__column ${
|
|
209
|
+
className: `motile-timepicker__column ${R || ""}`,
|
|
211
210
|
onScroll: J,
|
|
212
211
|
onMouseDown: G,
|
|
213
212
|
role: "listbox",
|
|
@@ -219,21 +218,21 @@ const B = U(({ type: t, className: w, ...v }, l) => {
|
|
|
219
218
|
"div",
|
|
220
219
|
{
|
|
221
220
|
className: "motile-timepicker__spacer",
|
|
222
|
-
style: { height:
|
|
221
|
+
style: { height: o },
|
|
223
222
|
"aria-hidden": "true"
|
|
224
223
|
}
|
|
225
224
|
),
|
|
226
|
-
|
|
227
|
-
const
|
|
225
|
+
i.map((e, r) => {
|
|
226
|
+
const c = e === n;
|
|
228
227
|
return /* @__PURE__ */ S(
|
|
229
228
|
"div",
|
|
230
229
|
{
|
|
231
|
-
className: `motile-timepicker__item ${
|
|
232
|
-
style: { height:
|
|
230
|
+
className: `motile-timepicker__item ${c ? "motile-timepicker__item--selected" : ""} ${p ? "motile-timepicker__item--disabled" : ""}`,
|
|
231
|
+
style: { height: o },
|
|
233
232
|
role: "option",
|
|
234
|
-
"aria-selected":
|
|
233
|
+
"aria-selected": c,
|
|
235
234
|
"data-value": e,
|
|
236
|
-
children:
|
|
235
|
+
children: h(e)
|
|
237
236
|
},
|
|
238
237
|
r
|
|
239
238
|
);
|
|
@@ -242,7 +241,7 @@ const B = U(({ type: t, className: w, ...v }, l) => {
|
|
|
242
241
|
"div",
|
|
243
242
|
{
|
|
244
243
|
className: "motile-timepicker__spacer",
|
|
245
|
-
style: { height:
|
|
244
|
+
style: { height: o },
|
|
246
245
|
"aria-hidden": "true"
|
|
247
246
|
}
|
|
248
247
|
)
|
|
@@ -251,15 +250,15 @@ const B = U(({ type: t, className: w, ...v }, l) => {
|
|
|
251
250
|
);
|
|
252
251
|
});
|
|
253
252
|
B.displayName = "TimePicker.Column";
|
|
254
|
-
const F = U(({ className: t, style:
|
|
255
|
-
const { itemHeight:
|
|
256
|
-
height:
|
|
257
|
-
...
|
|
253
|
+
const F = U(({ className: t, style: R, ...v }, s) => {
|
|
254
|
+
const { itemHeight: l } = q(), p = {
|
|
255
|
+
height: l,
|
|
256
|
+
...R
|
|
258
257
|
};
|
|
259
258
|
return /* @__PURE__ */ S(
|
|
260
259
|
"div",
|
|
261
260
|
{
|
|
262
|
-
ref:
|
|
261
|
+
ref: s,
|
|
263
262
|
className: `motile-timepicker__highlight ${t || ""}`,
|
|
264
263
|
style: p,
|
|
265
264
|
"aria-hidden": "true",
|
|
@@ -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
|
};
|