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,18 +1,18 @@
1
- import { jsxs as tt, jsx as W } from "react/jsx-runtime";
2
- import et, { useState as A, useEffect as H, useCallback as T, useId as ot, useRef as I, useLayoutEffect as nt, createContext as rt, useContext as it } from "react";
1
+ import { jsxs as tt, jsx as $ } from "react/jsx-runtime";
2
+ import et, { useState as S, useEffect as P, useCallback as T, useId as ot, useRef as A, useLayoutEffect as nt, createContext as rt, useContext as it } from "react";
3
3
  import { createPortal as st } from "react-dom";
4
4
  import { Slot as at } from "../../utils/Slot.js";
5
5
  import { FloatingArrow as lt } from "../../utils/FloatingArrow.js";
6
6
  import './Tooltip.css';/* empty css */
7
- const G = rt(null);
8
- function X() {
9
- const t = it(G);
7
+ const Z = rt(null);
8
+ function J() {
9
+ const t = it(Z);
10
10
  if (!t)
11
11
  throw new Error("Tooltip components must be used within Tooltip.Root");
12
12
  return t;
13
13
  }
14
14
  const s = 8;
15
- function D(t, e, r, i, a, m, u) {
15
+ function X(t, e, r, i, a, f, u) {
16
16
  switch (t) {
17
17
  case "top":
18
18
  return e.top - a.top - i >= s;
@@ -21,7 +21,7 @@ function D(t, e, r, i, a, m, u) {
21
21
  case "left":
22
22
  return e.left - a.left - r >= s;
23
23
  case "right":
24
- return e.right + a.right + r <= m - s;
24
+ return e.right + a.right + r <= f - s;
25
25
  }
26
26
  }
27
27
  function ct(t) {
@@ -45,10 +45,10 @@ function pt(t, e, r, i) {
45
45
  left: t.left - e.left - s,
46
46
  right: r - t.right - e.right - s
47
47
  };
48
- let m = "bottom", u = a.bottom;
48
+ let f = "bottom", u = a.bottom;
49
49
  for (const [n, l] of Object.entries(a))
50
- l > u && (u = l, m = n);
51
- return m;
50
+ l > u && (u = l, f = n);
51
+ return f;
52
52
  }
53
53
  function ft({
54
54
  children: t,
@@ -56,7 +56,7 @@ function ft({
56
56
  align: r = "center",
57
57
  variant: i = "filled",
58
58
  color: a,
59
- showArrow: m = !1,
59
+ showArrow: f = !1,
60
60
  keepOpen: u = !1,
61
61
  offset: n
62
62
  }) {
@@ -65,52 +65,52 @@ function ft({
65
65
  bottom: n.bottom ?? 6,
66
66
  left: n.left ?? 6,
67
67
  right: n.right ?? 6
68
- }, k = ot().replace(/:/g, ""), w = I(null), x = I(null), p = I(), [b, N] = A(!1), [P, Z] = A(e), [J, K] = A({}), F = I(null), B = T((M, E = 0) => {
69
- p.current && (clearTimeout(p.current), p.current = void 0), !M && E > 0 ? p.current = window.setTimeout(
70
- () => N(!1),
68
+ }, M = ot().replace(/:/g, ""), w = A(null), x = A(null), m = A(), [b, L] = S(!1), [B, z] = S(e), [H, K] = S({}), F = A(null), W = T((k, E = 0) => {
69
+ m.current && (clearTimeout(m.current), m.current = void 0), !k && E > 0 ? m.current = window.setTimeout(
70
+ () => L(!1),
71
71
  E
72
- ) : N(M);
72
+ ) : L(k);
73
73
  }, []);
74
74
  nt(() => {
75
75
  if (!b || !w.current || !x.current) return;
76
- const M = () => {
76
+ const k = () => {
77
77
  if (!w.current || !x.current) return;
78
78
  const o = w.current.getBoundingClientRect(), y = x.current;
79
79
  y.classList.add("measuring"), y.offsetHeight;
80
- const $ = window.getComputedStyle(y), V = parseFloat($.width), Y = parseFloat($.height);
81
- let c = V, d = Y;
80
+ const Y = window.getComputedStyle(y), _ = parseFloat(Y.width), q = parseFloat(Y.height);
81
+ let c = _, d = q;
82
82
  y.classList.remove("measuring");
83
83
  const R = window.innerWidth, O = window.innerHeight;
84
84
  (isNaN(c) || c <= 0) && (c = 100), (isNaN(d) || d <= 0) && (d = 50);
85
- const _ = R - s * 2, z = O - s * 2;
86
- c > _ && (c = _), d > z && (d = z);
85
+ const U = R - s * 2, j = O - s * 2;
86
+ c > U && (c = U), d > j && (d = j);
87
87
  let v = e;
88
- if (o.width === 0 && o.height === 0 || D(e, o, c, d, l, R, O))
88
+ if (o.width === 0 && o.height === 0 || X(e, o, c, d, l, R, O))
89
89
  v = e;
90
90
  else {
91
- const L = ut(e, o, R, O);
92
- let q = !1;
93
- for (const U of L)
94
- if (D(U, o, c, d, l, R, O)) {
95
- v = U, q = !0;
91
+ const N = ut(e, o, R, O);
92
+ let D = !1;
93
+ for (const G of N)
94
+ if (X(G, o, c, d, l, R, O)) {
95
+ v = G, D = !0;
96
96
  break;
97
97
  }
98
- q || (v = pt(o, l, R, O));
98
+ D || (v = pt(o, l, R, O));
99
99
  }
100
- let f = 0, g = 0;
100
+ let p = 0, g = 0;
101
101
  if (v === "top" || v === "bottom") {
102
102
  switch (r) {
103
103
  case "start":
104
- f = o.left;
104
+ p = o.left;
105
105
  break;
106
106
  case "center":
107
- f = o.left + o.width / 2 - c / 2;
107
+ p = o.left + o.width / 2 - c / 2;
108
108
  break;
109
109
  case "end":
110
- f = o.right - c;
110
+ p = o.right - c;
111
111
  break;
112
112
  }
113
- f = Math.max(s, Math.min(f, R - s - c)), g = v === "top" ? o.top - l.top - d : o.bottom + l.bottom, g = Math.max(s, Math.min(g, O - s - d));
113
+ p = Math.max(s, Math.min(p, R - s - c)), g = v === "top" ? o.top - l.top - d : o.bottom + l.bottom, g = Math.max(s, Math.min(g, O - s - d));
114
114
  } else {
115
115
  switch (r) {
116
116
  case "start":
@@ -123,134 +123,134 @@ function ft({
123
123
  g = o.bottom - d;
124
124
  break;
125
125
  }
126
- g = Math.max(s, Math.min(g, O - s - d)), v === "left" ? (f = o.left - l.left - c, f < s && (c = o.left - l.left - s, f = s)) : (f = o.right + l.right, f + c > R - s && (c = R - s - f));
126
+ g = Math.max(s, Math.min(g, O - s - d)), v === "left" ? (p = o.left - l.left - c, p < s && (c = o.left - l.left - s, p = s)) : (p = o.right + l.right, p + c > R - s && (c = R - s - p));
127
127
  }
128
128
  let h = 0;
129
- const S = 12, C = 16;
129
+ const I = 12, C = 16;
130
130
  if (v === "left" || v === "right") {
131
131
  switch (r) {
132
132
  case "start":
133
- h = o.top - g + S;
133
+ h = o.top - g + I;
134
134
  break;
135
135
  case "center":
136
136
  h = o.top + o.height / 2 - g;
137
137
  break;
138
138
  case "end":
139
- h = o.bottom - g - S;
139
+ h = o.bottom - g - I;
140
140
  break;
141
141
  }
142
- const L = Math.max(C, d - C);
142
+ const N = Math.max(C, d - C);
143
143
  h = Math.max(
144
144
  C,
145
- Math.min(h, L)
145
+ Math.min(h, N)
146
146
  );
147
147
  } else {
148
148
  switch (r) {
149
149
  case "start":
150
- h = o.left - f + S;
150
+ h = o.left - p + I;
151
151
  break;
152
152
  case "center":
153
- h = o.left + o.width / 2 - f;
153
+ h = o.left + o.width / 2 - p;
154
154
  break;
155
155
  case "end":
156
- h = o.right - f - S;
156
+ h = o.right - p - I;
157
157
  break;
158
158
  }
159
- const L = Math.max(C, c - C);
159
+ const N = Math.max(C, c - C);
160
160
  h = Math.max(
161
161
  C,
162
- Math.min(h, L)
162
+ Math.min(h, N)
163
163
  );
164
164
  }
165
- isNaN(h) && (h = C), Z(v), K({
166
- left: Math.round(f),
165
+ isNaN(h) && (h = C), z(v), K({
166
+ left: Math.round(p),
167
167
  top: Math.round(g),
168
- ...c !== V && { maxWidth: c },
169
- ...d !== Y && { maxHeight: z },
168
+ ...c !== _ && { maxWidth: c },
169
+ ...d !== q && { maxHeight: j },
170
170
  "--arrow-offset": `${Math.round(h)}px`,
171
171
  ...a && { "--motile-tooltip-color": a }
172
172
  });
173
173
  }, E = () => {
174
174
  F.current === null && (F.current = requestAnimationFrame(() => {
175
- M(), F.current = null;
175
+ k(), F.current = null;
176
176
  }));
177
177
  };
178
- M(), window.addEventListener("scroll", E, {
178
+ k(), window.addEventListener("scroll", E, {
179
179
  passive: !0,
180
180
  capture: !0
181
181
  }), window.addEventListener("resize", E, { passive: !0 });
182
- const j = new ResizeObserver(E);
183
- return w.current && j.observe(w.current), () => {
184
- F.current !== null && (cancelAnimationFrame(F.current), F.current = null), window.removeEventListener("scroll", E, { capture: !0 }), window.removeEventListener("resize", E), j.disconnect();
182
+ const V = new ResizeObserver(E);
183
+ return w.current && V.observe(w.current), () => {
184
+ F.current !== null && (cancelAnimationFrame(F.current), F.current = null), window.removeEventListener("scroll", E, { capture: !0 }), window.removeEventListener("resize", E), V.disconnect();
185
185
  };
186
- }, [b, e, r, a, n]), H(() => {
186
+ }, [b, e, r, a, n]), P(() => {
187
187
  if (!b) return;
188
- const M = () => {
189
- B(!1, 0);
188
+ const k = () => {
189
+ W(!1, 0);
190
190
  };
191
- return window.addEventListener("scroll", M, { capture: !0 }), () => {
192
- window.removeEventListener("scroll", M, { capture: !0 });
191
+ return window.addEventListener("scroll", k, { capture: !0 }), () => {
192
+ window.removeEventListener("scroll", k, { capture: !0 });
193
193
  };
194
- }, [b, B]), H(() => () => {
195
- p.current && clearTimeout(p.current);
194
+ }, [b, W]), P(() => () => {
195
+ m.current && clearTimeout(m.current);
196
196
  }, []);
197
197
  const Q = {
198
198
  open: b,
199
- setOpen: B,
199
+ setOpen: W,
200
200
  position: e,
201
201
  align: r,
202
202
  variant: i,
203
- showArrow: m,
203
+ showArrow: f,
204
204
  color: a,
205
205
  keepOpen: u,
206
- tooltipId: `${k}-tooltip`,
206
+ tooltipId: `${M}-tooltip`,
207
207
  triggerRef: w,
208
208
  contentRef: x,
209
- style: J,
210
- placement: P
209
+ style: H,
210
+ placement: B
211
211
  };
212
- return /* @__PURE__ */ W(G.Provider, { value: Q, children: t });
212
+ return /* @__PURE__ */ $(Z.Provider, { value: Q, children: t });
213
213
  }
214
214
  function mt({ children: t, asChild: e = !1 }) {
215
- const { open: r, setOpen: i, tooltipId: a, triggerRef: m, keepOpen: u } = X(), n = T(() => {
215
+ const { open: r, setOpen: i, tooltipId: a, triggerRef: f, keepOpen: u } = J(), n = T(() => {
216
216
  i(!0, 0);
217
217
  }, [i]), l = T(() => {
218
218
  u ? i(!1, 100) : i(!1, 0);
219
- }, [i, u]), k = T(() => {
219
+ }, [i, u]), M = T(() => {
220
220
  i(!0, 0);
221
221
  }, [i]), w = T(() => {
222
222
  i(!1, 0);
223
223
  }, [i]), x = T(() => {
224
224
  i(!r, 0);
225
225
  }, [i, r]);
226
- return e ? /* @__PURE__ */ W(
226
+ return e ? /* @__PURE__ */ $(
227
227
  at,
228
228
  {
229
- ref: (p) => {
230
- m.current = p;
229
+ ref: (m) => {
230
+ f.current = m;
231
231
  },
232
232
  className: "motile-tooltip-trigger",
233
233
  "aria-describedby": r ? a : void 0,
234
234
  tabIndex: 0,
235
235
  onMouseEnter: n,
236
236
  onMouseLeave: l,
237
- onFocus: k,
237
+ onFocus: M,
238
238
  onBlur: w,
239
239
  onClick: x,
240
240
  children: t
241
241
  }
242
242
  ) : et.cloneElement(t, {
243
- ref: (p) => {
244
- m.current = p;
243
+ ref: (m) => {
244
+ f.current = m;
245
245
  const b = t.props.ref || t.ref;
246
- b && (typeof b == "function" ? b(p) : typeof b == "object" && b !== null && (b.current = p));
246
+ b && (typeof b == "function" ? b(m) : typeof b == "object" && b !== null && (b.current = m));
247
247
  },
248
248
  className: `motile-tooltip-trigger ${t.props.className || ""}`.trim(),
249
249
  "aria-describedby": r ? a : void 0,
250
250
  tabIndex: t.props.tabIndex ?? 0,
251
251
  onMouseEnter: n,
252
252
  onMouseLeave: l,
253
- onFocus: k,
253
+ onFocus: M,
254
254
  onBlur: w,
255
255
  onClick: x
256
256
  });
@@ -261,48 +261,50 @@ function bt({ children: t }) {
261
261
  setOpen: r,
262
262
  tooltipId: i,
263
263
  contentRef: a,
264
- variant: m,
264
+ variant: f,
265
265
  showArrow: u,
266
266
  keepOpen: n,
267
267
  align: l,
268
- style: k,
268
+ style: M,
269
269
  placement: w
270
- } = X(), [x, p] = A(!1);
271
- H(() => {
270
+ } = J(), [x, m] = S(!1), [b, L] = S(!1);
271
+ P(() => {
272
+ m(!0);
273
+ }, []), P(() => {
272
274
  e ? requestAnimationFrame(() => {
273
- p(!0);
274
- }) : p(!1);
275
+ L(!0);
276
+ }) : L(!1);
275
277
  }, [e]);
276
- const b = T(() => {
278
+ const B = T(() => {
277
279
  n && r(!0, 0);
278
- }, [n, r]), N = T(() => {
280
+ }, [n, r]), z = T(() => {
279
281
  n && r(!1, 0);
280
- }, [n, r]), P = k["--motile-tooltip-color"] || (m === "filled" ? "var(--motile-ui-tooltip, rgba(0, 0, 0, 0.9))" : "var(--motile-ui-tooltip, #3b82f6)");
281
- return !e || typeof document > "u" ? null : st(
282
+ }, [n, r]), H = M["--motile-tooltip-color"] || (f === "filled" ? "var(--motile-ui-tooltip, rgba(0, 0, 0, 0.9))" : "var(--motile-ui-tooltip, #3b82f6)");
283
+ return !x || !e ? null : st(
282
284
  /* @__PURE__ */ tt(
283
285
  "div",
284
286
  {
285
287
  ref: a,
286
288
  id: i,
287
289
  role: "tooltip",
288
- className: `motile-tooltip-bubble motile-tooltip-bubble--${m}`,
289
- "data-open": x || void 0,
290
+ className: `motile-tooltip-bubble motile-tooltip-bubble--${f}`,
291
+ "data-open": b || void 0,
290
292
  "data-placement": w,
291
293
  "data-align": l,
292
294
  "data-show-arrow": u || void 0,
293
295
  "data-keep-open": n || void 0,
294
- style: k,
296
+ style: M,
295
297
  "aria-hidden": !e,
296
- onMouseEnter: b,
297
- onMouseLeave: N,
298
+ onMouseEnter: B,
299
+ onMouseLeave: z,
298
300
  children: [
299
301
  t,
300
- u && /* @__PURE__ */ W(
302
+ u && /* @__PURE__ */ $(
301
303
  lt,
302
304
  {
303
305
  className: "motile-tooltip-arrow",
304
- variant: m,
305
- color: P
306
+ variant: f,
307
+ color: H
306
308
  }
307
309
  )
308
310
  ]
@@ -311,11 +313,11 @@ function bt({ children: t }) {
311
313
  document.body
312
314
  );
313
315
  }
314
- const Mt = {
316
+ const kt = {
315
317
  Root: ft,
316
318
  Trigger: mt,
317
319
  Content: bt
318
320
  };
319
321
  export {
320
- Mt as Tooltip
322
+ kt as Tooltip
321
323
  };
@@ -0,0 +1,5 @@
1
+ export { useScrollLock } from './useScrollLock';
2
+ export { useClickOutside } from './useClickOutside';
3
+ export type { UseClickOutsideOptions } from './useClickOutside';
4
+ export { useEscapeKey } from './useEscapeKey';
5
+ export type { UseEscapeKeyOptions } from './useEscapeKey';
@@ -0,0 +1,8 @@
1
+ import { useScrollLock as r } from "./useScrollLock.js";
2
+ import { useClickOutside as c } from "./useClickOutside.js";
3
+ import { useEscapeKey as t } from "./useEscapeKey.js";
4
+ export {
5
+ c as useClickOutside,
6
+ t as useEscapeKey,
7
+ r as useScrollLock
8
+ };
package/dist/index.d.ts CHANGED
@@ -30,8 +30,3 @@ export { Dock } from './components/Dock';
30
30
  export type { DockRootProps, DockItemProps, DockSeparatorProps, DockPosition, } from './components/Dock';
31
31
  export { SpeedDial } from './components/SpeedDial';
32
32
  export type { SpeedDialDirection, SpeedDialRootProps, SpeedDialTriggerProps, SpeedDialActionsProps, SpeedDialActionProps, } from './components/SpeedDial';
33
- export { useScrollLock } from './hooks/useScrollLock';
34
- export { useClickOutside } from './hooks/useClickOutside';
35
- export type { UseClickOutsideOptions } from './hooks/useClickOutside';
36
- export { useEscapeKey } from './hooks/useEscapeKey';
37
- export type { UseEscapeKeyOptions } from './hooks/useEscapeKey';
package/dist/index.js CHANGED
@@ -1,42 +1,36 @@
1
- import { useScrollLock as e } from "./hooks/useScrollLock.js";
2
- import { useClickOutside as p } from "./hooks/useClickOutside.js";
3
- import { useEscapeKey as f } from "./hooks/useEscapeKey.js";
4
- import { Button as a } from "./components/Button/Button.js";
5
- import { Input as s } from "./components/Input/Input.js";
6
- import { Textarea as l } from "./components/Textarea/Textarea.js";
7
- import { Checkbox as d } from "./components/Checkbox/Checkbox.js";
8
- import { Switch as S } from "./components/Switch/Switch.js";
9
- import { Accordion as T } from "./components/Accordion/Accordion.js";
10
- import { Skeleton as D } from "./components/Skeleton/Skeleton.js";
11
- import { Badge as w } from "./components/Badge/Badge.js";
12
- import { Tooltip as C } from "./components/Tooltip/Tooltip.js";
13
- import { Popover as b } from "./components/Popover/Popover.js";
14
- import { Drawer as y } from "./components/Drawer/Drawer.js";
15
- import { Sheet as E } from "./components/Sheet/Sheet.js";
16
- import { Modal as K } from "./components/Modal/Modal.js";
17
- import { ToastProvider as M } from "./components/Toast/Toast.js";
18
- import { useToast as j } from "./components/Toast/useToast.js";
19
- import { Dock as z } from "./components/Dock/Dock.js";
20
- import { SpeedDial as G } from "./components/SpeedDial/SpeedDial.js";
1
+ import { Button as e } from "./components/Button/Button.js";
2
+ import { Input as p } from "./components/Input/Input.js";
3
+ import { Textarea as f } from "./components/Textarea/Textarea.js";
4
+ import { Checkbox as a } from "./components/Checkbox/Checkbox.js";
5
+ import { Switch as d } from "./components/Switch/Switch.js";
6
+ import { Accordion as l } from "./components/Accordion/Accordion.js";
7
+ import { Skeleton as S } from "./components/Skeleton/Skeleton.js";
8
+ import { Badge as h } from "./components/Badge/Badge.js";
9
+ import { Tooltip as s } from "./components/Tooltip/Tooltip.js";
10
+ import { Popover as D } from "./components/Popover/Popover.js";
11
+ import { Drawer as w } from "./components/Drawer/Drawer.js";
12
+ import { Sheet as P } from "./components/Sheet/Sheet.js";
13
+ import { Modal as g } from "./components/Modal/Modal.js";
14
+ import { ToastProvider as C } from "./components/Toast/Toast.js";
15
+ import { useToast as M } from "./components/Toast/useToast.js";
16
+ import { Dock as q } from "./components/Dock/Dock.js";
17
+ import { SpeedDial as z } from "./components/SpeedDial/SpeedDial.js";
21
18
  export {
22
- T as Accordion,
23
- w as Badge,
24
- a as Button,
25
- d as Checkbox,
26
- z as Dock,
27
- y as Drawer,
28
- s as Input,
29
- K as Modal,
30
- b as Popover,
31
- E as Sheet,
32
- D as Skeleton,
33
- G as SpeedDial,
34
- S as Switch,
35
- l as Textarea,
36
- M as ToastProvider,
37
- C as Tooltip,
38
- p as useClickOutside,
39
- f as useEscapeKey,
40
- e as useScrollLock,
41
- j as useToast
19
+ l as Accordion,
20
+ h as Badge,
21
+ e as Button,
22
+ a as Checkbox,
23
+ q as Dock,
24
+ w as Drawer,
25
+ p as Input,
26
+ g as Modal,
27
+ D as Popover,
28
+ P as Sheet,
29
+ S as Skeleton,
30
+ z as SpeedDial,
31
+ d as Switch,
32
+ f as Textarea,
33
+ C as ToastProvider,
34
+ s as Tooltip,
35
+ M as useToast
42
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motile-ui",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "A modern React component library for webview applications",
6
6
  "main": "./dist/index.js",
@@ -48,8 +48,8 @@
48
48
  "import": "./dist/components/Popover/Popover.js"
49
49
  },
50
50
  "./Sheet": {
51
- "types": "./dist/components/Sheet/Sheet.d.ts",
52
- "import": "./dist/components/Sheet/Sheet.js"
51
+ "types": "./dist/components/Sheet/useSheetNavigation.d.ts",
52
+ "import": "./dist/components/Sheet/useSheetNavigation.js"
53
53
  },
54
54
  "./Skeleton": {
55
55
  "types": "./dist/components/Skeleton/Skeleton.d.ts",
@@ -83,17 +83,9 @@
83
83
  "types": "./dist/components/Toast/useToast.d.ts",
84
84
  "import": "./dist/components/Toast/useToast.js"
85
85
  },
86
- "./useScrollLock": {
87
- "types": "./dist/hooks/useScrollLock.d.ts",
88
- "import": "./dist/hooks/useScrollLock.js"
89
- },
90
- "./useClickOutside": {
91
- "types": "./dist/hooks/useClickOutside.d.ts",
92
- "import": "./dist/hooks/useClickOutside.js"
93
- },
94
- "./useEscapeKey": {
95
- "types": "./dist/hooks/useEscapeKey.d.ts",
96
- "import": "./dist/hooks/useEscapeKey.js"
86
+ "./hooks": {
87
+ "types": "./dist/hooks/index.d.ts",
88
+ "import": "./dist/hooks/index.js"
97
89
  }
98
90
  },
99
91
  "files": [