@versaur/react 1.0.8 → 1.0.10

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.
@@ -532,10 +532,6 @@ declare interface TooltipGetTriggerPropsOptions {
532
532
  * Gap between tooltip and trigger in pixels
533
533
  */
534
534
  gap?: number;
535
- /**
536
- * Trigger type for determining popoverTarget behavior
537
- */
538
- triggerType?: "focus" | "hover" | "all";
539
535
  [key: string]: any;
540
536
  }
541
537
 
@@ -551,7 +547,7 @@ export declare interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
551
547
  */
552
548
  children: ReactNode;
553
549
  /**
554
- * Placement relative to the trigger
550
+ * Placement relative to the trigger. Defaults to "auto" which detects best placement based on viewport space.
555
551
  */
556
552
  placement?: TooltipPlacement;
557
553
  /**
package/dist/primitive.js CHANGED
@@ -4,8 +4,8 @@ import { LoaderIcon as T, UserIcon as U, XIcon as X } from "@versaur/icons";
4
4
  import { forwardRef as u, useState as q } from "react";
5
5
  import { u as b } from "./use-data-attrs-iPFyfiKN.js";
6
6
  import { c as p } from "./cx-B9vmfsc1.js";
7
- import { I as B, B as F } from "./tooltip-M8EGI3lZ.js";
8
- import { H as nt, T as lt } from "./tooltip-M8EGI3lZ.js";
7
+ import { I as B, B as F } from "./tooltip-Zuq8gd0f.js";
8
+ import { H as nt, T as lt } from "./tooltip-Zuq8gd0f.js";
9
9
  const G = u(
10
10
  ({
11
11
  variant: a = "primary",
@@ -0,0 +1,210 @@
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import { iconStyles as _, hrStyles as j, buttonIconStyles as H, tooltipStyles as x } from "@versaur/core/primitive";
3
+ import M, { forwardRef as b, useEffect as k, useRef as D } from "react";
4
+ import { u as T } from "./use-data-attrs-iPFyfiKN.js";
5
+ import { c as f } from "./cx-B9vmfsc1.js";
6
+ import { LoaderIcon as F } from "@versaur/icons";
7
+ const y = M.forwardRef(function({ intent: a = "inherit", size: n = "inherit", as: i, className: o, ...t }, e) {
8
+ const r = T({ intent: a, size: n });
9
+ return /* @__PURE__ */ u(i, { ref: e, className: f(_.icon, o), ...r, ...t });
10
+ });
11
+ y.displayName = "Icon";
12
+ const O = b(
13
+ ({ orientation: s, variant: a, size: n, spacing: i, className: o, ...t }, e) => {
14
+ const r = T({
15
+ orientation: s,
16
+ size: n,
17
+ spacing: i,
18
+ variant: a
19
+ });
20
+ return /* @__PURE__ */ u(
21
+ "hr",
22
+ {
23
+ ref: e,
24
+ className: f(j.hr, o),
25
+ role: "separator",
26
+ "aria-orientation": s === "vertical" ? "vertical" : void 0,
27
+ ...r,
28
+ ...t
29
+ }
30
+ );
31
+ }
32
+ );
33
+ O.displayName = "Hr";
34
+ const U = b(
35
+ ({
36
+ as: s,
37
+ variant: a = "primary",
38
+ size: n = "medium",
39
+ loading: i = !1,
40
+ disabled: o = !1,
41
+ pressed: t = !1,
42
+ type: e = "button",
43
+ onClick: r,
44
+ iconProps: p = {},
45
+ "aria-label": c,
46
+ className: m,
47
+ ...v
48
+ }, h) => {
49
+ const E = T({
50
+ disabled: o || i,
51
+ loading: i,
52
+ size: n,
53
+ variant: a
54
+ }), L = (d) => {
55
+ if (o || i) {
56
+ d.preventDefault();
57
+ return;
58
+ }
59
+ r == null || r(d);
60
+ };
61
+ return /* @__PURE__ */ u(
62
+ "button",
63
+ {
64
+ ref: h,
65
+ type: e,
66
+ className: f(H["button-icon"], m),
67
+ "aria-label": c,
68
+ "aria-pressed": t ? "true" : void 0,
69
+ "aria-busy": i ? "true" : void 0,
70
+ "aria-disabled": o || i ? "true" : void 0,
71
+ ...E,
72
+ ...v,
73
+ onClick: L,
74
+ children: i ? /* @__PURE__ */ u(y, { as: F, "aria-label": "Loading", "data-loading-icon": "loader" }) : /* @__PURE__ */ u(y, { as: s, ...p })
75
+ }
76
+ );
77
+ }
78
+ );
79
+ U.displayName = "ButtonIcon";
80
+ function C({ id: s, tooltipRef: a, placement: n, gap: i, triggerType: o }) {
81
+ k(() => {
82
+ const t = a.current;
83
+ if (!t || !s)
84
+ return;
85
+ let e = null;
86
+ if (t.parentElement && (e = t.parentElement.querySelector(`[data-tooltip-trigger="${s}"]`)), !e) {
87
+ let l = t.parentElement;
88
+ for (; l && !e && (e = l.querySelector(`[data-tooltip-trigger="${s}"]`), !(e || l.classList.contains("sbdocs-story") || l.classList.contains("docblock-storylet"))); )
89
+ l = l.parentElement;
90
+ }
91
+ if (e || (e = document.querySelector(`[data-tooltip-trigger="${s}"]`)), !e)
92
+ return;
93
+ let r = null;
94
+ const p = () => {
95
+ const l = e.getBoundingClientRect(), B = window.innerWidth, $ = window.innerHeight, q = 100, A = {
96
+ top: l.top,
97
+ bottom: $ - l.bottom,
98
+ left: l.left,
99
+ right: B - l.right
100
+ };
101
+ return A.bottom >= q ? "bottom" : Object.entries(A).reduce((I, N) => N[1] > I[1] ? N : I)[0];
102
+ }, c = () => {
103
+ r && (clearTimeout(r), r = null);
104
+ const l = n || p();
105
+ t.dataset.placement = l, t.matches(":popover-open") || t.showPopover();
106
+ }, m = () => {
107
+ r && clearTimeout(r), r = setTimeout(() => {
108
+ t.matches(":popover-open") && t.hidePopover(), r = null;
109
+ }, 100);
110
+ }, v = () => {
111
+ (o === "hover" || o === "all") && c();
112
+ }, h = () => {
113
+ (o === "hover" || o === "all") && m();
114
+ }, E = () => {
115
+ (o === "focus" || o === "all") && c();
116
+ }, L = () => {
117
+ o === "hover" && t.hidePopover();
118
+ }, d = () => {
119
+ o === "focus" && (t.matches(":popover-open") ? t.hidePopover() : c());
120
+ }, S = () => {
121
+ r && (clearTimeout(r), r = null);
122
+ }, w = () => {
123
+ (o === "hover" || o === "all") && m();
124
+ };
125
+ return e.addEventListener("mouseenter", v), e.addEventListener("mouseleave", h), e.addEventListener("focus", E), e.addEventListener("blur", L), e.addEventListener("click", d), t.addEventListener("mouseenter", S), t.addEventListener("mouseleave", w), () => {
126
+ r && clearTimeout(r), e.removeEventListener("mouseenter", v), e.removeEventListener("mouseleave", h), e.removeEventListener("focus", E), e.removeEventListener("blur", L), e.removeEventListener("click", d), t.removeEventListener("mouseenter", S), t.removeEventListener("mouseleave", w);
127
+ };
128
+ }, [s, i, o]);
129
+ }
130
+ function G(...s) {
131
+ return (a) => {
132
+ s.forEach((n) => {
133
+ if (typeof n == "function")
134
+ n(a);
135
+ else if (n && "current" in n)
136
+ try {
137
+ n.current = a;
138
+ } catch {
139
+ }
140
+ });
141
+ };
142
+ }
143
+ const W = 8, g = b(
144
+ ({ id: s, children: a, placement: n, gap: i = W, triggerType: o = "all", style: t, className: e, ...r }, p) => {
145
+ const c = D(null), m = T({
146
+ placement: n
147
+ });
148
+ return C({
149
+ gap: i,
150
+ id: s,
151
+ placement: n,
152
+ tooltipRef: c,
153
+ triggerType: o
154
+ }), /* @__PURE__ */ u(
155
+ "div",
156
+ {
157
+ ref: G(c, p),
158
+ id: s,
159
+ className: f(x.tooltip, e),
160
+ ...m,
161
+ style: {
162
+ "--_gap": `${i}px`,
163
+ positionAnchor: `--tooltip-${s}`,
164
+ ...t
165
+ },
166
+ ...r,
167
+ popover: "auto",
168
+ children: a
169
+ }
170
+ );
171
+ }
172
+ );
173
+ g.displayName = "Tooltip";
174
+ const R = b(
175
+ ({ children: s, maxWidth: a, maxLines: n = 2, style: i, className: o, ...t }, e) => {
176
+ const r = {
177
+ "--_lines": n,
178
+ "--_max-width": a,
179
+ ...i
180
+ };
181
+ return /* @__PURE__ */ u("div", { ref: e, className: f(x["tooltip-text"], o), style: r, ...t, children: s });
182
+ }
183
+ );
184
+ R.displayName = "Tooltip.Text";
185
+ function z(s) {
186
+ const { id: a, triggerType: n = "all", ...i } = s, o = {
187
+ "data-tooltip-trigger": a,
188
+ style: { anchorName: `--tooltip-${a}` },
189
+ ...Object.fromEntries(Object.entries(i).map(([t, e]) => [t, String(e)]))
190
+ };
191
+ return n !== "focus" && (o.popoverTarget = a), o;
192
+ }
193
+ function J(s) {
194
+ const { id: a } = s, n = document.getElementById(a);
195
+ n && n.matches(":popover-open") && requestAnimationFrame(() => {
196
+ const i = document.querySelector(`[data-tooltip-trigger="${a}"]`);
197
+ i && document.activeElement === i && i.blur(), n.matches(":popover-open") && n.hidePopover();
198
+ });
199
+ }
200
+ const P = g;
201
+ P.Text = R;
202
+ P.getTooltipTriggerProps = z;
203
+ P.close = J;
204
+ export {
205
+ U as B,
206
+ O as H,
207
+ y as I,
208
+ P as T,
209
+ G as c
210
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versaur/react",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "React components for Versaur Design System",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
+ "@storybook/react": "^8.6.17",
39
40
  "@types/react": "^18.3.28",
40
41
  "@types/react-dom": "^18.3.7",
41
42
  "@vitejs/plugin-react": "^4.7.0",
@@ -48,7 +49,7 @@
48
49
  "peerDependencies": {
49
50
  "react": "^18.0.0 || ^19.0.0",
50
51
  "react-dom": "^18.0.0 || ^19.0.0",
51
- "@versaur/core": "0.0.4",
52
+ "@versaur/core": "0.0.6",
52
53
  "@versaur/icons": "1.0.0"
53
54
  },
54
55
  "scripts": {
@@ -1,200 +0,0 @@
1
- import { jsx as u } from "react/jsx-runtime";
2
- import { iconStyles as P, hrStyles as R, buttonIconStyles as $, tooltipStyles as S } from "@versaur/core/primitive";
3
- import w, { forwardRef as T, useEffect as q, useRef as B } from "react";
4
- import { u as b } from "./use-data-attrs-iPFyfiKN.js";
5
- import { c as f } from "./cx-B9vmfsc1.js";
6
- import { LoaderIcon as M } from "@versaur/icons";
7
- const y = w.forwardRef(function({ intent: i = "inherit", size: r = "inherit", as: a, className: o, ...t }, e) {
8
- const n = b({ intent: i, size: r });
9
- return /* @__PURE__ */ u(a, { ref: e, className: f(P.icon, o), ...n, ...t });
10
- });
11
- y.displayName = "Icon";
12
- const _ = T(
13
- ({ orientation: s, variant: i, size: r, spacing: a, className: o, ...t }, e) => {
14
- const n = b({
15
- orientation: s,
16
- size: r,
17
- spacing: a,
18
- variant: i
19
- });
20
- return /* @__PURE__ */ u(
21
- "hr",
22
- {
23
- ref: e,
24
- className: f(R.hr, o),
25
- role: "separator",
26
- "aria-orientation": s === "vertical" ? "vertical" : void 0,
27
- ...n,
28
- ...t
29
- }
30
- );
31
- }
32
- );
33
- _.displayName = "Hr";
34
- const g = T(
35
- ({
36
- as: s,
37
- variant: i = "primary",
38
- size: r = "medium",
39
- loading: a = !1,
40
- disabled: o = !1,
41
- pressed: t = !1,
42
- type: e = "button",
43
- onClick: n,
44
- iconProps: l = {},
45
- "aria-label": c,
46
- className: m,
47
- ...v
48
- }, h) => {
49
- const E = b({
50
- disabled: o || a,
51
- loading: a,
52
- size: r,
53
- variant: i
54
- }), L = (d) => {
55
- if (o || a) {
56
- d.preventDefault();
57
- return;
58
- }
59
- n == null || n(d);
60
- };
61
- return /* @__PURE__ */ u(
62
- "button",
63
- {
64
- ref: h,
65
- type: e,
66
- className: f($["button-icon"], m),
67
- "aria-label": c,
68
- "aria-pressed": t ? "true" : void 0,
69
- "aria-busy": a ? "true" : void 0,
70
- "aria-disabled": o || a ? "true" : void 0,
71
- ...E,
72
- ...v,
73
- onClick: L,
74
- children: a ? /* @__PURE__ */ u(y, { as: M, "aria-label": "Loading", "data-loading-icon": "loader" }) : /* @__PURE__ */ u(y, { as: s, ...l })
75
- }
76
- );
77
- }
78
- );
79
- g.displayName = "ButtonIcon";
80
- function j({ id: s, tooltipRef: i, placement: r, gap: a, triggerType: o }) {
81
- q(() => {
82
- const t = i.current;
83
- if (!t || !s)
84
- return;
85
- let e = null;
86
- if (t.parentElement && (e = t.parentElement.querySelector(`[data-tooltip-trigger="${s}"]`)), !e) {
87
- let p = t.parentElement;
88
- for (; p && !e && (e = p.querySelector(`[data-tooltip-trigger="${s}"]`), !(e || p.classList.contains("sbdocs-story") || p.classList.contains("docblock-storylet"))); )
89
- p = p.parentElement;
90
- }
91
- if (e || (e = document.querySelector(`[data-tooltip-trigger="${s}"]`)), !e)
92
- return;
93
- let n = null;
94
- const l = () => {
95
- n && (clearTimeout(n), n = null), t.matches(":popover-open") || t.showPopover();
96
- }, c = () => {
97
- n && clearTimeout(n), n = setTimeout(() => {
98
- t.matches(":popover-open") && t.hidePopover(), n = null;
99
- }, 100);
100
- }, m = () => {
101
- (o === "hover" || o === "all") && l();
102
- }, v = () => {
103
- (o === "hover" || o === "all") && c();
104
- }, h = () => {
105
- (o === "focus" || o === "all") && l();
106
- }, E = () => {
107
- o === "hover" && t.hidePopover();
108
- }, L = () => {
109
- o === "focus" && (t.matches(":popover-open") ? t.hidePopover() : l());
110
- }, d = () => {
111
- n && (clearTimeout(n), n = null);
112
- }, I = () => {
113
- (o === "hover" || o === "all") && c();
114
- };
115
- return e.addEventListener("mouseenter", m), e.addEventListener("mouseleave", v), e.addEventListener("focus", h), e.addEventListener("blur", E), e.addEventListener("click", L), t.addEventListener("mouseenter", d), t.addEventListener("mouseleave", I), () => {
116
- n && clearTimeout(n), e.removeEventListener("mouseenter", m), e.removeEventListener("mouseleave", v), e.removeEventListener("focus", h), e.removeEventListener("blur", E), e.removeEventListener("click", L), t.removeEventListener("mouseenter", d), t.removeEventListener("mouseleave", I);
117
- };
118
- }, [s, r, a, o]);
119
- }
120
- function k(...s) {
121
- return (i) => {
122
- s.forEach((r) => {
123
- if (typeof r == "function")
124
- r(i);
125
- else if (r && "current" in r)
126
- try {
127
- r.current = i;
128
- } catch {
129
- }
130
- });
131
- };
132
- }
133
- const D = 8, x = T(
134
- ({ id: s, children: i, placement: r = "top", gap: a = D, triggerType: o = "all", style: t, className: e, ...n }, l) => {
135
- const c = B(null), m = b({
136
- placement: r
137
- });
138
- return j({
139
- gap: a,
140
- id: s,
141
- placement: r,
142
- tooltipRef: c,
143
- triggerType: o
144
- }), /* @__PURE__ */ u(
145
- "div",
146
- {
147
- ref: k(c, l),
148
- id: s,
149
- className: f(S.tooltip, e),
150
- ...m,
151
- style: {
152
- "--_gap": `${a}px`,
153
- positionAnchor: `--tooltip-${s}`,
154
- ...t
155
- },
156
- ...n,
157
- popover: "auto",
158
- children: i
159
- }
160
- );
161
- }
162
- );
163
- x.displayName = "Tooltip";
164
- const A = T(
165
- ({ children: s, maxWidth: i, maxLines: r = 2, style: a, className: o, ...t }, e) => {
166
- const n = {
167
- "--_lines": r,
168
- "--_max-width": i,
169
- ...a
170
- };
171
- return /* @__PURE__ */ u("div", { ref: e, className: f(S["tooltip-text"], o), style: n, ...t, children: s });
172
- }
173
- );
174
- A.displayName = "Tooltip.Text";
175
- function F(s) {
176
- const { id: i, triggerType: r = "all", ...a } = s, o = {
177
- "data-tooltip-trigger": i,
178
- style: { anchorName: `--tooltip-${i}` },
179
- ...Object.fromEntries(Object.entries(a).map(([t, e]) => [t, String(e)]))
180
- };
181
- return r !== "focus" && (o.popoverTarget = i), o;
182
- }
183
- function H(s) {
184
- const { id: i } = s, r = document.getElementById(i);
185
- r && r.matches(":popover-open") && requestAnimationFrame(() => {
186
- const a = document.querySelector(`[data-tooltip-trigger="${i}"]`);
187
- a && document.activeElement === a && a.blur(), r.matches(":popover-open") && r.hidePopover();
188
- });
189
- }
190
- const N = x;
191
- N.Text = A;
192
- N.getTooltipTriggerProps = F;
193
- N.close = H;
194
- export {
195
- g as B,
196
- _ as H,
197
- y as I,
198
- N as T,
199
- k as c
200
- };