motile-ui 1.2.0 → 1.2.1
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
|
-
.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",
|