motile-ui 1.1.0 → 1.1.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 +1 @@
1
- .motile-btn{width:fit-content;border:none;border-radius:12px;font-weight:600;cursor:pointer;transition:all .2s cubic-bezier(.4,0,.2,1);outline:none;display:inline-flex;align-items:center;justify-content:center;position:relative;overflow:hidden;min-height:fit-content}.motile-btn:active:not(.motile-btn--disabled){filter:brightness(.95);box-shadow:0 2px 4px #0000001a}.motile-btn--primary{background:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );color:#fff;box-shadow:0 1px 2px #0000000d}@media (hover: hover){.motile-btn--primary:hover:not(.motile-btn--disabled){filter:brightness(.9);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--primary:hover:not(.motile-btn--disabled){filter:brightness(.9);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--secondary{background:#fff;color:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );border:1px solid var(--motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)));box-shadow:none}@media (hover: hover){.motile-btn--secondary:hover:not(.motile-btn--disabled){background:color-mix(in srgb,var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) ) 10%,transparent);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--secondary:hover:not(.motile-btn--disabled){background:color-mix(in srgb,var(--motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6))) 10%,transparent);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--ghost{background:transparent;border:none;color:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );box-shadow:none}@media (hover: hover){.motile-btn--ghost:hover:not(.motile-btn--disabled){box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--ghost:hover:not(.motile-btn--disabled){box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--large{padding:0 24px;font-size:16px;height:56px;min-height:56px;line-height:1.4}.motile-btn--medium{padding:0 20px;font-size:15px;height:48px;min-height:48px;min-width:80px;line-height:1.4}.motile-btn--small{padding:0 16px;font-size:14px;height:40px;min-height:40px;min-width:64px;line-height:1.4}.motile-btn--primary.motile-btn--disabled{opacity:.5;filter:saturate(.9);cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--secondary.motile-btn--disabled{background:#e5e7eb;color:#6b7280;border:none;cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--ghost.motile-btn--disabled{background:#e5e7eb;color:#6b7280;cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--full-width{width:100%}.motile-btn svg{flex-shrink:0;margin-right:8px}.motile-btn svg:last-child{margin-right:0;margin-left:8px}.motile-btn svg:only-child{margin:0}@media (max-width: 1024px){.motile-btn--large{padding:0 20px;font-size:15px;height:52px;min-height:52px}}@media (max-width: 768px){.motile-btn--large{padding:0 18px;font-size:14px;height:48px;min-height:48px}.motile-btn:active:not(.motile-btn--disabled){filter:brightness(.92)}}@supports (-webkit-touch-callout: none){.motile-btn{-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}}.motile-btn__wrapper{display:grid;grid-template-areas:"content";place-items:center;width:100%;height:100%}.motile-btn__content{grid-area:content;display:inline-flex;align-items:center;justify-content:center}.motile-btn__loading{grid-area:content;display:flex;align-items:center;justify-content:center}.motile-btn__dots{display:flex;gap:8px;align-items:center;height:1em}.motile-btn--large .motile-btn__dot{width:8px;height:8px}.motile-btn--medium .motile-btn__dot{width:6px;height:6px}.motile-btn--small .motile-btn__dot{width:5px;height:5px}.motile-btn__dot{border-radius:50%;background-color:#ffffffb3;animation:motile-btn-loading-bounce 1.4s ease-in-out infinite both}.motile-btn__dot:nth-child(1){animation-delay:-.32s}.motile-btn__dot:nth-child(2){animation-delay:-.16s}.motile-btn__dot:nth-child(3){animation-delay:0s}.motile-btn--primary .motile-btn__dot{background-color:#ffffffb3}.motile-btn--secondary .motile-btn__dot,.motile-btn--ghost .motile-btn__dot{background-color:#9ca3afb3}@keyframes motile-btn-loading-bounce{0%,80%,to{transform:scale(1);opacity:.4}40%{transform:scale(1.2);opacity:1}}
1
+ .motile-btn{width:fit-content;border:none;border-radius:12px;font-weight:600;cursor:pointer;transition:all .2s cubic-bezier(.4,0,.2,1);outline:none;display:inline-flex;align-items:center;justify-content:center;position:relative;overflow:hidden;min-height:fit-content}.motile-btn:active:not(.motile-btn--disabled){filter:brightness(.95);box-shadow:0 2px 4px #0000001a}.motile-btn--primary{background:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );color:#fff;box-shadow:0 1px 2px #0000000d}@media (hover: hover){.motile-btn--primary:hover:not(.motile-btn--disabled){filter:brightness(.9);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--primary:hover:not(.motile-btn--disabled){filter:brightness(.9);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--secondary{background:#fff;color:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );border:1px solid var(--motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)));box-shadow:none}@media (hover: hover){.motile-btn--secondary:hover:not(.motile-btn--disabled){background:color-mix(in srgb,var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) ) 10%,transparent);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--secondary:hover:not(.motile-btn--disabled){background:color-mix(in srgb,var(--motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6))) 10%,transparent);box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--ghost{background:transparent;border:none;color:var( --motile-btn-color, var(--motile-ui-btn, var(--motile-theme, #3b82f6)) );box-shadow:none}@media (hover: hover){.motile-btn--ghost:hover:not(.motile-btn--disabled){box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}}.motile-btn--hover-on-touch.motile-btn--ghost:hover:not(.motile-btn--disabled){box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}.motile-btn--large{padding:0 24px;font-size:16px;height:56px;min-height:56px;line-height:1.4}.motile-btn--medium{padding:0 20px;font-size:15px;height:48px;min-height:48px;min-width:80px;line-height:1.4}.motile-btn--small{padding:0 16px;font-size:14px;height:40px;min-height:40px;min-width:64px;line-height:1.4}.motile-btn--primary.motile-btn--disabled{opacity:.5;filter:saturate(.9);cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--secondary.motile-btn--disabled{background:#e5e7eb;color:#6b7280;border:none;cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--ghost.motile-btn--disabled{background:#e5e7eb;color:#6b7280;cursor:not-allowed;transform:none;box-shadow:none;pointer-events:none}.motile-btn--full-width{width:100%}.motile-btn svg{flex-shrink:0;margin-right:8px}.motile-btn svg:last-child{margin-right:0;margin-left:8px}.motile-btn svg:only-child{margin:0}@media (max-width: 1024px){.motile-btn--large{padding:0 20px;font-size:15px;height:54px;min-height:54px}}@media (max-width: 768px){.motile-btn--large{padding:0 18px;font-size:15px;height:52px;min-height:52px}.motile-btn:active:not(.motile-btn--disabled){filter:brightness(.92)}}@supports (-webkit-touch-callout: none){.motile-btn{-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}}.motile-btn__wrapper{display:grid;grid-template-areas:"content";place-items:center;width:100%;height:100%}.motile-btn__content{grid-area:content;display:inline-flex;align-items:center;justify-content:center}.motile-btn__loading{grid-area:content;display:flex;align-items:center;justify-content:center}.motile-btn__dots{display:flex;gap:8px;align-items:center;height:1em}.motile-btn--large .motile-btn__dot{width:8px;height:8px}.motile-btn--medium .motile-btn__dot{width:6px;height:6px}.motile-btn--small .motile-btn__dot{width:5px;height:5px}.motile-btn__dot{border-radius:50%;background-color:#ffffffb3;animation:motile-btn-loading-bounce 1.4s ease-in-out infinite both}.motile-btn__dot:nth-child(1){animation-delay:-.32s}.motile-btn__dot:nth-child(2){animation-delay:-.16s}.motile-btn__dot:nth-child(3){animation-delay:0s}.motile-btn--primary .motile-btn__dot{background-color:#ffffffb3}.motile-btn--secondary .motile-btn__dot,.motile-btn--ghost .motile-btn__dot{background-color:#9ca3afb3}@keyframes motile-btn-loading-bounce{0%,80%,to{transform:scale(1);opacity:.4}40%{transform:scale(1.2);opacity:1}}
@@ -1,27 +1,27 @@
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
- import { createPortal as st } from "react-dom";
1
+ import { jsxs as tt, jsx as V } from "react/jsx-runtime";
2
+ import et, { useState as A, useEffect as B, useCallback as C, useId as ot, useRef as y, useLayoutEffect as nt, createContext as rt, useContext as st } from "react";
3
+ import { createPortal as it } 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
7
  const Z = rt(null);
8
8
  function J() {
9
- const t = it(Z);
9
+ const t = st(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
- const s = 8;
15
- function X(t, e, r, i, a, f, u) {
14
+ const i = 8;
15
+ function X(t, e, r, s, a, m, p) {
16
16
  switch (t) {
17
17
  case "top":
18
- return e.top - a.top - i >= s;
18
+ return e.top - a.top - s >= i;
19
19
  case "bottom":
20
- return e.bottom + a.bottom + i <= u - s;
20
+ return e.bottom + a.bottom + s <= p - i;
21
21
  case "left":
22
- return e.left - a.left - r >= s;
22
+ return e.left - a.left - r >= i;
23
23
  case "right":
24
- return e.right + a.right + r <= f - s;
24
+ return e.right + a.right + r <= m - i;
25
25
  }
26
26
  }
27
27
  function ct(t) {
@@ -32,32 +32,32 @@ function ct(t) {
32
32
  right: "left"
33
33
  }[t]];
34
34
  }
35
- function ut(t, e, r, i) {
35
+ function ut(t, e, r, s) {
36
36
  if (!(r < 768))
37
37
  return ct(t);
38
- const u = e.top + e.height / 2 < i / 2;
39
- return t === "left" || t === "right" ? [u ? "bottom" : "top", u ? "top" : "bottom", t === "left" ? "right" : "left"] : t === "top" || t === "bottom" ? [t === "top" ? "bottom" : "top"] : [];
38
+ const p = e.top + e.height / 2 < s / 2;
39
+ return t === "left" || t === "right" ? [p ? "bottom" : "top", p ? "top" : "bottom", t === "left" ? "right" : "left"] : t === "top" || t === "bottom" ? [t === "top" ? "bottom" : "top"] : [];
40
40
  }
41
- function pt(t, e, r, i) {
41
+ function pt(t, e, r, s) {
42
42
  const a = {
43
- top: t.top - e.top - s,
44
- bottom: i - t.bottom - e.bottom - s,
45
- left: t.left - e.left - s,
46
- right: r - t.right - e.right - s
43
+ top: t.top - e.top - i,
44
+ bottom: s - t.bottom - e.bottom - i,
45
+ left: t.left - e.left - i,
46
+ right: r - t.right - e.right - i
47
47
  };
48
- let f = "bottom", u = a.bottom;
48
+ let m = "bottom", p = a.bottom;
49
49
  for (const [n, l] of Object.entries(a))
50
- l > u && (u = l, f = n);
51
- return f;
50
+ l > p && (p = l, m = n);
51
+ return m;
52
52
  }
53
53
  function ft({
54
54
  children: t,
55
55
  position: e = "top",
56
56
  align: r = "center",
57
- variant: i = "filled",
57
+ variant: s = "filled",
58
58
  color: a,
59
- showArrow: f = !1,
60
- keepOpen: u = !1,
59
+ showArrow: m = !1,
60
+ keepOpen: p = !1,
61
61
  offset: n
62
62
  }) {
63
63
  const l = n === void 0 ? { top: 7, bottom: 6, left: 6, right: 6 } : typeof n == "number" ? { top: n, bottom: n, left: n, right: n } : {
@@ -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
- }, 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),
68
+ }, k = ot().replace(/:/g, ""), w = y(null), x = y(null), b = y(), [c, h] = A(!1), [F, z] = A(e), [W, K] = A({}), N = y(null), j = C((R, E = 0) => {
69
+ b.current && (clearTimeout(b.current), b.current = void 0), !R && E > 0 ? b.current = window.setTimeout(
70
+ () => h(!1),
71
71
  E
72
- ) : L(k);
72
+ ) : h(R);
73
73
  }, []);
74
74
  nt(() => {
75
- if (!b || !w.current || !x.current) return;
76
- const k = () => {
75
+ if (!c || !w.current || !x.current) return;
76
+ const R = () => {
77
77
  if (!w.current || !x.current) return;
78
- const o = w.current.getBoundingClientRect(), y = x.current;
79
- y.classList.add("measuring"), y.offsetHeight;
80
- const Y = window.getComputedStyle(y), _ = parseFloat(Y.width), q = parseFloat(Y.height);
81
- let c = _, d = q;
82
- y.classList.remove("measuring");
83
- const R = window.innerWidth, O = window.innerHeight;
84
- (isNaN(c) || c <= 0) && (c = 100), (isNaN(d) || d <= 0) && (d = 50);
85
- const U = R - s * 2, j = O - s * 2;
86
- c > U && (c = U), d > j && (d = j);
87
- let v = e;
88
- if (o.width === 0 && o.height === 0 || X(e, o, c, d, l, R, O))
89
- v = e;
78
+ const o = w.current.getBoundingClientRect(), P = x.current;
79
+ P.classList.add("measuring"), P.offsetHeight;
80
+ const _ = P.getBoundingClientRect(), q = _.width, H = _.height;
81
+ let u = q, d = H;
82
+ P.classList.remove("measuring");
83
+ const T = window.innerWidth, O = window.innerHeight;
84
+ (isNaN(u) || u <= 0) && (u = 100), (isNaN(d) || d <= 0) && (d = 50);
85
+ const U = T - i * 2, $ = O - i * 2;
86
+ u > U && (u = U), d > $ && (d = $);
87
+ let M = e;
88
+ if (o.width === 0 && o.height === 0 || X(e, o, u, d, l, T, O))
89
+ M = e;
90
90
  else {
91
- const N = ut(e, o, R, O);
91
+ const I = ut(e, o, T, O);
92
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;
93
+ for (const G of I)
94
+ if (X(G, o, u, d, l, T, O)) {
95
+ M = G, D = !0;
96
96
  break;
97
97
  }
98
- D || (v = pt(o, l, R, O));
98
+ D || (M = pt(o, l, T, O));
99
99
  }
100
- let p = 0, g = 0;
101
- if (v === "top" || v === "bottom") {
100
+ let f = 0, g = 0;
101
+ if (M === "top" || M === "bottom") {
102
102
  switch (r) {
103
103
  case "start":
104
- p = o.left;
104
+ f = o.left;
105
105
  break;
106
106
  case "center":
107
- p = o.left + o.width / 2 - c / 2;
107
+ f = o.left + o.width / 2 - u / 2;
108
108
  break;
109
109
  case "end":
110
- p = o.right - c;
110
+ f = o.right - u;
111
111
  break;
112
112
  }
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));
113
+ f = Math.max(i, Math.min(f, T - i - u)), g = M === "top" ? o.top - l.top - d : o.bottom + l.bottom, g = Math.max(i, Math.min(g, O - i - d));
114
114
  } else {
115
115
  switch (r) {
116
116
  case "start":
@@ -123,188 +123,199 @@ 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" ? (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));
126
+ g = Math.max(i, Math.min(g, O - i - d)), M === "left" ? (f = o.left - l.left - u, f < i && (u = o.left - l.left - i, f = i)) : (f = o.right + l.right, f + u > T - i && (u = T - i - f));
127
127
  }
128
- let h = 0;
129
- const I = 12, C = 16;
130
- if (v === "left" || v === "right") {
128
+ let v = 0;
129
+ const S = 12, L = 16;
130
+ if (M === "left" || M === "right") {
131
131
  switch (r) {
132
132
  case "start":
133
- h = o.top - g + I;
133
+ v = o.top - g + S;
134
134
  break;
135
135
  case "center":
136
- h = o.top + o.height / 2 - g;
136
+ v = o.top + o.height / 2 - g;
137
137
  break;
138
138
  case "end":
139
- h = o.bottom - g - I;
139
+ v = o.bottom - g - S;
140
140
  break;
141
141
  }
142
- const N = Math.max(C, d - C);
143
- h = Math.max(
144
- C,
145
- Math.min(h, N)
142
+ const I = Math.max(L, d - L);
143
+ v = Math.max(
144
+ L,
145
+ Math.min(v, I)
146
146
  );
147
147
  } else {
148
148
  switch (r) {
149
149
  case "start":
150
- h = o.left - p + I;
150
+ v = o.left - f + S;
151
151
  break;
152
152
  case "center":
153
- h = o.left + o.width / 2 - p;
153
+ v = o.left + o.width / 2 - f;
154
154
  break;
155
155
  case "end":
156
- h = o.right - p - I;
156
+ v = o.right - f - S;
157
157
  break;
158
158
  }
159
- const N = Math.max(C, c - C);
160
- h = Math.max(
161
- C,
162
- Math.min(h, N)
159
+ const I = Math.max(L, u - L);
160
+ v = Math.max(
161
+ L,
162
+ Math.min(v, I)
163
163
  );
164
164
  }
165
- isNaN(h) && (h = C), z(v), K({
166
- left: Math.round(p),
165
+ isNaN(v) && (v = L), z(M), K({
166
+ left: Math.round(f),
167
167
  top: Math.round(g),
168
- ...c !== _ && { maxWidth: c },
169
- ...d !== q && { maxHeight: j },
170
- "--arrow-offset": `${Math.round(h)}px`,
168
+ ...u !== q && { maxWidth: u },
169
+ ...d !== H && { maxHeight: $ },
170
+ "--arrow-offset": `${Math.round(v)}px`,
171
171
  ...a && { "--motile-tooltip-color": a }
172
172
  });
173
173
  }, E = () => {
174
- F.current === null && (F.current = requestAnimationFrame(() => {
175
- k(), F.current = null;
174
+ N.current === null && (N.current = requestAnimationFrame(() => {
175
+ R(), N.current = null;
176
176
  }));
177
177
  };
178
- k(), window.addEventListener("scroll", E, {
178
+ R(), window.addEventListener("scroll", E, {
179
179
  passive: !0,
180
180
  capture: !0
181
181
  }), window.addEventListener("resize", E, { passive: !0 });
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();
182
+ const Y = new ResizeObserver(E);
183
+ return w.current && Y.observe(w.current), () => {
184
+ N.current !== null && (cancelAnimationFrame(N.current), N.current = null), window.removeEventListener("scroll", E, { capture: !0 }), window.removeEventListener("resize", E), Y.disconnect();
185
185
  };
186
- }, [b, e, r, a, n]), P(() => {
187
- if (!b) return;
188
- const k = () => {
189
- W(!1, 0);
186
+ }, [c, e, r, a, n]), B(() => {
187
+ if (!c) return;
188
+ const R = () => {
189
+ j(!1, 0);
190
190
  };
191
- return window.addEventListener("scroll", k, { capture: !0 }), () => {
192
- window.removeEventListener("scroll", k, { capture: !0 });
191
+ return window.addEventListener("scroll", R, { capture: !0 }), () => {
192
+ window.removeEventListener("scroll", R, { capture: !0 });
193
193
  };
194
- }, [b, W]), P(() => () => {
195
- m.current && clearTimeout(m.current);
194
+ }, [c, j]), B(() => () => {
195
+ b.current && clearTimeout(b.current);
196
196
  }, []);
197
197
  const Q = {
198
- open: b,
199
- setOpen: W,
198
+ open: c,
199
+ setOpen: j,
200
200
  position: e,
201
201
  align: r,
202
- variant: i,
203
- showArrow: f,
202
+ variant: s,
203
+ showArrow: m,
204
204
  color: a,
205
- keepOpen: u,
206
- tooltipId: `${M}-tooltip`,
205
+ keepOpen: p,
206
+ tooltipId: `${k}-tooltip`,
207
207
  triggerRef: w,
208
208
  contentRef: x,
209
- style: H,
210
- placement: B
209
+ style: W,
210
+ placement: F
211
211
  };
212
- return /* @__PURE__ */ $(Z.Provider, { value: Q, children: t });
212
+ return /* @__PURE__ */ V(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: f, keepOpen: u } = J(), n = T(() => {
216
- i(!0, 0);
217
- }, [i]), l = T(() => {
218
- u ? i(!1, 100) : i(!1, 0);
219
- }, [i, u]), M = T(() => {
220
- i(!0, 0);
221
- }, [i]), w = T(() => {
222
- i(!1, 0);
223
- }, [i]), x = T(() => {
224
- i(!r, 0);
225
- }, [i, r]);
226
- return e ? /* @__PURE__ */ $(
227
- at,
228
- {
229
- ref: (m) => {
230
- f.current = m;
231
- },
232
- className: "motile-tooltip-trigger",
233
- "aria-describedby": r ? a : void 0,
234
- tabIndex: 0,
235
- onMouseEnter: n,
236
- onMouseLeave: l,
237
- onFocus: M,
238
- onBlur: w,
239
- onClick: x,
240
- children: t
241
- }
242
- ) : et.cloneElement(t, {
243
- ref: (m) => {
244
- f.current = m;
245
- const b = t.props.ref || t.ref;
246
- b && (typeof b == "function" ? b(m) : typeof b == "object" && b !== null && (b.current = m));
215
+ const { open: r, setOpen: s, tooltipId: a, triggerRef: m, keepOpen: p } = J(), n = C(() => {
216
+ s(!0, 0);
217
+ }, [s]), l = C(() => {
218
+ p ? s(!1, 100) : s(!1, 0);
219
+ }, [s, p]), k = C(() => {
220
+ s(!0, 0);
221
+ }, [s]), w = C(() => {
222
+ s(!1, 0);
223
+ }, [s]), x = C(() => {
224
+ s(!r, 0);
225
+ }, [s, r]);
226
+ if (e)
227
+ return /* @__PURE__ */ V(
228
+ at,
229
+ {
230
+ ref: (c) => {
231
+ m.current = c;
232
+ },
233
+ className: "motile-tooltip-trigger",
234
+ "aria-describedby": r ? a : void 0,
235
+ tabIndex: 0,
236
+ onMouseEnter: n,
237
+ onMouseLeave: l,
238
+ onFocus: k,
239
+ onBlur: w,
240
+ onClick: x,
241
+ children: t
242
+ }
243
+ );
244
+ const b = (c, h) => (F) => {
245
+ c == null || c(F), h(F);
246
+ };
247
+ return et.cloneElement(t, {
248
+ ref: (c) => {
249
+ m.current = c;
250
+ const h = t.props.ref || t.ref;
251
+ h && (typeof h == "function" ? h(c) : typeof h == "object" && h !== null && (h.current = c));
247
252
  },
248
253
  className: `motile-tooltip-trigger ${t.props.className || ""}`.trim(),
249
254
  "aria-describedby": r ? a : void 0,
250
255
  tabIndex: t.props.tabIndex ?? 0,
251
- onMouseEnter: n,
252
- onMouseLeave: l,
253
- onFocus: M,
254
- onBlur: w,
255
- onClick: x
256
+ onMouseEnter: b(
257
+ t.props.onMouseEnter,
258
+ n
259
+ ),
260
+ onMouseLeave: b(
261
+ t.props.onMouseLeave,
262
+ l
263
+ ),
264
+ onFocus: b(t.props.onFocus, k),
265
+ onBlur: b(t.props.onBlur, w),
266
+ onClick: b(t.props.onClick, x)
256
267
  });
257
268
  }
258
269
  function bt({ children: t }) {
259
270
  const {
260
271
  open: e,
261
272
  setOpen: r,
262
- tooltipId: i,
273
+ tooltipId: s,
263
274
  contentRef: a,
264
- variant: f,
265
- showArrow: u,
275
+ variant: m,
276
+ showArrow: p,
266
277
  keepOpen: n,
267
278
  align: l,
268
- style: M,
279
+ style: k,
269
280
  placement: w
270
- } = J(), [x, m] = S(!1), [b, L] = S(!1);
271
- P(() => {
272
- m(!0);
273
- }, []), P(() => {
281
+ } = J(), [x, b] = A(!1), [c, h] = A(!1);
282
+ B(() => {
283
+ b(!0);
284
+ }, []), B(() => {
274
285
  e ? requestAnimationFrame(() => {
275
- L(!0);
276
- }) : L(!1);
286
+ h(!0);
287
+ }) : h(!1);
277
288
  }, [e]);
278
- const B = T(() => {
289
+ const F = C(() => {
279
290
  n && r(!0, 0);
280
- }, [n, r]), z = T(() => {
291
+ }, [n, r]), z = C(() => {
281
292
  n && r(!1, 0);
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(
293
+ }, [n, r]), W = k["--motile-tooltip-color"] || (m === "filled" ? "var(--motile-ui-tooltip, rgba(0, 0, 0, 0.9))" : "var(--motile-ui-tooltip, #3b82f6)");
294
+ return !x || !e ? null : it(
284
295
  /* @__PURE__ */ tt(
285
296
  "div",
286
297
  {
287
298
  ref: a,
288
- id: i,
299
+ id: s,
289
300
  role: "tooltip",
290
- className: `motile-tooltip-bubble motile-tooltip-bubble--${f}`,
291
- "data-open": b || void 0,
301
+ className: `motile-tooltip-bubble motile-tooltip-bubble--${m}`,
302
+ "data-open": c || void 0,
292
303
  "data-placement": w,
293
304
  "data-align": l,
294
- "data-show-arrow": u || void 0,
305
+ "data-show-arrow": p || void 0,
295
306
  "data-keep-open": n || void 0,
296
- style: M,
307
+ style: k,
297
308
  "aria-hidden": !e,
298
- onMouseEnter: B,
309
+ onMouseEnter: F,
299
310
  onMouseLeave: z,
300
311
  children: [
301
312
  t,
302
- u && /* @__PURE__ */ $(
313
+ p && /* @__PURE__ */ V(
303
314
  lt,
304
315
  {
305
316
  className: "motile-tooltip-arrow",
306
- variant: f,
307
- color: H
317
+ variant: m,
318
+ color: W
308
319
  }
309
320
  )
310
321
  ]
@@ -1,39 +1,43 @@
1
- import { useRef as r, useState as w, useEffect as l } from "react";
1
+ import { useRef as o, useState as w, useEffect as u } from "react";
2
2
  function p({
3
- onClose: o,
4
- isOpen: s
3
+ onClose: s,
4
+ isOpen: n
5
5
  }) {
6
- const i = r(o), n = r(!1), [a, c] = w(!1), u = r(0), e = r(null);
7
- return l(() => {
8
- i.current = o;
9
- }, [o]), l(() => {
10
- if (s && !n.current) {
11
- const t = (f) => {
12
- c(!0), i.current();
13
- };
14
- return u.current = window.history.length, window.history.pushState({ modal: !0 }, ""), n.current = !0, window.addEventListener("popstate", t), () => {
15
- window.removeEventListener("popstate", t);
16
- };
6
+ const i = o(s), r = o(!1), [a, c] = w(!1), l = o(0), t = o(null);
7
+ return u(() => {
8
+ i.current = s;
9
+ }, [s]), u(() => {
10
+ if (!n) return;
11
+ const e = (d) => {
12
+ c(!0), i.current();
13
+ };
14
+ return r.current || (l.current = window.history.length, window.history.pushState({ modal: !0 }, ""), r.current = !0), window.addEventListener("popstate", e), () => {
15
+ window.removeEventListener("popstate", e);
16
+ };
17
+ }, [n]), u(() => {
18
+ if (n || !r.current) return;
19
+ let e = null;
20
+ if (!a) {
21
+ const d = l.current + 1;
22
+ if (window.history.length !== d)
23
+ t.current = null;
24
+ else if (t.current) {
25
+ const f = t.current;
26
+ t.current = null, e = () => {
27
+ window.removeEventListener("popstate", e), e = null, setTimeout(() => {
28
+ f();
29
+ }, 0);
30
+ }, window.addEventListener("popstate", e), window.history.back();
31
+ } else
32
+ window.history.back();
17
33
  }
18
- if (!s && n.current) {
19
- if (!a) {
20
- const t = u.current + 1;
21
- if (window.history.length !== t)
22
- e.current = null;
23
- else if (e.current) {
24
- const d = () => {
25
- window.removeEventListener("popstate", d), e.current && (e.current(), e.current = null);
26
- };
27
- window.addEventListener("popstate", d), window.history.back();
28
- } else
29
- window.history.back();
30
- }
31
- n.current = !1, c(!1);
32
- }
33
- }, [s, a]), {
34
+ return r.current = !1, c(!1), () => {
35
+ e && window.removeEventListener("popstate", e);
36
+ };
37
+ }, [n, a]), {
34
38
  isClosingFromHistory: a,
35
- navigateAndClose: (t) => {
36
- e.current = t, i.current();
39
+ navigateAndClose: (e) => {
40
+ t.current = e, i.current();
37
41
  }
38
42
  };
39
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motile-ui",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "A modern React component library for webview applications",
6
6
  "main": "./dist/index.js",