@versaur/react 1.0.13 → 1.0.15

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.
@@ -0,0 +1,364 @@
1
+ import { jsxs as N, jsx as p } from "react/jsx-runtime";
2
+ import { buttonStyles as M, headingStyles as _, textStyles as $, avatarStyles as I, hrStyles as q, loaderStyles as F, badgeStyles as K, bannerStyles as A, dotStyles as O, kbdStyles as z, tooltipStyles as P } from "@versaur/core/primitive";
3
+ import { LoaderIcon as w, UserIcon as U, XIcon as G } from "@versaur/icons";
4
+ import { forwardRef as h, useState as X, useRef as x, useEffect as L } from "react";
5
+ import { u as T, I as E, B as J, f as Q, c as V } from "./helpers-D23F5WBX.js";
6
+ import { c as v } from "./cx-B9vmfsc1.js";
7
+ const W = h(
8
+ ({
9
+ variant: t = "primary",
10
+ size: n = "medium",
11
+ loading: e = !1,
12
+ disabled: o = !1,
13
+ pressed: s = !1,
14
+ leftIcon: i,
15
+ rightIcon: r,
16
+ children: a,
17
+ type: c = "button",
18
+ onClick: l,
19
+ className: u,
20
+ ...d
21
+ }, m) => {
22
+ const g = !!i, 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 C = T({
26
+ disabled: o || e,
27
+ loading: e,
28
+ size: n,
29
+ variant: t,
30
+ ...y && { iconConfig: y }
31
+ }), j = (S) => {
32
+ if (o || e) {
33
+ S.preventDefault();
34
+ return;
35
+ }
36
+ l == null || l(S);
37
+ };
38
+ return /* @__PURE__ */ N(
39
+ "button",
40
+ {
41
+ ref: m,
42
+ type: c,
43
+ className: v(M.button, u),
44
+ "aria-pressed": s ? "true" : void 0,
45
+ "aria-busy": e ? "true" : void 0,
46
+ "aria-disabled": o || e ? "true" : void 0,
47
+ ...C,
48
+ ...d,
49
+ onClick: j,
50
+ children: [
51
+ e ? /* @__PURE__ */ p(E, { as: w, "aria-label": "Loading", "data-loading-icon": "loader" }) : null,
52
+ i,
53
+ a,
54
+ r
55
+ ]
56
+ }
57
+ );
58
+ }
59
+ );
60
+ W.displayName = "Button";
61
+ const Y = h(
62
+ ({ as: t = "h2", size: n, weight: e, intent: o = "default", case: s, transform: i, children: r, className: a, ...c }, l) => {
63
+ const u = t, d = T({
64
+ as: t,
65
+ case: s,
66
+ intent: o,
67
+ size: n,
68
+ transform: i,
69
+ weight: e
70
+ });
71
+ return /* @__PURE__ */ p(u, { ref: l, className: v(_.heading, a), ...d, ...c, children: r });
72
+ }
73
+ );
74
+ Y.displayName = "Heading";
75
+ const Z = h(
76
+ ({ as: t = "p", size: n, weight: e, intent: o = "default", case: s, transform: i, children: r, className: a, ...c }, l) => {
77
+ const u = t, d = T({
78
+ as: t,
79
+ case: s,
80
+ intent: o,
81
+ size: n,
82
+ transform: i,
83
+ weight: e
84
+ });
85
+ return /* @__PURE__ */ p(u, { ref: l, className: v($.text, a), ...d, ...c, children: r });
86
+ }
87
+ );
88
+ Z.displayName = "Text";
89
+ const k = h(
90
+ ({ variant: t = "primary", size: n = "md", shape: e = "circle", children: o, className: s, ...i }, r) => {
91
+ const a = T({ shape: e, size: n, variant: t }), c = o || /* @__PURE__ */ p(E, { as: U });
92
+ return /* @__PURE__ */ p("span", { ref: r, className: v(I.avatar, s), role: "img", ...a, ...i, children: c });
93
+ }
94
+ );
95
+ k.displayName = "Avatar";
96
+ const R = h(({ src: t, alt: n, onError: e, className: o, ...s }, i) => {
97
+ const [r, a] = X(!1);
98
+ return r ? null : /* @__PURE__ */ p(
99
+ "img",
100
+ {
101
+ ref: i,
102
+ className: v(I["avatar-image"], o),
103
+ src: t,
104
+ alt: n,
105
+ onError: (c) => {
106
+ a(!0), e == null || e(c);
107
+ },
108
+ ...s
109
+ }
110
+ );
111
+ });
112
+ R.displayName = "Avatar.Image";
113
+ const Te = Object.assign(k, {
114
+ Image: R
115
+ }), ee = h(
116
+ ({ orientation: t, variant: n, size: e, spacing: o, className: s, ...i }, r) => {
117
+ const a = T({
118
+ orientation: t,
119
+ size: e,
120
+ spacing: o,
121
+ variant: n
122
+ });
123
+ return /* @__PURE__ */ p(
124
+ "hr",
125
+ {
126
+ ref: r,
127
+ className: v(q.hr, s),
128
+ role: "separator",
129
+ "aria-orientation": t === "vertical" ? "vertical" : void 0,
130
+ ...a,
131
+ ...i
132
+ }
133
+ );
134
+ }
135
+ );
136
+ ee.displayName = "Hr";
137
+ const te = h(
138
+ ({ type: t = "spinner", size: n = "sm", children: e, className: o, ...s }, i) => {
139
+ const r = T({
140
+ size: n,
141
+ type: t
142
+ });
143
+ return /* @__PURE__ */ N("div", { ref: i, className: v(F.loader, o), ...r, ...s, children: [
144
+ t === "spinner" && /* @__PURE__ */ p(E, { as: w, "aria-hidden": "true" }),
145
+ e
146
+ ] });
147
+ }
148
+ );
149
+ te.displayName = "Loader";
150
+ const oe = h(
151
+ ({
152
+ variant: t = "primary",
153
+ size: n = "medium",
154
+ shape: e = "rounded",
155
+ iconLeft: o,
156
+ iconRight: s,
157
+ maxWidth: i,
158
+ children: r,
159
+ style: a,
160
+ className: c,
161
+ ...l
162
+ }, u) => {
163
+ const d = !!o, m = !!s, g = !!r;
164
+ let f;
165
+ d && m && g ? f = "both-text" : d && g ? f = "left-text" : m && g ? f = "right-text" : d && m ? f = "both" : d ? f = "left" : m && (f = "right");
166
+ const b = T({
167
+ shape: e,
168
+ size: n,
169
+ variant: t,
170
+ ...f && { iconConfig: f }
171
+ }), y = {
172
+ ...a,
173
+ ...i && { "--vers-comp-badge-max-width": i }
174
+ };
175
+ return /* @__PURE__ */ N("div", { ref: u, className: v(K.badge, c), ...b, ...l, style: y, children: [
176
+ o,
177
+ r,
178
+ s
179
+ ] });
180
+ }
181
+ );
182
+ oe.displayName = "Badge";
183
+ const ne = h(
184
+ ({ variant: t = "info", icon: n, onDismiss: e, children: o, className: s, ...i }, r) => {
185
+ const a = T({
186
+ variant: t
187
+ });
188
+ return /* @__PURE__ */ N("div", { ref: r, className: v(A.banner, s), ...a, ...i, children: [
189
+ n && /* @__PURE__ */ p("div", { className: A.icon, children: n }),
190
+ /* @__PURE__ */ p("div", { className: A.content, children: o }),
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 = h(
197
+ ({ variant: t = "primary", size: n = "medium", className: e, ...o }, s) => {
198
+ const i = T({
199
+ size: n,
200
+ variant: t
201
+ });
202
+ return /* @__PURE__ */ p("span", { ref: s, className: v(O.dot, e), ...i, ...o });
203
+ }
204
+ );
205
+ re.displayName = "Dot";
206
+ const se = h(
207
+ ({ variant: t = "filled", size: n = "md", children: e, className: o, ...s }, i) => {
208
+ const r = T({ size: n, variant: t });
209
+ return /* @__PURE__ */ p("kbd", { ref: i, className: v(z.kbd, o), ...r, ...s, children: e });
210
+ }
211
+ );
212
+ se.displayName = "Kbd";
213
+ function ae(...t) {
214
+ return (n) => {
215
+ t.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(t, n, e) {
227
+ let o = null;
228
+ const s = () => new Promise((c) => {
229
+ t.matches(":popover-open") || t.showPopover(), requestAnimationFrame(() => {
230
+ const l = t.getBoundingClientRect(), u = { width: l.width, height: l.height }, d = e || V(n.getBoundingClientRect(), u);
231
+ c(d);
232
+ });
233
+ }), i = async () => {
234
+ a();
235
+ const c = await s();
236
+ t.dataset.placement = c;
237
+ }, r = (c) => {
238
+ o && (clearTimeout(o), o = null), c ? o = setTimeout(() => {
239
+ t.matches(":popover-open") && t.hidePopover(), o = null;
240
+ }, 100) : t.matches(":popover-open") && t.hidePopover();
241
+ }, a = () => {
242
+ o && (clearTimeout(o), o = null);
243
+ };
244
+ return { showTooltip: i, hideTooltip: r, cancelHide: a, cleanup: () => clearTimeout(o ?? void 0) };
245
+ }
246
+ function ce({ id: t, tooltipRef: n, placement: e, type: o }) {
247
+ const s = x(null), i = x(null);
248
+ L(() => {
249
+ const r = n.current;
250
+ if (!r || !t)
251
+ return;
252
+ const a = Q(r, t);
253
+ if (a)
254
+ return i.current = a, s.current = ie(r, a, e), () => {
255
+ var c;
256
+ (c = s.current) == null || c.cleanup(), s.current = null;
257
+ };
258
+ }, [t, e, n]), L(() => {
259
+ if (o !== "hover" || !s.current || !i.current) return;
260
+ const r = i.current, a = s.current, c = n.current;
261
+ if (!c) return;
262
+ const l = () => {
263
+ a.showTooltip();
264
+ }, u = () => {
265
+ a.hideTooltip(!0);
266
+ }, d = () => {
267
+ a.cancelHide();
268
+ }, m = () => {
269
+ a.hideTooltip(!0);
270
+ };
271
+ return r.addEventListener("mouseenter", l), r.addEventListener("mouseleave", u), c.addEventListener("mouseenter", d), c.addEventListener("mouseleave", m), () => {
272
+ r.removeEventListener("mouseenter", l), r.removeEventListener("mouseleave", u), c.removeEventListener("mouseenter", d), c.removeEventListener("mouseleave", m);
273
+ };
274
+ }, [o, n]), L(() => {
275
+ if (o !== "persisted" || !s.current || !i.current) return;
276
+ const r = i.current, a = s.current, c = n.current;
277
+ if (!c) return;
278
+ const l = (m) => {
279
+ m.stopPropagation(), c.matches(":popover-open") ? a.hideTooltip(!1) : a.showTooltip();
280
+ }, u = (m) => {
281
+ const g = m.target;
282
+ c.matches(":popover-open") && !r.contains(g) && !c.contains(g) && a.hideTooltip(!1);
283
+ }, d = (m) => {
284
+ m.key === "Escape" && c.matches(":popover-open") && a.hideTooltip(!1);
285
+ };
286
+ return r.addEventListener("click", l), document.addEventListener("click", u), document.addEventListener("keydown", d), () => {
287
+ r.removeEventListener("click", l), document.removeEventListener("click", u), document.removeEventListener("keydown", d);
288
+ };
289
+ }, [o, n]);
290
+ }
291
+ const le = 8, D = h(
292
+ ({ id: t, children: n, placement: e, gap: o = le, type: s = "hover", style: i, className: r, ...a }, c) => {
293
+ const l = x(null), u = T({
294
+ placement: e
295
+ });
296
+ return ce({
297
+ id: t,
298
+ placement: e,
299
+ tooltipRef: l,
300
+ type: s
301
+ }), /* @__PURE__ */ p(
302
+ "div",
303
+ {
304
+ ref: ae(l, c),
305
+ id: t,
306
+ className: v(P.tooltip, r),
307
+ ...u,
308
+ style: {
309
+ "--_gap": `${o}px`,
310
+ positionAnchor: `--tooltip-${t}`,
311
+ ...i
312
+ },
313
+ ...a,
314
+ popover: "auto",
315
+ children: n
316
+ }
317
+ );
318
+ }
319
+ );
320
+ D.displayName = "Tooltip";
321
+ const H = h(
322
+ ({ children: t, maxWidth: n, maxLines: e = 2, style: o, className: s, ...i }, r) => {
323
+ const a = {
324
+ "--_lines": e,
325
+ "--_max-width": n,
326
+ ...o
327
+ };
328
+ return /* @__PURE__ */ p("div", { ref: r, className: v(P["tooltip-text"], s), style: a, ...i, children: t });
329
+ }
330
+ );
331
+ H.displayName = "Tooltip.Text";
332
+ function de(t) {
333
+ const { id: n, ...e } = t;
334
+ return {
335
+ "data-tooltip-trigger": n,
336
+ style: { anchorName: `--tooltip-${n}` },
337
+ ...Object.fromEntries(Object.entries(e).map(([o, s]) => [o, String(s)]))
338
+ };
339
+ }
340
+ function ue(t) {
341
+ const { id: n } = t, e = document.getElementById(n);
342
+ e && e.matches(":popover-open") && requestAnimationFrame(() => {
343
+ const o = document.querySelector(`[data-tooltip-trigger="${n}"]`);
344
+ o && document.activeElement === o && o.blur(), e.matches(":popover-open") && e.hidePopover();
345
+ });
346
+ }
347
+ const B = D;
348
+ B.Text = H;
349
+ B.getTooltipTriggerProps = de;
350
+ B.close = ue;
351
+ export {
352
+ Te as A,
353
+ oe as B,
354
+ re as D,
355
+ Y as H,
356
+ se as K,
357
+ te as L,
358
+ Z as T,
359
+ ne as a,
360
+ W as b,
361
+ ee as c,
362
+ B as d,
363
+ ae as e
364
+ };
package/dist/utils.d.ts CHANGED
@@ -4,6 +4,58 @@ import { HTMLAttributes } from 'react';
4
4
  import { ReactNode } from 'react';
5
5
  import { RefAttributes } from 'react';
6
6
 
7
+ /**
8
+ * Component that renders its children only when viewport is at desktop breakpoint
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <DesktopBreakpoint>
13
+ * <DesktopSidebar />
14
+ * </DesktopBreakpoint>
15
+ * ```
16
+ */
17
+ export declare function DesktopBreakpoint({ children }: DesktopBreakpointProps): ReactNode;
18
+
19
+ export declare interface DesktopBreakpointProps {
20
+ /** Content to render when viewport is at desktop breakpoint (>= 1024px) */
21
+ children: ReactNode;
22
+ }
23
+
24
+ /**
25
+ * Component that renders its children only when viewport is at mobile breakpoint
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * <MobileBreakpoint>
30
+ * <MobileMenu />
31
+ * </MobileBreakpoint>
32
+ * ```
33
+ */
34
+ export declare function MobileBreakpoint({ children }: MobileBreakpointProps): ReactNode;
35
+
36
+ export declare interface MobileBreakpointProps {
37
+ /** Content to render when viewport is at mobile breakpoint (< 640px) */
38
+ children: ReactNode;
39
+ }
40
+
41
+ /**
42
+ * Component that renders its children only when viewport is mobile or tablet
43
+ * (exclusive: hides on desktop)
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * <MobileOrTabletBreakpoint>
48
+ * <CompactLayout />
49
+ * </MobileOrTabletBreakpoint>
50
+ * ```
51
+ */
52
+ export declare function MobileOrTabletBreakpoint({ children }: MobileOrTabletBreakpointProps): ReactNode;
53
+
54
+ export declare interface MobileOrTabletBreakpointProps {
55
+ /** Content to render when viewport is mobile or tablet (< 1024px) */
56
+ children: ReactNode;
57
+ }
58
+
7
59
  export declare const OverlayBody: ForwardRefExoticComponent<OverlayBodyProps & RefAttributes<HTMLDivElement>>;
8
60
 
9
61
  export declare interface OverlayBodyProps extends HTMLAttributes<HTMLDivElement> {
@@ -37,4 +89,39 @@ export declare interface OverlayTitleProps extends HTMLAttributes<HTMLHeadingEle
37
89
  as?: ElementType;
38
90
  }
39
91
 
92
+ /**
93
+ * Component that renders its children only when viewport is at tablet breakpoint
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * <TabletBreakpoint>
98
+ * <TabletLayout />
99
+ * </TabletBreakpoint>
100
+ * ```
101
+ */
102
+ export declare function TabletBreakpoint({ children }: TabletBreakpointProps): ReactNode;
103
+
104
+ export declare interface TabletBreakpointProps {
105
+ /** Content to render when viewport is at tablet breakpoint (< 1024px) */
106
+ children: ReactNode;
107
+ }
108
+
109
+ /**
110
+ * Component that renders its children only when viewport is tablet or desktop
111
+ * (exclusive: hides on mobile)
112
+ *
113
+ * @example
114
+ * ```tsx
115
+ * <TabletOrDesktopBreakpoint>
116
+ * <FullLayout />
117
+ * </TabletOrDesktopBreakpoint>
118
+ * ```
119
+ */
120
+ export declare function TabletOrDesktopBreakpoint({ children }: TabletOrDesktopBreakpointProps): ReactNode;
121
+
122
+ export declare interface TabletOrDesktopBreakpointProps {
123
+ /** Content to render when viewport is tablet or desktop (>= 640px) */
124
+ children: ReactNode;
125
+ }
126
+
40
127
  export { }
package/dist/utils.js CHANGED
@@ -1,7 +1,64 @@
1
- import { O as r, a as l, b as o, c as y } from "./overlay-parts-Zq9CuT31.js";
1
+ import { b as v, a as S, c as g, O as D } from "./overlay-parts-BtD-Qj_k.js";
2
+ import { useState as l, useEffect as c } from "react";
3
+ import { getBreakpointPx as n } from "@versaur/core/utils";
4
+ function r(e) {
5
+ const [t, a] = l(!1);
6
+ return c(() => {
7
+ const o = window.matchMedia(e);
8
+ a(o.matches);
9
+ const i = (s) => {
10
+ a(s.matches);
11
+ };
12
+ return o.addEventListener("change", i), () => {
13
+ o.removeEventListener("change", i);
14
+ };
15
+ }, [e]), t;
16
+ }
17
+ function p() {
18
+ const e = n("mobile");
19
+ return r(`(max-width: ${parseInt(e) - 1}px)`);
20
+ }
21
+ function u() {
22
+ const e = n("mobile"), t = n("tablet");
23
+ return r(
24
+ `(min-width: ${parseInt(e)}px) and (max-width: ${parseInt(t) - 1}px)`
25
+ );
26
+ }
27
+ function b() {
28
+ const e = n("tablet");
29
+ return r(`(min-width: ${parseInt(e)}px)`);
30
+ }
31
+ function m() {
32
+ const e = n("tablet");
33
+ return r(`(max-width: ${parseInt(e) - 1}px)`);
34
+ }
35
+ function k() {
36
+ const e = n("mobile");
37
+ return r(`(min-width: ${parseInt(e)}px)`);
38
+ }
39
+ function h({ children: e }) {
40
+ return p() ? e : null;
41
+ }
42
+ function d({ children: e }) {
43
+ return u() ? e : null;
44
+ }
45
+ function x({ children: e }) {
46
+ return b() ? e : null;
47
+ }
48
+ function M({ children: e }) {
49
+ return m() ? e : null;
50
+ }
51
+ function O({ children: e }) {
52
+ return k() ? e : null;
53
+ }
2
54
  export {
3
- r as OverlayBody,
4
- l as OverlayFooter,
5
- o as OverlayHeader,
6
- y as OverlayTitle
55
+ x as DesktopBreakpoint,
56
+ h as MobileBreakpoint,
57
+ M as MobileOrTabletBreakpoint,
58
+ v as OverlayBody,
59
+ S as OverlayFooter,
60
+ g as OverlayHeader,
61
+ D as OverlayTitle,
62
+ d as TabletBreakpoint,
63
+ O as TabletOrDesktopBreakpoint
7
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versaur/react",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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.9",
52
+ "@versaur/core": "0.0.11",
53
53
  "@versaur/icons": "1.0.0"
54
54
  },
55
55
  "scripts": {