motile-ui 1.0.3 → 1.1.0

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,21 +1,21 @@
1
1
  import { jsx as u } from "react/jsx-runtime";
2
- import W, { forwardRef as w, useRef as _, useState as E, useEffect as M, createContext as G, useContext as J } from "react";
2
+ import W, { forwardRef as w, useState as g, useEffect as Y, useRef as _, createContext as G, useContext as J } from "react";
3
3
  import { createPortal as Q } from "react-dom";
4
- import { Slot as Y } from "../../utils/Slot.js";
4
+ import { Slot as M } from "../../utils/Slot.js";
5
5
  import { useScrollLock as X } from "../../hooks/useScrollLock.js";
6
6
  import { useClickOutside as Z } from "../../hooks/useClickOutside.js";
7
7
  import { useEscapeKey as k } from "../../hooks/useEscapeKey.js";
8
8
  import './Drawer.css';/* empty css */
9
9
  const $ = G(null), f = () => {
10
- const t = J($);
11
- if (!t)
10
+ const r = J($);
11
+ if (!r)
12
12
  throw new Error("Drawer components must be used within Drawer.Root");
13
- return t;
13
+ return r;
14
14
  }, C = ({
15
- children: t,
15
+ children: r,
16
16
  open: s,
17
17
  defaultOpen: n = !1,
18
- onOpenChange: r,
18
+ onOpenChange: t,
19
19
  closeOnBackdrop: e = !0,
20
20
  closeOnDrag: o = !0,
21
21
  maxHeight: d = "70dvh",
@@ -23,8 +23,8 @@ const $ = G(null), f = () => {
23
23
  maxWidth: y,
24
24
  zIndex: h = 9999
25
25
  }) => {
26
- const a = _(null), m = _(null), l = _(null), v = _(0), b = _(!1), [A, g] = E(!1), [x, N] = E(n), [F, U] = E(n), D = s !== void 0 ? s : F, R = (i) => {
27
- s === void 0 && U(i), r == null || r(i);
26
+ const a = _(null), m = _(null), l = _(null), v = _(0), b = _(!1), [A, N] = g(!1), [x, R] = g(n), [F, U] = g(n), D = s !== void 0 ? s : F, T = (i) => {
27
+ s === void 0 && U(i), t == null || t(i);
28
28
  }, S = typeof e == "boolean" ? { escapeKey: e, clickOutside: e } : {
29
29
  escapeKey: (e == null ? void 0 : e.escapeKey) ?? !1,
30
30
  clickOutside: (e == null ? void 0 : e.clickOutside) ?? !1
@@ -35,23 +35,23 @@ const $ = G(null), f = () => {
35
35
  });
36
36
  const p = () => {
37
37
  if (!a.current) {
38
- g(!1), setTimeout(() => {
39
- N(!1), R(!1);
38
+ N(!1), setTimeout(() => {
39
+ R(!1), T(!1);
40
40
  }, 300);
41
41
  return;
42
42
  }
43
- a.current.style.transition = "transform 0.3s ease", a.current.style.transform = "translateY(100%)", g(!1), setTimeout(() => {
44
- N(!1), R(!1);
43
+ a.current.style.transition = "transform 0.3s ease", a.current.style.transform = "translateY(100%)", N(!1), setTimeout(() => {
44
+ R(!1), T(!1);
45
45
  }, 300);
46
46
  };
47
- M(() => {
48
- D ? N(!0) : x && p();
49
- }, [D]), M(() => {
47
+ Y(() => {
48
+ D ? R(!0) : x && p();
49
+ }, [D]), Y(() => {
50
50
  if (!x || !a.current) return;
51
51
  const i = a.current;
52
52
  i.style.transition = "none", i.style.transform = "translateY(100%)", requestAnimationFrame(() => {
53
53
  requestAnimationFrame(() => {
54
- i.style.transition = "transform 0.3s ease", i.style.transform = "translateY(0)", g(!0);
54
+ i.style.transition = "transform 0.3s ease", i.style.transform = "translateY(0)", N(!0);
55
55
  });
56
56
  });
57
57
  }, [x]), Z({
@@ -64,7 +64,7 @@ const $ = G(null), f = () => {
64
64
  });
65
65
  const j = {
66
66
  open: x,
67
- setOpen: R,
67
+ setOpen: T,
68
68
  closeOnBackdrop: e,
69
69
  closeOnDrag: o,
70
70
  maxHeight: d,
@@ -81,8 +81,8 @@ const $ = G(null), f = () => {
81
81
  handleDragMove: (i) => {
82
82
  if (!o || !a.current || l.current === null || !m.current)
83
83
  return;
84
- const T = i - l.current;
85
- m.current.scrollTop <= 0 && T > 0 && (b.current = !0, v.current = T, a.current.style.transition = "none", a.current.style.transform = `translateY(${T}px)`);
84
+ const E = i - l.current;
85
+ m.current.scrollTop <= 0 && E > 0 && (b.current = !0, v.current = E, a.current.style.transition = "none", a.current.style.transform = `translateY(${E}px)`);
86
86
  },
87
87
  handleDragEnd: () => {
88
88
  if (!o || !a.current) return;
@@ -90,42 +90,44 @@ const $ = G(null), f = () => {
90
90
  a.current.style.transition = "transform 0.3s ease", b.current && v.current > i ? p() : (a.current.style.transform = "translateY(0)", v.current = 0), b.current = !1, l.current = null;
91
91
  }
92
92
  };
93
- return /* @__PURE__ */ u($.Provider, { value: j, children: t });
93
+ return /* @__PURE__ */ u($.Provider, { value: j, children: r });
94
94
  };
95
95
  C.displayName = "Drawer.Root";
96
96
  const P = w(
97
- ({ children: t, asChild: s, onClick: n, ...r }, e) => {
97
+ ({ children: r, asChild: s, onClick: n, ...t }, e) => {
98
98
  const { setOpen: o } = f(), d = (c) => {
99
99
  n == null || n(c), o(!0);
100
100
  };
101
101
  return s ? /* @__PURE__ */ u(
102
- Y,
102
+ M,
103
103
  {
104
- ...r,
104
+ ...t,
105
105
  onClick: d,
106
106
  ref: e,
107
- children: t
107
+ children: r
108
108
  }
109
- ) : /* @__PURE__ */ u("button", { type: "button", onClick: d, ref: e, ...r, children: t });
109
+ ) : /* @__PURE__ */ u("button", { type: "button", onClick: d, ref: e, ...t, children: r });
110
110
  }
111
111
  );
112
112
  P.displayName = "Drawer.Trigger";
113
113
  const V = ({
114
- children: t,
114
+ children: r,
115
115
  container: s
116
116
  }) => {
117
- const { open: n } = f();
118
- return !n || typeof document > "u" ? null : Q(t, s || document.body);
117
+ const { open: n } = f(), [t, e] = g(!1);
118
+ return Y(() => {
119
+ e(!0);
120
+ }, []), !t || !n ? null : Q(r, s || document.body);
119
121
  };
120
122
  V.displayName = "Drawer.Portal";
121
123
  const H = w(
122
- ({ className: t, ...s }, n) => {
123
- const { isVisible: r, zIndex: e } = f();
124
+ ({ className: r, ...s }, n) => {
125
+ const { isVisible: t, zIndex: e } = f();
124
126
  return /* @__PURE__ */ u(
125
127
  "div",
126
128
  {
127
129
  ref: n,
128
- className: `motile-drawer__overlay ${r ? "motile-drawer__overlay--visible" : ""} ${t || ""}`,
130
+ className: `motile-drawer__overlay ${t ? "motile-drawer__overlay--visible" : ""} ${r || ""}`,
129
131
  style: { zIndex: e },
130
132
  role: "presentation",
131
133
  ...s
@@ -135,7 +137,7 @@ const H = w(
135
137
  );
136
138
  H.displayName = "Drawer.Overlay";
137
139
  const K = w(
138
- ({ className: t, style: s, children: n, ...r }, e) => {
140
+ ({ className: r, style: s, children: n, ...t }, e) => {
139
141
  const { drawerRef: o, isVisible: d, maxHeight: c, width: y, maxWidth: h, zIndex: a } = f(), m = {
140
142
  ...c !== "70dvh" && { "--drawer-max-height": c },
141
143
  ...y !== "480px" && { "--drawer-width": y },
@@ -149,12 +151,12 @@ const K = w(
149
151
  ref: (l) => {
150
152
  typeof e == "function" ? e(l) : e && (e.current = l), o.current = l;
151
153
  },
152
- className: `motile-drawer__content ${d ? "motile-drawer__content--visible" : ""} ${t || ""}`,
154
+ className: `motile-drawer__content ${d ? "motile-drawer__content--visible" : ""} ${r || ""}`,
153
155
  style: m,
154
156
  onClick: (l) => l.stopPropagation(),
155
157
  role: "dialog",
156
158
  "aria-modal": "true",
157
- ...r,
159
+ ...t,
158
160
  children: n
159
161
  }
160
162
  );
@@ -162,15 +164,15 @@ const K = w(
162
164
  );
163
165
  K.displayName = "Drawer.Content";
164
166
  const L = w(
165
- ({ className: t, ...s }, n) => {
166
- const { handleDragStart: r, handleDragMove: e, handleDragEnd: o } = f(), d = (a) => {
167
- r(a.touches[0].clientY);
167
+ ({ className: r, ...s }, n) => {
168
+ const { handleDragStart: t, handleDragMove: e, handleDragEnd: o } = f(), d = (a) => {
169
+ t(a.touches[0].clientY);
168
170
  }, c = (a) => {
169
171
  e(a.touches[0].clientY);
170
172
  }, y = () => {
171
173
  o();
172
174
  }, h = (a) => {
173
- r(a.clientY);
175
+ t(a.clientY);
174
176
  const m = (v) => {
175
177
  e(v.clientY);
176
178
  }, l = () => {
@@ -182,7 +184,7 @@ const L = w(
182
184
  "div",
183
185
  {
184
186
  ref: n,
185
- className: `motile-drawer__header ${t || ""}`,
187
+ className: `motile-drawer__header ${r || ""}`,
186
188
  onTouchStart: d,
187
189
  onTouchMove: c,
188
190
  onTouchEnd: y,
@@ -195,13 +197,13 @@ const L = w(
195
197
  );
196
198
  L.displayName = "Drawer.Handle";
197
199
  const I = w(
198
- ({ children: t, asChild: s, className: n, ...r }, e) => s && W.isValidElement(t) ? /* @__PURE__ */ u(
199
- Y,
200
+ ({ children: r, asChild: s, className: n, ...t }, e) => s && W.isValidElement(r) ? /* @__PURE__ */ u(
201
+ M,
200
202
  {
201
- ...r,
203
+ ...t,
202
204
  className: `motile-drawer__title ${n || ""}`,
203
205
  ref: e,
204
- children: t
206
+ children: r
205
207
  }
206
208
  ) : /* @__PURE__ */ u("div", { className: "motile-drawer__title-wrapper", children: /* @__PURE__ */ u(
207
209
  "h2",
@@ -209,22 +211,22 @@ const I = w(
209
211
  ref: e,
210
212
  id: "motile-drawer-title",
211
213
  className: `motile-drawer__title ${n || ""}`,
212
- ...r,
213
- children: t
214
+ ...t,
215
+ children: r
214
216
  }
215
217
  ) })
216
218
  );
217
219
  I.displayName = "Drawer.Title";
218
220
  const z = w(
219
- ({ className: t, children: s, ...n }, r) => {
221
+ ({ className: r, children: s, ...n }, t) => {
220
222
  const { bodyRef: e } = f();
221
223
  return /* @__PURE__ */ u(
222
224
  "div",
223
225
  {
224
226
  ref: (o) => {
225
- typeof r == "function" ? r(o) : r && (r.current = o), e.current = o;
227
+ typeof t == "function" ? t(o) : t && (t.current = o), e.current = o;
226
228
  },
227
- className: `motile-drawer__body ${t || ""}`,
229
+ className: `motile-drawer__body ${r || ""}`,
228
230
  "data-scroll-allowed": !0,
229
231
  ...n,
230
232
  children: s
@@ -234,19 +236,19 @@ const z = w(
234
236
  );
235
237
  z.displayName = "Drawer.Body";
236
238
  const q = w(
237
- ({ children: t, asChild: s, onClick: n, ...r }, e) => {
239
+ ({ children: r, asChild: s, onClick: n, ...t }, e) => {
238
240
  const { handleClose: o } = f(), d = (c) => {
239
241
  n == null || n(c), o();
240
242
  };
241
243
  return s ? /* @__PURE__ */ u(
242
- Y,
244
+ M,
243
245
  {
244
- ...r,
246
+ ...t,
245
247
  onClick: d,
246
248
  ref: e,
247
- children: t
249
+ children: r
248
250
  }
249
- ) : /* @__PURE__ */ u("button", { type: "button", onClick: d, ref: e, ...r, children: t });
251
+ ) : /* @__PURE__ */ u("button", { type: "button", onClick: d, ref: e, ...t, children: r });
250
252
  }
251
253
  );
252
254
  q.displayName = "Drawer.Close";
@@ -1,17 +1,17 @@
1
- import { jsx as l, jsxs as H } from "react/jsx-runtime";
2
- import n, { useRef as K, useId as h, createContext as L, useContext as k } from "react";
3
- import { createPortal as O } from "react-dom";
4
- import { Slot as P } from "../../utils/Slot.js";
5
- import { useClickOutside as V } from "../../hooks/useClickOutside.js";
6
- import { useEscapeKey as q } from "../../hooks/useEscapeKey.js";
7
- import { useScrollLock as z } from "../../hooks/useScrollLock.js";
1
+ import { jsx as l, jsxs as L } from "react/jsx-runtime";
2
+ import n, { useRef as k, useState as O, useEffect as P, useId as h, createContext as V, useContext as q } from "react";
3
+ import { createPortal as z } from "react-dom";
4
+ import { Slot as A } from "../../utils/Slot.js";
5
+ import { useClickOutside as D } from "../../hooks/useClickOutside.js";
6
+ import { useEscapeKey as G } from "../../hooks/useEscapeKey.js";
7
+ import { useScrollLock as J } from "../../hooks/useScrollLock.js";
8
8
  import './Modal.css';/* empty css */
9
- const v = L(null), m = () => {
10
- const o = k(v);
9
+ const v = V(null), m = () => {
10
+ const o = q(v);
11
11
  if (!o)
12
12
  throw new Error("Modal compound components must be used within Modal.Root");
13
13
  return o;
14
- }, A = ({
14
+ }, Q = ({
15
15
  open: o,
16
16
  onOpenChange: t,
17
17
  children: e
@@ -35,47 +35,51 @@ const v = L(null), m = () => {
35
35
  width: d,
36
36
  maxWidth: r,
37
37
  zIndex: s = 1e3,
38
- className: f,
38
+ className: u,
39
39
  onClick: i,
40
40
  style: $,
41
41
  ...p
42
42
  }, g) => {
43
- const { open: c, onOpenChange: u } = m(), M = K(null), b = typeof e == "boolean" ? e : e.clickOutside ?? !1, S = typeof e == "boolean" ? e : e.escapeKey ?? !1;
44
- z({
43
+ const { open: c, onOpenChange: f } = m(), M = k(null), [S, E] = O(!1);
44
+ P(() => {
45
+ E(!0);
46
+ }, []);
47
+ const b = typeof e == "boolean" ? e : e.clickOutside ?? !1, T = typeof e == "boolean" ? e : e.escapeKey ?? !1;
48
+ J({
45
49
  enabled: c && !a,
46
50
  allowedSelectors: [".motile-modal__content"]
47
- }), V({
51
+ }), D({
48
52
  refs: [M],
49
53
  handler: () => {
50
- b && u(!1);
54
+ b && f(!1);
51
55
  },
52
56
  enabled: c
53
- }), q({
57
+ }), G({
54
58
  handler: () => {
55
- S && u(!1);
59
+ T && f(!1);
56
60
  },
57
61
  enabled: c
58
62
  });
59
- const T = (y) => {
60
- i == null || i(y), y.target === y.currentTarget && b && u(!1);
63
+ const j = (y) => {
64
+ i == null || i(y), y.target === y.currentTarget && b && f(!1);
61
65
  };
62
- if (!c || typeof document > "u") return null;
63
- const j = {
66
+ if (!S || !c) return null;
67
+ const F = {
64
68
  zIndex: s,
65
69
  ...$
66
- }, E = {
70
+ }, H = {
67
71
  ...d && { "--modal-width": d },
68
72
  ...r && { "--modal-max-width": r },
69
73
  zIndex: s + 1
70
- }, F = /* @__PURE__ */ l(
74
+ }, K = /* @__PURE__ */ l(
71
75
  "div",
72
76
  {
73
77
  ref: g,
74
- className: `motile-modal__backdrop ${f || ""}`,
78
+ className: `motile-modal__backdrop ${u || ""}`,
75
79
  "data-state": c ? "open" : "closed",
76
80
  "data-variant": t,
77
- onClick: T,
78
- style: j,
81
+ onClick: j,
82
+ style: F,
79
83
  ...p,
80
84
  children: /* @__PURE__ */ l(
81
85
  "div",
@@ -83,13 +87,13 @@ const v = L(null), m = () => {
83
87
  ref: M,
84
88
  className: "motile-modal",
85
89
  "data-variant": t,
86
- style: E,
90
+ style: H,
87
91
  children: p.children
88
92
  }
89
93
  )
90
94
  }
91
95
  );
92
- return O(F, o || document.body);
96
+ return z(K, o || document.body);
93
97
  }
94
98
  );
95
99
  _.displayName = "Modal.Overlay";
@@ -144,14 +148,14 @@ const x = n.forwardRef(
144
148
  x.displayName = "Modal.Body";
145
149
  const R = n.forwardRef(
146
150
  ({ asChild: o, className: t, onClick: e, children: a, ...d }, r) => {
147
- const { onOpenChange: s } = m(), f = (i) => {
151
+ const { onOpenChange: s } = m(), u = (i) => {
148
152
  e == null || e(i), s(!1);
149
153
  };
150
154
  return o ? /* @__PURE__ */ l(
151
- P,
155
+ A,
152
156
  {
153
157
  ...d,
154
- onClick: f,
158
+ onClick: u,
155
159
  ref: r,
156
160
  children: a
157
161
  }
@@ -161,10 +165,10 @@ const R = n.forwardRef(
161
165
  ref: r,
162
166
  type: "button",
163
167
  className: `motile-modal__close ${t || ""}`,
164
- onClick: f,
168
+ onClick: u,
165
169
  "aria-label": "닫기",
166
170
  ...d,
167
- children: a || /* @__PURE__ */ H(
171
+ children: a || /* @__PURE__ */ L(
168
172
  "svg",
169
173
  {
170
174
  width: "18",
@@ -208,8 +212,8 @@ const I = n.forwardRef(
208
212
  )
209
213
  );
210
214
  I.displayName = "Modal.Header";
211
- const Z = {
212
- Root: A,
215
+ const te = {
216
+ Root: Q,
213
217
  Overlay: _,
214
218
  Content: N,
215
219
  Title: w,
@@ -219,13 +223,13 @@ const Z = {
219
223
  Header: I
220
224
  };
221
225
  export {
222
- Z as Modal,
226
+ te as Modal,
223
227
  x as ModalBody,
224
228
  R as ModalClose,
225
229
  N as ModalContent,
226
230
  C as ModalFooter,
227
231
  I as ModalHeader,
228
232
  _ as ModalOverlay,
229
- A as ModalRoot,
233
+ Q as ModalRoot,
230
234
  w as ModalTitle
231
235
  };