stargazer-ui 1.0.0 → 1.0.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.
@@ -0,0 +1,125 @@
1
+ import { jsxs as M, Fragment as U, jsx as N } from "react/jsx-runtime";
2
+ import { forwardRef as X, useRef as P, useState as w, useEffect as $, cloneElement as Y } from "react";
3
+ import { createPortal as Z } from "react-dom";
4
+ const q = (l, g, u, c, i = !1) => {
5
+ let f = document.body, o = l.current, a = g.current, e = getComputedStyle(o).position, n = o.getBoundingClientRect().top - (e != "fixed" ? f.getBoundingClientRect().top : 0), d = o.offsetHeight, h = o.getBoundingClientRect().left - (e != "fixed" ? f.getBoundingClientRect().left : 0), R = o.offsetWidth, m = a.clientHeight, y = a.clientWidth;
6
+ const p = (v, S, B) => a.getBoundingClientRect()[v] <= B ? S : r[v];
7
+ let x = 0, C = 0;
8
+ i || (C = c.clientHeight - 1, x = c.clientWidth - 1);
9
+ let r;
10
+ switch (u) {
11
+ case "top":
12
+ return r = { top: n - m - C, left: h + R / 2 - y / 2 }, r.right = p("right", 12, 0), r.left = p("left", 0, 0), r;
13
+ case "right":
14
+ return r = { top: n + d / 2 - m / 2, left: h + o.offsetWidth + x }, r;
15
+ case "bottom":
16
+ return r = { top: n + d + C, left: h + R / 2 - y / 2 }, r.right = p("right", 12, 0), r.left = p("left", 0, 0), r;
17
+ case "left":
18
+ return r = { top: n + d / 2 - m / 2, left: h - y - x }, r;
19
+ default:
20
+ return { top: n - m, left: h + R / 2 - y / 2 };
21
+ }
22
+ }, G = (l, g, u, c) => {
23
+ let i = g.current.getBoundingClientRect().top, f = window.innerHeight - g.current.getBoundingClientRect().bottom, o = g.current.getBoundingClientRect().left, a = window.innerWidth - g.current.getBoundingClientRect().right, e = u.current.clientWidth + c.current.clientWidth + 48, n = u.current.clientHeight + c.current.clientHeight + 48;
24
+ if (l.current === "top") {
25
+ if (i <= n)
26
+ return a <= e ? "left" : o <= e ? "right" : "top";
27
+ } else if (l.current === "bottom") {
28
+ if (f <= n)
29
+ return a <= e ? "left" : o <= e ? "right" : "bottom";
30
+ } else if (l.current === "left" || l.current === "right") {
31
+ if (i >= n)
32
+ return "top";
33
+ if (i < n / 2)
34
+ return "bottom";
35
+ if (f < n / 2)
36
+ return l.current === "left" ? "left" : "right";
37
+ }
38
+ return l.current;
39
+ }, et = X(({ children: l, overlay: g, show: u, onToggle: c, position: i = "auto", trigger: f = "click", defaultShow: o = !1 }, a) => {
40
+ const e = P(), n = P(), d = P(), [h, R] = w(""), [m, y] = w(""), [p, x] = w(o), C = P(p), r = (t) => {
41
+ C.current = t, x(t);
42
+ }, [v, S] = w(i === "auto" ? "top" : i), B = P(v), W = (t) => {
43
+ B.current = t, S(t);
44
+ }, [k, A] = w(!1), [L, O] = w(!1), [J, F] = w(!0), H = Array.isArray(f) ? f : [f], E = (t, s, b) => {
45
+ s.current && (y(q(t, s, B.current, b.current)), R(q(t, b, B.current, b.current, !0)));
46
+ }, I = () => {
47
+ if (C.current && i === "auto") {
48
+ let t = G(B, e, n, d);
49
+ W(t);
50
+ }
51
+ }, z = () => {
52
+ E(e, n, d), C.current;
53
+ }, K = (t) => {
54
+ if (L && J) {
55
+ F(!1);
56
+ return;
57
+ }
58
+ r(!p), c(!p);
59
+ }, Q = (t) => {
60
+ k || (A(!0), c(!0));
61
+ }, T = (t) => {
62
+ r(!0), O(!0), c(!0);
63
+ }, D = (t) => {
64
+ k ? A(!1) : L && (O(!1), F(!0)), r(!1), c(!1);
65
+ };
66
+ $(() => {
67
+ if (console.log(e.current.getBoundingClientRect()), n.current && u && (E(e, n, d), i === "auto")) {
68
+ let t = G(B, e, n, d);
69
+ W(t);
70
+ }
71
+ if (e.current) {
72
+ let t = document.body, s = getComputedStyle(e.current).position;
73
+ console.log(e.current.getBoundingClientRect()), y({
74
+ top: e.current.getBoundingClientRect().top - (s != "fixed" ? t.getBoundingClientRect().top : 0),
75
+ left: e.current.getBoundingClientRect().left - (s != "fixed" ? t.getBoundingClientRect().left : 0)
76
+ }), R({
77
+ top: e.current.getBoundingClientRect().top - (s != "fixed" ? t.getBoundingClientRect().top : 0),
78
+ left: e.current.getBoundingClientRect().left - (s != "fixed" ? t.getBoundingClientRect().left : 0)
79
+ });
80
+ }
81
+ r(u);
82
+ }, [u, n, e, v]), $(() => (window.addEventListener("scroll", I), window.addEventListener("resize", z), function() {
83
+ window.removeEventListener("scroll", I), window.removeEventListener("resize", z);
84
+ }), []);
85
+ const j = (t) => {
86
+ let s = getComputedStyle(t.current).position;
87
+ return s === "fixed" ? "fixed" : s === "sticky" ? "sticky" : "absolute";
88
+ };
89
+ return /* @__PURE__ */ M("div", { ref: a, style: { display: "static" }, children: [
90
+ Y(l, {
91
+ ref: e,
92
+ onClick: H.find((t) => t === "click") ? K : null,
93
+ onMouseOver: H.find((t) => t === "hover") ? Q : null,
94
+ onMouseLeave: H.find((t) => t === "hover") ? D : null,
95
+ onFocus: H.find((t) => t === "focus") ? T : null,
96
+ onBlur: H.find((t) => t === "focus") ? D : null
97
+ }),
98
+ u ? Z(
99
+ /* @__PURE__ */ M(U, { children: [
100
+ /* @__PURE__ */ N(
101
+ "div",
102
+ {
103
+ ref: n,
104
+ style: { maxWidth: "100%", maxHeight: "100%", position: j(e), top: m.top, left: m.left, zIndex: "1010" },
105
+ children: g
106
+ }
107
+ ),
108
+ /* @__PURE__ */ N(
109
+ "div",
110
+ {
111
+ id: "sg-overlay-arrow",
112
+ ref: d,
113
+ "aria-hidden": !0,
114
+ className: `sg-overlay-arrow${v ? " overlay-position-" + v : ""}`,
115
+ style: { position: j(e), top: h.top, left: h.left }
116
+ }
117
+ )
118
+ ] }),
119
+ document.body
120
+ ) : null
121
+ ] });
122
+ });
123
+ export {
124
+ et as default
125
+ };
@@ -0,0 +1,85 @@
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import { createPortal as $ } from "react-dom";
3
+ import A, { forwardRef as p, useState as L, useRef as T, useEffect as N } from "react";
4
+ const B = (e, o, s, r) => {
5
+ const t = r ? r.element : document.body;
6
+ N(() => {
7
+ if (t)
8
+ return t.addEventListener(e, o, s), function() {
9
+ t.removeEventListener(e, o, s);
10
+ };
11
+ }, [o, t]);
12
+ }, a = p(({ children: e, initialPosition: o, id: s, resize: r = !1, move: t = !1, ...i }, u) => {
13
+ const [n, C] = L({ offSetTop: 0, offSetLeft: 0, ...o });
14
+ console.log(n);
15
+ const b = r ? "true" : "false", M = t ? "true" : "false", l = T(u || null), [h, S] = L(!1), y = T(h);
16
+ N(() => {
17
+ y.current = h;
18
+ }, [h]);
19
+ const R = (f) => {
20
+ if (t && f.target.className.includes("sg-popout-title") || f.target.className.includes("sg-popout-header")) {
21
+ const { top: d, left: g } = l.current.getBoundingClientRect();
22
+ C((m) => ({
23
+ ...m,
24
+ offSetTop: f.clientY - d,
25
+ offSetLeft: f.clientX - g
26
+ })), l.current.style.setProperty("user-select", "none"), l.current.setPointerCapture("moveable-popup-" + s), S((m) => !0);
27
+ }
28
+ }, H = (f) => {
29
+ t && (l.current.style.removeProperty("user-select"), S((d) => !1));
30
+ }, P = (f) => {
31
+ if (t && y.current) {
32
+ const d = f.clientY - n.offSetTop < 0, g = window.innerHeight - (f.clientY - n.offSetTop + l.current.offsetHeight) < 0, m = f.clientX - n.offSetLeft < 0, x = window.innerWidth - (f.clientX - n.offSetLeft + l.current.offsetWidth) < 0;
33
+ let v = d ? 0 : f.clientY - n.offSetTop;
34
+ v = g ? window.innerHeight - l.current.offsetHeight : v;
35
+ let w = m ? 0 : f.clientX - n.offSetLeft;
36
+ w = x ? window.innerWidth - l.current.offsetWidth : w, C((E) => ({
37
+ ...E,
38
+ top: v,
39
+ left: w
40
+ }));
41
+ }
42
+ };
43
+ return B("pointerup", H, !0, { element: document.body }), $(
44
+ /* @__PURE__ */ c(
45
+ "dialog",
46
+ {
47
+ "data-resize": b,
48
+ "data-move": M,
49
+ ref: l,
50
+ id: s,
51
+ className: "moveable-popout",
52
+ style: { top: n.top, left: n.left, bottom: n.bottom, right: n.right },
53
+ onMouseDown: R,
54
+ onMouseMove: P,
55
+ children: e
56
+ }
57
+ ),
58
+ document.body
59
+ );
60
+ }), D = ({ as: e, className: o, children: s, ...r }, t) => {
61
+ let u = ["div", "span", "h1", "h2", "h3", "h4", "h5", "h6"].find((n) => n === e) ? e : "div";
62
+ return /* @__PURE__ */ c(u, { ref: t, className: `sg-popout-header ${o}`, ...r, children: s });
63
+ };
64
+ a.Header = p(D);
65
+ const W = ({ children: e, className: o, ...s }, r) => {
66
+ e = e.length ? e.filter((i) => i != null && i != "") : e;
67
+ let t = [];
68
+ return A.Children.forEach(e, (i) => {
69
+ t.push(i);
70
+ }), /* @__PURE__ */ c("div", { ref: r, className: `sg-popout-body ${o}`, ...s, children: t.map((i) => i) });
71
+ };
72
+ a.Body = p(W);
73
+ const X = ({ as: e, className: o, children: s, ...r }, t) => {
74
+ let u = ["h1", "h2", "h3", "h4", "h5", "h6"].find((n) => n === e) ? e : "h5";
75
+ return /* @__PURE__ */ c(u, { ref: t, className: `sg-popout-title ${o}`, ...r, children: s });
76
+ };
77
+ a.Title = p(X);
78
+ const Y = ({ children: e, className: o, ...s }, r) => /* @__PURE__ */ c("p", { ref: r, className: `sg-popout-text ${o}`, ...s, children: e });
79
+ a.Text = p(Y);
80
+ const O = ({ children: e, className: o, ...s }, r) => /* @__PURE__ */ c("div", { ref: r, className: `sg-popout-footer ${o}`, ...s, children: e });
81
+ a.Footer = p(O);
82
+ export {
83
+ a as default,
84
+ B as useEventListener
85
+ };
@@ -0,0 +1,69 @@
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import { createContext as x, forwardRef as v, useState as h, useMemo as T, useContext as m } from "react";
3
+ const C = x(null), w = ({ children: s, value: t }) => /* @__PURE__ */ u(C.Provider, { value: t, children: s }), p = v(({ children: s, className: t, controlId: e, activeClassName: n, defaultActive: l = 0, ...i }, b) => {
4
+ const [a, c] = h(l), o = n || "sg-active", r = T(() => ({
5
+ activeTab: a,
6
+ setActiveTab: c,
7
+ controlId: e,
8
+ activeClass: o
9
+ }), [a, c, e]);
10
+ return /* @__PURE__ */ u(w, { value: r, children: /* @__PURE__ */ u("div", { ref: b, id: e + "-tab-wrapper", className: `sg-tabs${t ? " " + t : ""}`, ...i, children: s }) });
11
+ }), y = ({ children: s, className: t, ...e }, n) => {
12
+ const { controlId: l, activeClass: i } = m(C);
13
+ return /* @__PURE__ */ u("div", { onKeyDown: (a) => {
14
+ const c = a.key, o = Array.from(document.getElementById(l + "-tab-controls").children);
15
+ if (c === "ArrowRight" || c === "ArrowLeft") {
16
+ a.preventDefault();
17
+ const r = document.querySelector(".sg-tabs-button." + i), d = o.indexOf(r), g = c === "ArrowRight" ? 1 : -1, f = d + g < 0 ? o.length - 1 : d + g >= o.length ? 0 : d + g;
18
+ o[f].focus(), o[f].click();
19
+ } else if (c === "Home" || c === "End") {
20
+ a.preventDefault();
21
+ const r = c === "Home" ? 0 : o.length - 1;
22
+ o[r].focus(), o[r].click();
23
+ }
24
+ }, role: "tablist", id: l + "-tab-controls", ref: n, className: `sg-tabs-controls${t ? " " + t : ""}`, ...e, children: s });
25
+ };
26
+ p.Controls = v(y);
27
+ const A = ({ children: s, className: t, onClick: e, tabId: n, id: l, ...i }, b) => {
28
+ const { activeTab: a, setActiveTab: c, activeClass: o } = m(C), r = "sg-tabs-button" + (t ? " " + t : "") + (a === n ? " " + o : ""), d = a === n, g = (f) => {
29
+ c(n), e && e(f);
30
+ };
31
+ return /* @__PURE__ */ u(
32
+ "button",
33
+ {
34
+ role: "tab",
35
+ type: "button",
36
+ id: n + "-button",
37
+ ref: b,
38
+ onClick: g,
39
+ className: r,
40
+ ...i,
41
+ tabIndex: d ? "0" : "-1",
42
+ "aria-selected": d ? "true" : "false",
43
+ "aria-controls": n + "-page",
44
+ children: s
45
+ }
46
+ );
47
+ };
48
+ p.Button = v(A);
49
+ const k = ({ children: s, className: t, ...e }, n) => (m(C), /* @__PURE__ */ u("div", { role: "none", ref: n, className: `sg-tabs-content${t ? " " + t : ""}`, ...e, children: s }));
50
+ p.Content = v(k);
51
+ const D = ({ children: s, className: t, tabId: e, ...n }, l) => {
52
+ const { activeTab: i, activeClass: b } = m(C), a = "sg-tabs-page" + (t ? " " + t : "") + (i === e ? " " + b : "");
53
+ return /* @__PURE__ */ u(
54
+ "div",
55
+ {
56
+ role: "tabpanel",
57
+ id: e + "-page",
58
+ "aria-labelledby": e + "-button",
59
+ ref: l,
60
+ className: a,
61
+ ...n,
62
+ children: s
63
+ }
64
+ );
65
+ };
66
+ p.Page = v(D);
67
+ export {
68
+ p as default
69
+ };
@@ -0,0 +1,11 @@
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { forwardRef as u, useState as g } from "react";
3
+ const p = u(({ children: t, toggled: r = "false", onClick: e, ...o }, d) => {
4
+ const [l, n] = g(r);
5
+ return /* @__PURE__ */ s("button", { onClick: (a) => {
6
+ n((f) => f === "true" ? "false" : "true"), e && e(a);
7
+ }, toggled: l, ...o, children: t });
8
+ });
9
+ export {
10
+ p as default
11
+ };
package/dist/main.js ADDED
@@ -0,0 +1,30 @@
1
+ import { default as t } from "./Button/index.js";
2
+ import { default as e } from "./Card/index.js";
3
+ import { default as u } from "./CloseButton/index.js";
4
+ import { default as p } from "./Dropdown/index.js";
5
+ import { default as s } from "./FloatingLabel/index.js";
6
+ import { default as x } from "./Form/index.js";
7
+ import { default as b } from "./InputGroup/index.js";
8
+ import { default as v } from "./Modal/index.js";
9
+ import { default as N } from "./Nav/index.js";
10
+ import { default as C } from "./NavBar/index.js";
11
+ import { default as F } from "./NavDropdown/index.js";
12
+ import { default as i } from "./Popout/index.js";
13
+ import { default as I } from "./Tabs/index.js";
14
+ import { default as M } from "./ToggleButton/index.js";
15
+ export {
16
+ t as Button,
17
+ e as Card,
18
+ u as CloseButton,
19
+ p as Dropdown,
20
+ s as FloatingLabel,
21
+ x as Form,
22
+ b as InputGroup,
23
+ v as Modal,
24
+ N as Nav,
25
+ F as NavDropdown,
26
+ C as Navbar,
27
+ i as Popout,
28
+ I as Tabs,
29
+ M as ToggleButton
30
+ };