@versaur/react 1.0.13 → 1.0.14

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,268 +0,0 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import { iconStyles as _, hrStyles as k, buttonIconStyles as F, tooltipStyles as A } from "@versaur/core/primitive";
3
- import B, { forwardRef as E, useRef as b, useEffect as y } from "react";
4
- import { u as w } from "./use-data-attrs-iPFyfiKN.js";
5
- import { c as T } from "./cx-B9vmfsc1.js";
6
- import { LoaderIcon as C } from "@versaur/icons";
7
- const L = B.forwardRef(function({ intent: t = "inherit", size: n = "inherit", as: o, className: c, ...a }, s) {
8
- const r = w({ intent: t, size: n });
9
- return /* @__PURE__ */ f(o, { ref: s, className: T(_.icon, c), ...r, ...a });
10
- });
11
- L.displayName = "Icon";
12
- const H = E(
13
- ({ orientation: e, variant: t, size: n, spacing: o, className: c, ...a }, s) => {
14
- const r = w({
15
- orientation: e,
16
- size: n,
17
- spacing: o,
18
- variant: t
19
- });
20
- return /* @__PURE__ */ f(
21
- "hr",
22
- {
23
- ref: s,
24
- className: T(k.hr, c),
25
- role: "separator",
26
- "aria-orientation": e === "vertical" ? "vertical" : void 0,
27
- ...r,
28
- ...a
29
- }
30
- );
31
- }
32
- );
33
- H.displayName = "Hr";
34
- const M = E(
35
- ({
36
- as: e,
37
- variant: t = "primary",
38
- size: n = "medium",
39
- loading: o = !1,
40
- disabled: c = !1,
41
- pressed: a = !1,
42
- type: s = "button",
43
- onClick: r,
44
- iconProps: i = {},
45
- "aria-label": l,
46
- className: u,
47
- ...p
48
- }, d) => {
49
- const h = w({
50
- disabled: c || o,
51
- loading: o,
52
- size: n,
53
- variant: t
54
- }), g = (v) => {
55
- if (c || o) {
56
- v.preventDefault();
57
- return;
58
- }
59
- r == null || r(v);
60
- };
61
- return /* @__PURE__ */ f(
62
- "button",
63
- {
64
- ref: d,
65
- type: s,
66
- className: T(F["button-icon"], u),
67
- "aria-label": l,
68
- "aria-pressed": a ? "true" : void 0,
69
- "aria-busy": o ? "true" : void 0,
70
- "aria-disabled": c || o ? "true" : void 0,
71
- ...h,
72
- ...p,
73
- onClick: g,
74
- children: o ? /* @__PURE__ */ f(L, { as: C, "aria-label": "Loading", "data-loading-icon": "loader" }) : /* @__PURE__ */ f(L, { as: e, ...i })
75
- }
76
- );
77
- }
78
- );
79
- M.displayName = "ButtonIcon";
80
- function $(...e) {
81
- return (t) => {
82
- e.forEach((n) => {
83
- if (typeof n == "function")
84
- n(t);
85
- else if (n && "current" in n)
86
- try {
87
- n.current = t;
88
- } catch {
89
- }
90
- });
91
- };
92
- }
93
- const j = 100, m = 16;
94
- function q(e, t) {
95
- let n = e.parentElement;
96
- for (; n; ) {
97
- const o = n.querySelector(`[data-tooltip-trigger="${t}"]`);
98
- if (o) return o;
99
- if (n === document.body) break;
100
- n = n.parentElement;
101
- }
102
- return null;
103
- }
104
- function D(e, t, n = j) {
105
- const o = window.innerWidth, c = window.innerHeight, a = {
106
- top: e.top,
107
- bottom: c - e.bottom,
108
- left: e.left,
109
- right: o - e.right
110
- };
111
- if (a.bottom >= n)
112
- return "bottom";
113
- if (t) {
114
- const s = e.left + e.width / 2, r = e.top + e.height / 2, i = [], l = e.bottom + t.height + m <= c && s - t.width / 2 >= m && s + t.width / 2 <= o - m;
115
- i.push(["bottom", a.bottom, l]);
116
- const u = e.top - t.height - m >= 0 && s - t.width / 2 >= m && s + t.width / 2 <= o - m;
117
- i.push(["top", a.top, u]);
118
- const p = e.right + t.width + m <= o && r - t.height / 2 >= m && r + t.height / 2 <= c - m;
119
- i.push(["right", a.right, p]);
120
- const d = e.left - t.width - m >= 0 && r - t.height / 2 >= m && r + t.height / 2 <= c - m;
121
- i.push(["left", a.left, d]);
122
- const h = i.filter(([g, v, x]) => x);
123
- if (h.length > 0)
124
- return h.reduce(
125
- (g, v) => v[1] > g[1] ? v : g
126
- )[0];
127
- }
128
- return Object.entries(a).reduce(
129
- (s, r) => r[1] > s[1] ? r : s
130
- )[0];
131
- }
132
- function O(e, t, n) {
133
- let o = null;
134
- const c = () => new Promise((i) => {
135
- requestAnimationFrame(() => {
136
- const l = e.getBoundingClientRect(), u = { width: l.width, height: l.height }, p = n || D(t.getBoundingClientRect(), u);
137
- i(p);
138
- });
139
- }), a = async () => {
140
- r();
141
- const i = await c();
142
- e.dataset.placement = i, e.matches(":popover-open") || e.showPopover();
143
- }, s = (i) => {
144
- o && (clearTimeout(o), o = null), i ? o = setTimeout(() => {
145
- e.matches(":popover-open") && e.hidePopover(), o = null;
146
- }, 100) : e.matches(":popover-open") && e.hidePopover();
147
- }, r = () => {
148
- o && (clearTimeout(o), o = null);
149
- };
150
- return { showTooltip: a, hideTooltip: s, cancelHide: r, cleanup: () => clearTimeout(o ?? void 0) };
151
- }
152
- function G({
153
- id: e,
154
- tooltipRef: t,
155
- placement: n,
156
- type: o
157
- }) {
158
- const c = b(null), a = b(null);
159
- y(() => {
160
- const s = t.current;
161
- if (!s || !e)
162
- return;
163
- const r = q(s, e);
164
- if (r)
165
- return a.current = r, c.current = O(s, r, n), () => {
166
- var i;
167
- (i = c.current) == null || i.cleanup(), c.current = null;
168
- };
169
- }, [e, n, t]), y(() => {
170
- if (o !== "hover" || !c.current || !a.current) return;
171
- const s = a.current, r = c.current, i = t.current;
172
- if (!i) return;
173
- const l = () => {
174
- r.showTooltip();
175
- }, u = () => {
176
- r.hideTooltip(!0);
177
- }, p = () => {
178
- r.cancelHide();
179
- }, d = () => {
180
- r.hideTooltip(!0);
181
- };
182
- return s.addEventListener("mouseenter", l), s.addEventListener("mouseleave", u), i.addEventListener("mouseenter", p), i.addEventListener("mouseleave", d), () => {
183
- s.removeEventListener("mouseenter", l), s.removeEventListener("mouseleave", u), i.removeEventListener("mouseenter", p), i.removeEventListener("mouseleave", d);
184
- };
185
- }, [o, t]), y(() => {
186
- if (o !== "persisted" || !c.current || !a.current) return;
187
- const s = a.current, r = c.current, i = t.current;
188
- if (!i) return;
189
- const l = (d) => {
190
- d.stopPropagation(), i.matches(":popover-open") ? r.hideTooltip(!1) : r.showTooltip();
191
- }, u = (d) => {
192
- const h = d.target;
193
- i.matches(":popover-open") && !s.contains(h) && !i.contains(h) && r.hideTooltip(!1);
194
- }, p = (d) => {
195
- d.key === "Escape" && i.matches(":popover-open") && r.hideTooltip(!1);
196
- };
197
- return s.addEventListener("click", l), document.addEventListener("click", u), document.addEventListener("keydown", p), () => {
198
- s.removeEventListener("click", l), document.removeEventListener("click", u), document.removeEventListener("keydown", p);
199
- };
200
- }, [o, t]);
201
- }
202
- const U = 8, I = E(
203
- ({ id: e, children: t, placement: n, gap: o = U, type: c = "hover", style: a, className: s, ...r }, i) => {
204
- const l = b(null), u = w({
205
- placement: n
206
- });
207
- return G({
208
- id: e,
209
- placement: n,
210
- tooltipRef: l,
211
- type: c
212
- }), /* @__PURE__ */ f(
213
- "div",
214
- {
215
- ref: $(l, i),
216
- id: e,
217
- className: T(A.tooltip, s),
218
- ...u,
219
- style: {
220
- "--_gap": `${o}px`,
221
- positionAnchor: `--tooltip-${e}`,
222
- ...a
223
- },
224
- ...r,
225
- popover: "auto",
226
- children: t
227
- }
228
- );
229
- }
230
- );
231
- I.displayName = "Tooltip";
232
- const N = E(
233
- ({ children: e, maxWidth: t, maxLines: n = 2, style: o, className: c, ...a }, s) => {
234
- const r = {
235
- "--_lines": n,
236
- "--_max-width": t,
237
- ...o
238
- };
239
- return /* @__PURE__ */ f("div", { ref: s, className: T(A["tooltip-text"], c), style: r, ...a, children: e });
240
- }
241
- );
242
- N.displayName = "Tooltip.Text";
243
- function W(e) {
244
- const { id: t, ...n } = e;
245
- return {
246
- "data-tooltip-trigger": t,
247
- style: { anchorName: `--tooltip-${t}` },
248
- ...Object.fromEntries(Object.entries(n).map(([o, c]) => [o, String(c)]))
249
- };
250
- }
251
- function X(e) {
252
- const { id: t } = e, n = document.getElementById(t);
253
- n && n.matches(":popover-open") && requestAnimationFrame(() => {
254
- const o = document.querySelector(`[data-tooltip-trigger="${t}"]`);
255
- o && document.activeElement === o && o.blur(), n.matches(":popover-open") && n.hidePopover();
256
- });
257
- }
258
- const P = I;
259
- P.Text = N;
260
- P.getTooltipTriggerProps = W;
261
- P.close = X;
262
- export {
263
- M as B,
264
- H,
265
- L as I,
266
- P as T,
267
- $ as c
268
- };
@@ -1,16 +0,0 @@
1
- function r(e) {
2
- return e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
3
- }
4
- function i(e) {
5
- const o = {};
6
- for (const [a, t] of Object.entries(e)) {
7
- if (t == null)
8
- continue;
9
- const n = r(a);
10
- typeof t == "boolean" ? t && (o[`data-${n}`] = (!!t).toString()) : (typeof t == "string" || typeof t == "number") && (o[`data-${n}`] = String(t));
11
- }
12
- return o;
13
- }
14
- export {
15
- i as u
16
- };