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.
@@ -1,14 +1,14 @@
1
1
  import { jsx as d, jsxs as $ } from "react/jsx-runtime";
2
- import { useCallback as k, useState as S, useEffect as b, useId as A, useRef as g, useMemo as F, createContext as N, useContext as T } from "react";
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 I = N(null);
10
- function v() {
11
- const e = T(I);
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] = S(n), s = t ? e : i, r = k(
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, ""), h = g(null), m = g(null), [c, p] = V({
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, navigateAndClose: u } = H({
45
+ }), { isClosingFromHistory: y, close: u, navigateAndClose: S } = H({
46
46
  isOpen: c,
47
- onClose: () => p(!1),
47
+ onClose: () => h(!1),
48
48
  enabled: a
49
- }), _ = F(
49
+ }), C = F(
50
50
  () => ({
51
51
  open: c,
52
- setOpen: p,
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: h,
60
+ overlayRef: p,
61
61
  sheetRef: m,
62
62
  isClosingFromHistory: y,
63
- navigateAndClose: u
63
+ close: u,
64
+ navigateAndClose: S
64
65
  }),
65
66
  [
66
67
  c,
67
- p,
68
+ h,
68
69
  n,
69
70
  o,
70
71
  t,
71
72
  i,
72
73
  r,
73
74
  f,
74
- h,
75
+ p,
75
76
  m,
76
77
  y,
77
- u
78
+ u,
79
+ S
78
80
  ]
79
81
  );
80
- return /* @__PURE__ */ d(I.Provider, { value: _, children: e });
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 } = v(), s = k(() => {
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 } = v(), [t, i] = S(!1);
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, setOpen: t, position: i, closeOnBackdrop: l, zIndex: s, overlayRef: r } = v(), [a, f] = S(!1), [h, m] = S(!1), c = typeof l == "boolean" ? { clickOutside: l } : {
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 _ = requestAnimationFrame(() => {
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 p = k(
140
+ const h = k(
139
141
  (u) => {
140
- c.clickOutside && u.target === r.current && (u.stopPropagation(), t(!1));
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 ${h ? "motile-sheet__overlay--visible" : ""} motile-sheet__overlay--${i} ${e}`,
156
+ className: `motile-sheet__overlay ${p ? "motile-sheet__overlay--visible" : ""} motile-sheet__overlay--${i} ${e}`,
155
157
  style: y,
156
- onClick: p,
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
- setOpen: i,
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: h,
172
+ sheetRef: p,
171
173
  isClosingFromHistory: m
172
- } = v(), [c, p] = S(!1), [y, u] = S(!1), _ = typeof s == "boolean" ? { escapeKey: s } : {
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: () => i(!1),
181
- enabled: t && _.escapeKey
182
+ handler: i,
183
+ enabled: t && S.escapeKey
182
184
  }), b(() => {
183
185
  if (t)
184
- p(!0);
186
+ h(!0);
185
187
  else if (c) {
186
188
  u(!1);
187
- const C = setTimeout(() => {
188
- p(!1);
189
+ const x = setTimeout(() => {
190
+ h(!1);
189
191
  }, m ? 0 : 300);
190
- return () => clearTimeout(C);
192
+ return () => clearTimeout(x);
191
193
  }
192
194
  }, [t, c, m]), b(() => {
193
195
  if (!c || !t || m) return;
194
- const x = requestAnimationFrame(() => {
195
- const C = requestAnimationFrame(() => {
196
+ const g = requestAnimationFrame(() => {
197
+ const x = requestAnimationFrame(() => {
196
198
  u(!0);
197
199
  });
198
- return () => cancelAnimationFrame(C);
200
+ return () => cancelAnimationFrame(x);
199
201
  });
200
- return () => cancelAnimationFrame(x);
202
+ return () => cancelAnimationFrame(g);
201
203
  }, [c, t, m]), !c)
202
204
  return null;
203
- const R = {
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: h,
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: R,
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 { setOpen: o } = v(), t = k(() => {
232
- o(!1);
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 } = v();
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-timepicker--full-width{width:100%}.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}@media (prefers-reduced-motion: reduce){.motile-timepicker__column{scroll-behavior:auto}}
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: w,
14
+ defaultValue: R,
15
15
  onChange: v,
16
- format: l = "12",
17
- minuteStep: a = 5,
16
+ format: s = "12",
17
+ minuteStep: l = 5,
18
18
  disabled: p = !1,
19
- itemHeight: n = 40,
20
- fullWidth: g = !1,
21
- children: $,
19
+ itemHeight: o = 40,
20
+ children: g,
22
21
  className: D,
23
22
  style: I,
24
- ...m
25
- }, M) => {
26
- const [P, E] = Z(() => t || w || {
27
- hour: l === "12" ? 12 : 0,
23
+ ...$
24
+ }, a) => {
25
+ const [x, w] = Z(() => t || R || {
26
+ hour: s === "12" ? 12 : 0,
28
27
  minute: 0,
29
- period: l === "12" ? "AM" : void 0
30
- }), k = t !== void 0, b = k ? t : P, L = O(() => l === "12" ? Array.from({ length: 12 }, (x, u) => u + 1) : Array.from({ length: 24 }, (x, u) => u), [l]), _ = O(() => {
31
- const x = 60 / a;
32
- return Array.from({ length: x }, (u, s) => s * a);
33
- }, [a]), V = O(() => ["AM", "PM"], []), A = T(
34
- (x, u) => {
35
- const s = { ...b };
36
- x === "hour" ? s.hour = u : x === "minute" ? s.minute = u : s.period = u, k || E(s), v == null || v(s);
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
- [b, k, v]
39
- ), o = {
40
- value: b,
41
- format: l,
42
- minuteStep: a,
37
+ [k, M, v]
38
+ ), A = {
39
+ value: k,
40
+ format: s,
41
+ minuteStep: l,
43
42
  disabled: p,
44
- itemHeight: n,
45
- updateValue: A,
46
- hourOptions: L,
47
- minuteOptions: _,
48
- periodOptions: V
49
- }, c = {
50
- "--timepicker-item-height": `${n}px`,
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: o, children: /* @__PURE__ */ S(
52
+ return /* @__PURE__ */ S(W.Provider, { value: A, children: /* @__PURE__ */ S(
54
53
  "div",
55
54
  {
56
- ref: M,
57
- className: `motile-timepicker ${p ? "motile-timepicker--disabled" : ""} ${g ? "motile-timepicker--full-width" : ""} ${D || ""}`,
58
- style: c,
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
- ...m,
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: w, ...v }, l) => {
68
+ const B = U(({ type: t, className: R, ...v }, s) => {
70
69
  const {
71
- value: a,
70
+ value: l,
72
71
  disabled: p,
73
- itemHeight: n,
72
+ itemHeight: o,
74
73
  updateValue: g,
75
- hourOptions: $,
76
- minuteOptions: D,
77
- periodOptions: I
78
- } = q(), m = f(null), M = f(null), P = f(!1), E = f(!1), k = f(0), b = f(null), L = f(!0), _ = f(!1), V = f(0), A = f(0), o = O(() => {
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 "period":
81
+ case "minute":
85
82
  return I;
83
+ case "period":
84
+ return $;
86
85
  default:
87
86
  return [];
88
87
  }
89
- }, [t, $, D, I]), c = O(() => {
88
+ }, [t, D, I, $]), n = O(() => {
90
89
  switch (t) {
91
90
  case "hour":
92
- return a.hour;
91
+ return l.hour;
93
92
  case "minute":
94
- return a.minute;
93
+ return l.minute;
95
94
  case "period":
96
- return a.period;
95
+ return l.period;
97
96
  default:
98
97
  return;
99
98
  }
100
- }, [t, a]), x = 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 i = m.current;
106
- if (!i || e === void 0) return;
107
- const d = o.indexOf(e);
108
- if (d === -1) return;
109
- const R = d * n;
110
- i.scrollTo({
111
- top: R,
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
- [o, n]
116
- ), s = T(() => typeof window < "u" && window.matchMedia("(hover: none) and (pointer: coarse)").matches, []), Y = T(
114
+ [i, o]
115
+ ), P = T(() => typeof window < "u" && window.matchMedia("(hover: none) and (pointer: coarse)").matches, []), Y = T(
117
116
  (e) => {
118
- if (s()) return;
117
+ if (P()) return;
119
118
  e.preventDefault();
120
- const r = m.current;
121
- r && (k.current += e.deltaY, b.current && clearTimeout(b.current), E.current = !0, b.current = setTimeout(() => {
122
- const i = k.current, d = 20, R = 80;
123
- let h = 0;
124
- if (Math.abs(i) >= d && (h = Math.sign(i) * Math.max(1, Math.round(Math.abs(i) / R))), h !== 0) {
125
- const H = o.indexOf(c), j = Math.max(
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 + h, o.length - 1)
126
+ Math.min(H + d, i.length - 1)
128
127
  );
129
128
  if (j !== H) {
130
- const K = o[j], Q = j * n;
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
- E.current = !1;
134
+ M.current = !1;
136
135
  }, 150);
137
136
  }, 50));
138
137
  },
139
- [o, n, c, g, t, s]
138
+ [i, o, n, g, t, P]
140
139
  ), G = T(
141
140
  (e) => {
142
- if (s() || p) return;
143
- const r = m.current;
144
- r && (_.current = !0, V.current = e.clientY, A.current = r.scrollTop, r.style.cursor = "grabbing", e.preventDefault());
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
- [s, p]
145
+ [P, p]
147
146
  ), y = T((e) => {
148
- if (!_.current) return;
149
- const r = m.current;
147
+ if (!b.current) return;
148
+ const r = a.current;
150
149
  if (!r) return;
151
- const i = V.current - e.clientY;
152
- r.scrollTop = A.current + i;
150
+ const c = V.current - e.clientY;
151
+ r.scrollTop = A.current + c;
153
152
  }, []), C = T(() => {
154
- if (!_.current) return;
155
- _.current = !1;
156
- const e = m.current;
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, i = Math.round(r / n), d = Math.max(0, Math.min(i, o.length - 1)), R = d * n;
160
- e.scrollTo({ top: R, behavior: "smooth" });
161
- const h = o[d];
162
- h !== void 0 && h !== c && g(t, h);
163
- }, [o, n, c, g, t]), J = T(() => {
164
- if (E.current || _.current) return;
165
- M.current && clearTimeout(M.current);
166
- const e = s() ? 50 : 100;
167
- M.current = setTimeout(() => {
168
- const r = m.current;
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 (P.current) {
171
- P.current = !1;
169
+ if (w.current) {
170
+ w.current = !1;
172
171
  return;
173
172
  }
174
- const i = r.scrollTop, d = Math.round(i / n), R = Math.max(0, Math.min(d, o.length - 1)), h = o[R];
175
- h !== void 0 && h !== c && g(t, h);
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, c, g, t, s]);
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(c, !1);
181
+ u(n, !1);
183
182
  }, 0);
184
183
  return () => clearTimeout(e);
185
- }, [u, c]), N(() => {
186
- const e = m.current;
187
- if (!e || c === void 0) return;
188
- const r = o.indexOf(c);
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 i = r * n, d = e.scrollTop;
191
- Math.abs(d - i) > 1 && (P.current = !0, u(c, !0), setTimeout(() => {
192
- P.current = !1;
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
- }, [c, u, o, n]), N(() => {
195
- const e = m.current;
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
- M.current !== null && clearTimeout(M.current);
202
+ x.current !== null && clearTimeout(x.current);
204
203
  }, []), /* @__PURE__ */ X(
205
204
  "div",
206
205
  {
207
206
  ref: (e) => {
208
- typeof l == "function" ? l(e) : l && (l.current = e), m.current = e;
207
+ typeof s == "function" ? s(e) : s && (s.current = e), a.current = e;
209
208
  },
210
- className: `motile-timepicker__column ${w || ""}`,
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: n },
221
+ style: { height: o },
223
222
  "aria-hidden": "true"
224
223
  }
225
224
  ),
226
- o.map((e, r) => {
227
- const i = e === c;
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 ${i ? "motile-timepicker__item--selected" : ""} ${p ? "motile-timepicker__item--disabled" : ""}`,
232
- style: { height: n },
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": i,
233
+ "aria-selected": c,
235
234
  "data-value": e,
236
- children: x(e)
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: n },
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: w, ...v }, l) => {
255
- const { itemHeight: a } = q(), p = {
256
- height: a,
257
- ...w
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: l,
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 i, useState as h, useEffect as c } from "react";
2
- function m({
3
- onClose: s,
4
- isOpen: n,
5
- enabled: r = !0
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 u = i(s), o = i(!1), [a, l] = h(!1), f = i(0), e = i(null);
8
- return c(() => {
9
- u.current = s;
10
- }, [s]), c(() => {
11
- if (!r || !n) return;
12
- const t = (d) => {
13
- l(!0), u.current();
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 o.current || (f.current = window.history.length, window.history.pushState({ modal: !0 }, ""), o.current = !0), window.addEventListener("popstate", t), () => {
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
- }, [n, r]), c(() => {
19
- if (!r || n || !o.current) return;
18
+ }, [i, e]), a(() => {
19
+ if (!e || i || !n.current) return;
20
20
  let t = null;
21
- if (!a) {
22
- const d = f.current + 1;
23
- if (window.history.length !== d)
24
- e.current = null;
25
- else if (e.current) {
26
- const w = e.current;
27
- e.current = null, t = () => {
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
- w();
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 o.current = !1, l(!1), () => {
35
+ return n.current = !1, l(!1), () => {
36
36
  t && window.removeEventListener("popstate", t);
37
37
  };
38
- }, [n, a, r]), {
39
- isClosingFromHistory: a,
40
- navigateAndClose: (t) => {
41
- e.current = t, u.current();
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
- m as useHistoryClose
55
+ L as useHistoryClose
47
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motile-ui",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "A modern React component library for webview applications",
6
6
  "main": "./dist/index.js",