@versaur/react 1.0.15 → 1.0.17

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.
@@ -43,6 +43,7 @@ import { TextAs } from '@versaur/core/primitive';
43
43
  import { TextIntent } from '@versaur/core/primitive';
44
44
  import { TextSize } from '@versaur/core/primitive';
45
45
  import { TextWeight } from '@versaur/core/primitive';
46
+ import { Tooltip as Tooltip_2 } from '@versaur/core/primitive';
46
47
 
47
48
  export declare const Avatar: ForwardRefExoticComponent<AvatarProps & RefAttributes<HTMLSpanElement>> & {
48
49
  Image: ForwardRefExoticComponent<AvatarImageProps & RefAttributes<HTMLImageElement>>;
@@ -544,7 +545,7 @@ declare interface TooltipGetTriggerPropsOptions {
544
545
  [key: string]: any;
545
546
  }
546
547
 
547
- declare type TooltipPlacement = "top" | "bottom" | "left" | "right";
548
+ declare type TooltipPlacement = Tooltip_2.Placement;
548
549
 
549
550
  export declare interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
550
551
  /**
@@ -565,10 +566,11 @@ export declare interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
565
566
  gap?: number;
566
567
  /**
567
568
  * Tooltip interaction type:
568
- * - "hover" (default): Show on hover, hide on hover away (100ms grace period)
569
+ * - "hover" (default): Show on mouse hover, hide on hover away (100ms grace period)
569
570
  * - "persisted": Show on click, persists until user clicks outside or presses Escape
571
+ * - "focus": Show on focus (Tab key), hide on blur
570
572
  */
571
- type?: "hover" | "persisted";
573
+ type?: "hover" | "persisted" | "focus";
572
574
  }
573
575
 
574
576
  /**
package/dist/primitive.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as o, B as t, a as r, b as e, D as n, H as B, c as d, K as i, L as p, T as c, d as x } from "./tooltip-Cn7Ml9vw.js";
1
+ import { A as o, B as t, a as r, b as e, D as n, H as B, c as d, K as i, L as p, T as c, d as x } from "./tooltip-60d7mYVa.js";
2
2
  import { B as I, F as T, I as b } from "./helpers-D23F5WBX.js";
3
3
  export {
4
4
  o as Avatar,
@@ -0,0 +1,378 @@
1
+ import { jsxs as N, jsx as p } from "react/jsx-runtime";
2
+ import { buttonStyles as j, headingStyles as F, textStyles as M, avatarStyles as S, hrStyles as _, loaderStyles as $, badgeStyles as q, bannerStyles as E, dotStyles as O, kbdStyles as U, tooltipStyles as k } from "@versaur/core/primitive";
3
+ import { LoaderIcon as I, UserIcon as z, XIcon as G } from "@versaur/icons";
4
+ import { forwardRef as v, useState as X, useRef as A, useEffect as L } from "react";
5
+ import { u as T, I as w, B as J, f as Q, c as V } from "./helpers-D23F5WBX.js";
6
+ import { c as h } from "./cx-B9vmfsc1.js";
7
+ const W = v(
8
+ ({
9
+ variant: o = "primary",
10
+ size: n = "medium",
11
+ loading: e = !1,
12
+ disabled: t = !1,
13
+ pressed: s = !1,
14
+ leftIcon: c,
15
+ rightIcon: r,
16
+ children: a,
17
+ type: i = "button",
18
+ onClick: l,
19
+ className: d,
20
+ ...u
21
+ }, m) => {
22
+ const g = !!c, f = !!r, b = !!a;
23
+ let y;
24
+ g && f && b ? y = "both-text" : g && b ? y = "left-text" : f && b ? y = "right-text" : g && f ? y = "both" : g ? y = "left" : f && (y = "right");
25
+ const K = T({
26
+ disabled: t || e,
27
+ loading: e,
28
+ size: n,
29
+ variant: o,
30
+ ...y && { iconConfig: y }
31
+ }), C = (B) => {
32
+ if (t || e) {
33
+ B.preventDefault();
34
+ return;
35
+ }
36
+ l == null || l(B);
37
+ };
38
+ return /* @__PURE__ */ N(
39
+ "button",
40
+ {
41
+ ref: m,
42
+ type: i,
43
+ className: h(j.button, d),
44
+ "aria-pressed": s ? "true" : void 0,
45
+ "aria-busy": e ? "true" : void 0,
46
+ "aria-disabled": t || e ? "true" : void 0,
47
+ ...K,
48
+ ...u,
49
+ onClick: C,
50
+ children: [
51
+ e ? /* @__PURE__ */ p(w, { as: I, "aria-label": "Loading", "data-loading-icon": "loader" }) : null,
52
+ c,
53
+ a,
54
+ r
55
+ ]
56
+ }
57
+ );
58
+ }
59
+ );
60
+ W.displayName = "Button";
61
+ const Y = v(
62
+ ({ as: o = "h2", size: n, weight: e, intent: t = "default", case: s, transform: c, children: r, className: a, ...i }, l) => {
63
+ const d = o, u = T({
64
+ as: o,
65
+ case: s,
66
+ intent: t,
67
+ size: n,
68
+ transform: c,
69
+ weight: e
70
+ });
71
+ return /* @__PURE__ */ p(d, { ref: l, className: h(F.heading, a), ...u, ...i, children: r });
72
+ }
73
+ );
74
+ Y.displayName = "Heading";
75
+ const Z = v(
76
+ ({ as: o = "p", size: n, weight: e, intent: t = "default", case: s, transform: c, children: r, className: a, ...i }, l) => {
77
+ const d = o, u = T({
78
+ as: o,
79
+ case: s,
80
+ intent: t,
81
+ size: n,
82
+ transform: c,
83
+ weight: e
84
+ });
85
+ return /* @__PURE__ */ p(d, { ref: l, className: h(M.text, a), ...u, ...i, children: r });
86
+ }
87
+ );
88
+ Z.displayName = "Text";
89
+ const P = v(
90
+ ({ variant: o = "primary", size: n = "md", shape: e = "circle", children: t, className: s, ...c }, r) => {
91
+ const a = T({ shape: e, size: n, variant: o }), i = t || /* @__PURE__ */ p(w, { as: z });
92
+ return /* @__PURE__ */ p("span", { ref: r, className: h(S.avatar, s), role: "img", ...a, ...c, children: i });
93
+ }
94
+ );
95
+ P.displayName = "Avatar";
96
+ const D = v(({ src: o, alt: n, onError: e, className: t, ...s }, c) => {
97
+ const [r, a] = X(!1);
98
+ return r ? null : /* @__PURE__ */ p(
99
+ "img",
100
+ {
101
+ ref: c,
102
+ className: h(S["avatar-image"], t),
103
+ src: o,
104
+ alt: n,
105
+ onError: (i) => {
106
+ a(!0), e == null || e(i);
107
+ },
108
+ ...s
109
+ }
110
+ );
111
+ });
112
+ D.displayName = "Avatar.Image";
113
+ const Te = Object.assign(P, {
114
+ Image: D
115
+ }), ee = v(
116
+ ({ orientation: o, variant: n, size: e, spacing: t, className: s, ...c }, r) => {
117
+ const a = T({
118
+ orientation: o,
119
+ size: e,
120
+ spacing: t,
121
+ variant: n
122
+ });
123
+ return /* @__PURE__ */ p(
124
+ "hr",
125
+ {
126
+ ref: r,
127
+ className: h(_.hr, s),
128
+ role: "separator",
129
+ "aria-orientation": o === "vertical" ? "vertical" : void 0,
130
+ ...a,
131
+ ...c
132
+ }
133
+ );
134
+ }
135
+ );
136
+ ee.displayName = "Hr";
137
+ const te = v(
138
+ ({ type: o = "spinner", size: n = "sm", children: e, className: t, ...s }, c) => {
139
+ const r = T({
140
+ size: n,
141
+ type: o
142
+ });
143
+ return /* @__PURE__ */ N("div", { ref: c, className: h($.loader, t), ...r, ...s, children: [
144
+ o === "spinner" && /* @__PURE__ */ p(w, { as: I, "aria-hidden": "true" }),
145
+ e
146
+ ] });
147
+ }
148
+ );
149
+ te.displayName = "Loader";
150
+ const oe = v(
151
+ ({
152
+ variant: o = "primary",
153
+ size: n = "medium",
154
+ shape: e = "rounded",
155
+ iconLeft: t,
156
+ iconRight: s,
157
+ maxWidth: c,
158
+ children: r,
159
+ style: a,
160
+ className: i,
161
+ ...l
162
+ }, d) => {
163
+ const u = !!t, m = !!s, g = !!r;
164
+ let f;
165
+ u && m && g ? f = "both-text" : u && g ? f = "left-text" : m && g ? f = "right-text" : u && m ? f = "both" : u ? f = "left" : m && (f = "right");
166
+ const b = T({
167
+ shape: e,
168
+ size: n,
169
+ variant: o,
170
+ ...f && { iconConfig: f }
171
+ }), y = {
172
+ ...a,
173
+ ...c && { "--vers-comp-badge-max-width": c }
174
+ };
175
+ return /* @__PURE__ */ N("div", { ref: d, className: h(q.badge, i), ...b, ...l, style: y, children: [
176
+ t,
177
+ r,
178
+ s
179
+ ] });
180
+ }
181
+ );
182
+ oe.displayName = "Badge";
183
+ const ne = v(
184
+ ({ variant: o = "info", icon: n, onDismiss: e, children: t, className: s, ...c }, r) => {
185
+ const a = T({
186
+ variant: o
187
+ });
188
+ return /* @__PURE__ */ N("div", { ref: r, className: h(E.banner, s), ...a, ...c, children: [
189
+ n && /* @__PURE__ */ p("div", { className: E.icon, children: n }),
190
+ /* @__PURE__ */ p("div", { className: E.content, children: t }),
191
+ e && /* @__PURE__ */ p(J, { as: G, variant: "ghost", size: "small", onClick: e, "aria-label": "Dismiss banner" })
192
+ ] });
193
+ }
194
+ );
195
+ ne.displayName = "Banner";
196
+ const re = v(
197
+ ({ variant: o = "primary", size: n = "medium", className: e, ...t }, s) => {
198
+ const c = T({
199
+ size: n,
200
+ variant: o
201
+ });
202
+ return /* @__PURE__ */ p("span", { ref: s, className: h(O.dot, e), ...c, ...t });
203
+ }
204
+ );
205
+ re.displayName = "Dot";
206
+ const se = v(
207
+ ({ variant: o = "filled", size: n = "md", children: e, className: t, ...s }, c) => {
208
+ const r = T({ size: n, variant: o });
209
+ return /* @__PURE__ */ p("kbd", { ref: c, className: h(U.kbd, t), ...r, ...s, children: e });
210
+ }
211
+ );
212
+ se.displayName = "Kbd";
213
+ function ae(...o) {
214
+ return (n) => {
215
+ o.forEach((e) => {
216
+ if (typeof e == "function")
217
+ e(n);
218
+ else if (e && "current" in e)
219
+ try {
220
+ e.current = n;
221
+ } catch {
222
+ }
223
+ });
224
+ };
225
+ }
226
+ function ie(o, n, e) {
227
+ let t = null;
228
+ const s = () => new Promise((i) => {
229
+ o.matches(":popover-open") || o.showPopover(), requestAnimationFrame(() => {
230
+ const l = o.getBoundingClientRect(), d = { width: l.width, height: l.height }, u = e || V(n.getBoundingClientRect(), d);
231
+ i(u);
232
+ });
233
+ }), c = async () => {
234
+ a();
235
+ const i = await s();
236
+ o.dataset.placement = i;
237
+ }, r = (i) => {
238
+ t && (clearTimeout(t), t = null), i ? t = setTimeout(() => {
239
+ o.matches(":popover-open") && o.hidePopover(), t = null;
240
+ }, 100) : o.matches(":popover-open") && o.hidePopover();
241
+ }, a = () => {
242
+ t && (clearTimeout(t), t = null);
243
+ };
244
+ return { showTooltip: c, hideTooltip: r, cancelHide: a, cleanup: () => clearTimeout(t ?? void 0) };
245
+ }
246
+ function ce({ id: o, tooltipRef: n, placement: e, type: t }) {
247
+ const s = A(null), c = A(null);
248
+ L(() => {
249
+ const r = n.current;
250
+ if (!r || !o)
251
+ return;
252
+ const a = Q(r, o);
253
+ if (a)
254
+ return c.current = a, s.current = ie(r, a, e), () => {
255
+ var i;
256
+ (i = s.current) == null || i.cleanup(), s.current = null;
257
+ };
258
+ }, [o, e, n]), L(() => {
259
+ if (t !== "hover" || !s.current || !c.current) return;
260
+ const r = c.current, a = s.current, i = n.current;
261
+ if (!i) return;
262
+ const l = () => {
263
+ a.showTooltip();
264
+ }, d = () => {
265
+ a.hideTooltip(!0);
266
+ }, u = () => {
267
+ a.cancelHide();
268
+ }, m = () => {
269
+ a.hideTooltip(!0);
270
+ };
271
+ return r.addEventListener("mouseenter", l), r.addEventListener("mouseleave", d), i.addEventListener("mouseenter", u), i.addEventListener("mouseleave", m), () => {
272
+ r.removeEventListener("mouseenter", l), r.removeEventListener("mouseleave", d), i.removeEventListener("mouseenter", u), i.removeEventListener("mouseleave", m);
273
+ };
274
+ }, [t, n]), L(() => {
275
+ if (t !== "persisted" || !s.current || !c.current) return;
276
+ const r = c.current, a = s.current, i = n.current;
277
+ if (!i) return;
278
+ const l = (m) => {
279
+ m.stopPropagation(), i.matches(":popover-open") ? a.hideTooltip(!1) : a.showTooltip();
280
+ }, d = (m) => {
281
+ const g = m.target;
282
+ i.matches(":popover-open") && !r.contains(g) && !i.contains(g) && a.hideTooltip(!1);
283
+ }, u = (m) => {
284
+ m.key === "Escape" && i.matches(":popover-open") && a.hideTooltip(!1);
285
+ };
286
+ return r.addEventListener("click", l), document.addEventListener("click", d), document.addEventListener("keydown", u), () => {
287
+ r.removeEventListener("click", l), document.removeEventListener("click", d), document.removeEventListener("keydown", u);
288
+ };
289
+ }, [t, n]), L(() => {
290
+ if (t !== "focus" || !s.current || !c.current) return;
291
+ const r = c.current, a = s.current;
292
+ let i = !1;
293
+ const l = (m) => {
294
+ ["Tab", "Enter", " ", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(m.key) && (i = !0);
295
+ }, d = () => {
296
+ i && (a.showTooltip(), i = !1);
297
+ }, u = () => {
298
+ a.hideTooltip(!1), i = !1;
299
+ };
300
+ return document.addEventListener("keydown", l), r.addEventListener("focus", d), r.addEventListener("blur", u), () => {
301
+ document.removeEventListener("keydown", l), r.removeEventListener("focus", d), r.removeEventListener("blur", u);
302
+ };
303
+ }, [t, n]);
304
+ }
305
+ const le = 8, R = v(
306
+ ({ id: o, children: n, placement: e, gap: t = le, type: s = "hover", style: c, className: r, ...a }, i) => {
307
+ const l = A(null), d = T({
308
+ placement: e
309
+ });
310
+ return ce({
311
+ id: o,
312
+ placement: e,
313
+ tooltipRef: l,
314
+ type: s
315
+ }), /* @__PURE__ */ p(
316
+ "div",
317
+ {
318
+ ref: ae(l, i),
319
+ id: o,
320
+ className: h(k.tooltip, r),
321
+ ...d,
322
+ style: {
323
+ "--_gap": `${t}px`,
324
+ positionAnchor: `--tooltip-${o}`,
325
+ ...c
326
+ },
327
+ ...a,
328
+ popover: "auto",
329
+ children: n
330
+ }
331
+ );
332
+ }
333
+ );
334
+ R.displayName = "Tooltip";
335
+ const H = v(
336
+ ({ children: o, maxWidth: n, maxLines: e = 2, style: t, className: s, ...c }, r) => {
337
+ const a = {
338
+ "--_lines": e,
339
+ "--_max-width": n,
340
+ ...t
341
+ };
342
+ return /* @__PURE__ */ p("div", { ref: r, className: h(k["tooltip-text"], s), style: a, ...c, children: o });
343
+ }
344
+ );
345
+ H.displayName = "Tooltip.Text";
346
+ function ue(o) {
347
+ const { id: n, ...e } = o;
348
+ return {
349
+ "data-tooltip-trigger": n,
350
+ style: { anchorName: `--tooltip-${n}` },
351
+ ...Object.fromEntries(Object.entries(e).map(([t, s]) => [t, String(s)]))
352
+ };
353
+ }
354
+ function de(o) {
355
+ const { id: n } = o, e = document.getElementById(n);
356
+ e && e.matches(":popover-open") && requestAnimationFrame(() => {
357
+ const t = document.querySelector(`[data-tooltip-trigger="${n}"]`);
358
+ t && document.activeElement === t && t.blur(), e.matches(":popover-open") && e.hidePopover();
359
+ });
360
+ }
361
+ const x = R;
362
+ x.Text = H;
363
+ x.getTooltipTriggerProps = ue;
364
+ x.close = de;
365
+ export {
366
+ Te as A,
367
+ oe as B,
368
+ re as D,
369
+ Y as H,
370
+ se as K,
371
+ te as L,
372
+ Z as T,
373
+ ne as a,
374
+ W as b,
375
+ ee as c,
376
+ x as d,
377
+ ae as e
378
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versaur/react",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "React components for Versaur Design System",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,7 @@
49
49
  "peerDependencies": {
50
50
  "react": "^18.0.0 || ^19.0.0",
51
51
  "react-dom": "^18.0.0 || ^19.0.0",
52
- "@versaur/core": "0.0.11",
52
+ "@versaur/core": "0.0.13",
53
53
  "@versaur/icons": "1.0.0"
54
54
  },
55
55
  "scripts": {