@hamster-note/components 0.2.1-beta.3 → 0.3.0
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.
- package/README.md +313 -73
- package/dist/{icon-DNZLJUqH.js → Icon-BBSPOBTI.js} +25 -11
- package/dist/button-DjMS8bKj.js +20 -0
- package/dist/button.js +1 -1
- package/dist/components/button/Button.d.ts +3 -2
- package/dist/components/dialog/Dialog.d.ts +3 -1
- package/dist/components/drawer/Drawer.d.ts +3 -1
- package/dist/components/icon/icon-names.d.ts +3 -3
- package/dist/components/menu/Menu.d.ts +11 -19
- package/dist/components/menu/Menu.placement.test.d.ts +1 -0
- package/dist/components/menu/MenuSubmenu.d.ts +13 -0
- package/dist/components/menu/MenuSurface.d.ts +12 -0
- package/dist/components/menu/menu-tree-context.d.ts +9 -0
- package/dist/components/popover/use-anchor-position.d.ts +16 -1
- package/dist/components/popover/use-anchor-position.test.d.ts +1 -0
- package/dist/components/theme/theme-context.d.ts +10 -0
- package/dist/{confirm-3eBmopl8.js → confirm-Faavk_5T.js} +4 -5
- package/dist/confirm.js +1 -1
- package/dist/dialog-BYlEUJ_j.js +102 -0
- package/dist/dialog.js +1 -1
- package/dist/drawer-BV9RFSna.js +120 -0
- package/dist/drawer.js +1 -1
- package/dist/hamster-note-components.css +1 -1
- package/dist/icon-BFAcjkFI.js +5 -0
- package/dist/icon.js +2 -1
- package/dist/index.js +10 -9
- package/dist/menu-B4WwCQyw.js +179 -0
- package/dist/menu.js +1 -1
- package/dist/{popover-baLHE3lf.js → popover-D00SlGpL.js} +1 -1
- package/dist/popover.js +1 -1
- package/dist/test/fields-and-cards.test.d.ts +1 -0
- package/dist/test/imperative-apis.test.d.ts +1 -0
- package/dist/test/modals.test.d.ts +1 -0
- package/dist/test/primitives.test.d.ts +1 -0
- package/dist/test/setup.d.ts +0 -0
- package/dist/test/theme-and-popover.test.d.ts +1 -0
- package/dist/{theme-C0p_hpKk.js → theme-CVNLJL1G.js} +29 -21
- package/dist/theme-context-CdWvVVP8.js +8 -0
- package/dist/theme.js +1 -1
- package/dist/use-anchor-position-D3QBcIet.js +166 -0
- package/package.json +16 -3
- package/dist/button-DRz0VTkf.js +0 -18
- package/dist/dialog-B4xS5zlK.js +0 -53
- package/dist/drawer-DoeuGAHD.js +0 -60
- package/dist/menu-Dj-Dje_l.js +0 -153
- package/dist/use-anchor-position-DWle8yoL.js +0 -87
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { t as e } from "./use-anchor-position-D3QBcIet.js";
|
|
3
|
+
import { jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
4
|
+
import { createContext as r, useContext as i, useEffect as a, useRef as o, useState as s } from "react";
|
|
5
|
+
import { createPortal as c } from "react-dom";
|
|
6
|
+
//#region src/components/menu/MenuSurface.tsx
|
|
7
|
+
function l({ children: n, className: r, anchor: i = null, placement: a = "bottom-start", anchorOffset: o = 6, anchorCrossOffset: s = 0, viewportMargin: l = 8, ref: u, style: d, ...f }) {
|
|
8
|
+
let p = i !== null, { floatingRef: m, style: h } = e({
|
|
9
|
+
anchor: i,
|
|
10
|
+
placement: a,
|
|
11
|
+
offset: o,
|
|
12
|
+
crossOffset: s,
|
|
13
|
+
viewportMargin: l
|
|
14
|
+
}), g = [
|
|
15
|
+
"hn-menu",
|
|
16
|
+
p ? "hn-menu--floating" : void 0,
|
|
17
|
+
r
|
|
18
|
+
].filter(Boolean).join(" "), _ = p ? {
|
|
19
|
+
...h,
|
|
20
|
+
...d
|
|
21
|
+
} : d, v = (e) => {
|
|
22
|
+
m.current = e, typeof u == "function" ? u(e) : u != null && (u.current = e);
|
|
23
|
+
}, y = /* @__PURE__ */ t("div", {
|
|
24
|
+
...f,
|
|
25
|
+
className: g,
|
|
26
|
+
ref: v,
|
|
27
|
+
role: "menu",
|
|
28
|
+
style: _,
|
|
29
|
+
children: n
|
|
30
|
+
});
|
|
31
|
+
return p && typeof document < "u" ? c(y, document.body) : y;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/components/menu/menu-tree-context.ts
|
|
35
|
+
var u = {
|
|
36
|
+
submenuOffset: 2,
|
|
37
|
+
submenuPlacement: "right-start",
|
|
38
|
+
submenuViewportMargin: 8
|
|
39
|
+
}, d = r(u), f = 150, p = 200;
|
|
40
|
+
function m({ label: e, children: r, className: c, disabled: u = !1, offset: m, panelTheme: h, placement: g, viewportMargin: _, "aria-label": v, ...y }) {
|
|
41
|
+
let b = i(d), x = g ?? b.submenuPlacement, S = m ?? b.submenuOffset, C = _ ?? b.submenuViewportMargin, w = x.endsWith("-start") ? "start" : x.endsWith("-end") ? "end" : "center", T = w === "start" ? -6 : w === "end" ? 6 : 0, E = x.split("-")[0], D = E === "left" ? "◂" : E === "top" ? "▴" : E === "bottom" ? "▾" : "▸", [O, k] = s(!1), A = o(null), j = o(null), [M, N] = s(null), P = o(null), F = () => {
|
|
42
|
+
A.current !== null && (clearTimeout(A.current), A.current = null);
|
|
43
|
+
}, I = (e, t) => {
|
|
44
|
+
F(), A.current = setTimeout(() => {
|
|
45
|
+
k(e), A.current = null;
|
|
46
|
+
}, t);
|
|
47
|
+
};
|
|
48
|
+
a(() => () => {
|
|
49
|
+
A.current !== null && (clearTimeout(A.current), A.current = null);
|
|
50
|
+
}, []);
|
|
51
|
+
let L = () => {
|
|
52
|
+
u || I(!0, f);
|
|
53
|
+
}, R = () => {
|
|
54
|
+
I(!1, p);
|
|
55
|
+
}, z = () => {
|
|
56
|
+
u || (F(), k((e) => !e));
|
|
57
|
+
}, B = () => {
|
|
58
|
+
let e = P.current;
|
|
59
|
+
if (e === null) return;
|
|
60
|
+
let t = e.querySelector("[role=\"menuitem\"]:not([disabled]):not([aria-disabled=\"true\"])");
|
|
61
|
+
t === null ? e.focus() : t.focus();
|
|
62
|
+
}, V = (e) => {
|
|
63
|
+
if (!u) switch (e.key) {
|
|
64
|
+
case "ArrowRight":
|
|
65
|
+
case "Enter":
|
|
66
|
+
case " ":
|
|
67
|
+
e.preventDefault(), F(), k(!0), requestAnimationFrame(() => {
|
|
68
|
+
B();
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}, H = (e) => {
|
|
73
|
+
switch (e.key) {
|
|
74
|
+
case "ArrowLeft":
|
|
75
|
+
case "Escape":
|
|
76
|
+
e.preventDefault(), e.stopPropagation(), F(), k(!1), j.current?.focus();
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}, U = (e) => {
|
|
80
|
+
if (!(e.target instanceof Element)) return;
|
|
81
|
+
let t = e.target.closest("[role=\"menuitem\"]");
|
|
82
|
+
t === null || t.getAttribute("aria-haspopup") === "menu" || (F(), k(!1), j.current?.focus());
|
|
83
|
+
}, W = v ?? (typeof e == "string" ? e : void 0), G = [
|
|
84
|
+
"hn-menu__submenu",
|
|
85
|
+
O ? "hn-menu__submenu--open" : void 0,
|
|
86
|
+
c
|
|
87
|
+
].filter(Boolean).join(" "), K = (e) => {
|
|
88
|
+
j.current = e, N(e);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ n("div", {
|
|
91
|
+
...y,
|
|
92
|
+
className: G,
|
|
93
|
+
onPointerEnter: u ? void 0 : L,
|
|
94
|
+
onPointerLeave: u ? void 0 : R,
|
|
95
|
+
children: [/* @__PURE__ */ n("button", {
|
|
96
|
+
"aria-label": W,
|
|
97
|
+
"aria-expanded": O,
|
|
98
|
+
"aria-haspopup": "menu",
|
|
99
|
+
className: "hn-menu__item hn-menu__submenu-trigger",
|
|
100
|
+
disabled: u,
|
|
101
|
+
onClick: z,
|
|
102
|
+
onKeyDown: V,
|
|
103
|
+
ref: K,
|
|
104
|
+
role: "menuitem",
|
|
105
|
+
type: "button",
|
|
106
|
+
children: [/* @__PURE__ */ t("span", {
|
|
107
|
+
className: "hn-menu__item-label",
|
|
108
|
+
children: e
|
|
109
|
+
}), /* @__PURE__ */ t("span", {
|
|
110
|
+
"aria-hidden": "true",
|
|
111
|
+
className: "hn-menu__submenu-chevron",
|
|
112
|
+
children: D
|
|
113
|
+
})]
|
|
114
|
+
}), O ? /* @__PURE__ */ t(l, {
|
|
115
|
+
anchor: M,
|
|
116
|
+
anchorCrossOffset: T,
|
|
117
|
+
anchorOffset: S,
|
|
118
|
+
"aria-label": W,
|
|
119
|
+
className: "hn-menu__submenu-panel",
|
|
120
|
+
"data-theme": h,
|
|
121
|
+
onClick: U,
|
|
122
|
+
onKeyDown: H,
|
|
123
|
+
placement: x,
|
|
124
|
+
ref: P,
|
|
125
|
+
tabIndex: -1,
|
|
126
|
+
viewportMargin: C,
|
|
127
|
+
children: r
|
|
128
|
+
}) : null]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/components/menu/Menu.tsx
|
|
133
|
+
function h({ submenuOffset: e = u.submenuOffset, submenuPlacement: n = u.submenuPlacement, submenuViewportMargin: r = u.submenuViewportMargin, ...i }) {
|
|
134
|
+
return /* @__PURE__ */ t(d.Provider, {
|
|
135
|
+
value: {
|
|
136
|
+
submenuOffset: e,
|
|
137
|
+
submenuPlacement: n,
|
|
138
|
+
submenuViewportMargin: r
|
|
139
|
+
},
|
|
140
|
+
children: /* @__PURE__ */ t(l, { ...i })
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function g({ children: e, className: r, shortcut: i, tone: a = "default", type: o = "button", ...s }) {
|
|
144
|
+
let c = [
|
|
145
|
+
"hn-menu__item",
|
|
146
|
+
`hn-menu__item--${a}`,
|
|
147
|
+
r
|
|
148
|
+
].filter(Boolean).join(" ");
|
|
149
|
+
return /* @__PURE__ */ n("button", {
|
|
150
|
+
...s,
|
|
151
|
+
className: c,
|
|
152
|
+
role: "menuitem",
|
|
153
|
+
type: o,
|
|
154
|
+
children: [/* @__PURE__ */ t("span", {
|
|
155
|
+
className: "hn-menu__item-label",
|
|
156
|
+
children: e
|
|
157
|
+
}), i != null && i !== "" ? /* @__PURE__ */ t("span", {
|
|
158
|
+
className: "hn-menu__shortcut",
|
|
159
|
+
children: i
|
|
160
|
+
}) : null]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function _({ className: e, ...n }) {
|
|
164
|
+
let r = ["hn-menu__separator", e].filter(Boolean).join(" ");
|
|
165
|
+
return /* @__PURE__ */ t("hr", {
|
|
166
|
+
...n,
|
|
167
|
+
className: r
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function v({ children: e, className: n, ...r }) {
|
|
171
|
+
let i = ["hn-menu__label", n].filter(Boolean).join(" ");
|
|
172
|
+
return /* @__PURE__ */ t("div", {
|
|
173
|
+
...r,
|
|
174
|
+
className: i,
|
|
175
|
+
children: e
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { m as a, _ as i, g as n, v as r, h as t };
|
package/dist/menu.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, i as t, n, r, t as i } from "./menu-
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./menu-B4WwCQyw.js";
|
|
2
2
|
export { i as Menu, n as MenuItem, r as MenuLabel, t as MenuSeparator, e as MenuSubmenu };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* empty css */
|
|
2
|
-
import { t as e } from "./use-anchor-position-
|
|
2
|
+
import { t as e } from "./use-anchor-position-D3QBcIet.js";
|
|
3
3
|
import { jsx as t } from "react/jsx-runtime";
|
|
4
4
|
import { createContext as n, useContext as r } from "react";
|
|
5
5
|
import { createPortal as i } from "react-dom";
|
package/dist/popover.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as e, t } from "./popover-
|
|
1
|
+
import { n as e, t } from "./popover-D00SlGpL.js";
|
|
2
2
|
export { t as Popover, e as PopoverSeparator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* empty css */
|
|
2
|
-
import {
|
|
2
|
+
import { t as e } from "./theme-context-CdWvVVP8.js";
|
|
3
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
4
|
//#region src/components/theme/theme.ts
|
|
4
|
-
var
|
|
5
|
+
var n = {
|
|
5
6
|
violet: {
|
|
6
7
|
accent: "#7c83ff",
|
|
7
8
|
accentHover: "#9197ff",
|
|
@@ -28,20 +29,20 @@ var t = {
|
|
|
28
29
|
focusRingColor: "rgb(244 114 182 / 42%)"
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
|
-
function
|
|
32
|
-
return e in
|
|
32
|
+
function r(e) {
|
|
33
|
+
return e in n;
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
//#region src/components/theme/ThemeProvider.tsx
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
38
|
-
let
|
|
37
|
+
function i(e) {
|
|
38
|
+
if (r(e)) {
|
|
39
|
+
let t = n[e];
|
|
39
40
|
return {
|
|
40
41
|
dataAccent: e,
|
|
41
42
|
style: {
|
|
42
|
-
"--hn-color-accent":
|
|
43
|
-
"--hn-color-accent-hover":
|
|
44
|
-
"--hn-focus-ring": `0 0 0 3px ${
|
|
43
|
+
"--hn-color-accent": t.accent,
|
|
44
|
+
"--hn-color-accent-hover": t.accentHover,
|
|
45
|
+
"--hn-focus-ring": `0 0 0 3px ${t.focusRingColor}`
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
}
|
|
@@ -50,18 +51,25 @@ function r(e) {
|
|
|
50
51
|
style: { "--hn-color-accent": e }
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
-
let { dataAccent:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
function a({ accent: n = "violet", children: r, className: a, mode: o = "dark", style: s }) {
|
|
55
|
+
let { dataAccent: c, style: l } = i(n), u = ["hn-theme", a].filter(Boolean).join(" "), d = {
|
|
56
|
+
...l,
|
|
57
|
+
...s
|
|
58
|
+
};
|
|
59
|
+
return /* @__PURE__ */ t(e, {
|
|
60
|
+
value: {
|
|
61
|
+
accent: c,
|
|
62
|
+
mode: o,
|
|
63
|
+
style: d
|
|
62
64
|
},
|
|
63
|
-
children:
|
|
65
|
+
children: /* @__PURE__ */ t("div", {
|
|
66
|
+
className: u,
|
|
67
|
+
"data-accent": c,
|
|
68
|
+
"data-mode": o,
|
|
69
|
+
style: d,
|
|
70
|
+
children: r
|
|
71
|
+
})
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
//#endregion
|
|
67
|
-
export {
|
|
75
|
+
export { n, r, a as t };
|
package/dist/theme.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as e, r as t, t as n } from "./theme-
|
|
1
|
+
import { n as e, r as t, t as n } from "./theme-CVNLJL1G.js";
|
|
2
2
|
export { e as THEME_ACCENTS, n as ThemeProvider, t as isThemeAccentPreset };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useLayoutEffect as e, useRef as t, useState as n } from "react";
|
|
2
|
+
//#region src/components/popover/use-anchor-position.ts
|
|
3
|
+
var r = {
|
|
4
|
+
position: "fixed",
|
|
5
|
+
top: 0,
|
|
6
|
+
left: 0,
|
|
7
|
+
visibility: "hidden"
|
|
8
|
+
}, i = {
|
|
9
|
+
top: "bottom",
|
|
10
|
+
bottom: "top",
|
|
11
|
+
left: "right",
|
|
12
|
+
right: "left"
|
|
13
|
+
}, a = {
|
|
14
|
+
"top-start": {
|
|
15
|
+
side: "top",
|
|
16
|
+
align: "start"
|
|
17
|
+
},
|
|
18
|
+
top: {
|
|
19
|
+
side: "top",
|
|
20
|
+
align: "center"
|
|
21
|
+
},
|
|
22
|
+
"top-end": {
|
|
23
|
+
side: "top",
|
|
24
|
+
align: "end"
|
|
25
|
+
},
|
|
26
|
+
"bottom-start": {
|
|
27
|
+
side: "bottom",
|
|
28
|
+
align: "start"
|
|
29
|
+
},
|
|
30
|
+
bottom: {
|
|
31
|
+
side: "bottom",
|
|
32
|
+
align: "center"
|
|
33
|
+
},
|
|
34
|
+
"bottom-end": {
|
|
35
|
+
side: "bottom",
|
|
36
|
+
align: "end"
|
|
37
|
+
},
|
|
38
|
+
"left-start": {
|
|
39
|
+
side: "left",
|
|
40
|
+
align: "start"
|
|
41
|
+
},
|
|
42
|
+
left: {
|
|
43
|
+
side: "left",
|
|
44
|
+
align: "center"
|
|
45
|
+
},
|
|
46
|
+
"left-end": {
|
|
47
|
+
side: "left",
|
|
48
|
+
align: "end"
|
|
49
|
+
},
|
|
50
|
+
"right-start": {
|
|
51
|
+
side: "right",
|
|
52
|
+
align: "start"
|
|
53
|
+
},
|
|
54
|
+
right: {
|
|
55
|
+
side: "right",
|
|
56
|
+
align: "center"
|
|
57
|
+
},
|
|
58
|
+
"right-end": {
|
|
59
|
+
side: "right",
|
|
60
|
+
align: "end"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
function o({ anchorRect: e, crossOffset: t, floatingHeight: n, floatingWidth: r, offset: o, placement: s, viewportHeight: c, viewportMargin: l, viewportWidth: u }) {
|
|
64
|
+
let { side: d, align: f } = a[s], p = (t) => {
|
|
65
|
+
switch (t) {
|
|
66
|
+
case "bottom": return e.bottom + o + n > c - l;
|
|
67
|
+
case "top": return e.top - o - n < l;
|
|
68
|
+
case "right": return e.right + o + r > u - l;
|
|
69
|
+
case "left": return e.left - o - r < l;
|
|
70
|
+
}
|
|
71
|
+
}, m = d;
|
|
72
|
+
if (p(d)) {
|
|
73
|
+
let e = i[d];
|
|
74
|
+
p(e) || (m = e);
|
|
75
|
+
}
|
|
76
|
+
let h = 0, g = 0;
|
|
77
|
+
switch (m) {
|
|
78
|
+
case "bottom":
|
|
79
|
+
h = e.bottom + o;
|
|
80
|
+
break;
|
|
81
|
+
case "top":
|
|
82
|
+
h = e.top - o - n;
|
|
83
|
+
break;
|
|
84
|
+
case "right":
|
|
85
|
+
g = e.right + o;
|
|
86
|
+
break;
|
|
87
|
+
case "left":
|
|
88
|
+
g = e.left - o - r;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (m === "top" || m === "bottom") {
|
|
92
|
+
switch (f) {
|
|
93
|
+
case "start":
|
|
94
|
+
g = e.left;
|
|
95
|
+
break;
|
|
96
|
+
case "center":
|
|
97
|
+
g = e.left + (e.width - r) / 2;
|
|
98
|
+
break;
|
|
99
|
+
case "end":
|
|
100
|
+
g = e.right - r;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
g += t;
|
|
104
|
+
} else {
|
|
105
|
+
switch (f) {
|
|
106
|
+
case "start":
|
|
107
|
+
h = e.top;
|
|
108
|
+
break;
|
|
109
|
+
case "center":
|
|
110
|
+
h = e.top + (e.height - n) / 2;
|
|
111
|
+
break;
|
|
112
|
+
case "end":
|
|
113
|
+
h = e.bottom - n;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
h += t;
|
|
117
|
+
}
|
|
118
|
+
return g = Math.min(Math.max(g, l), Math.max(l, u - r - l)), h = Math.min(Math.max(h, l), Math.max(l, c - n - l)), {
|
|
119
|
+
left: g,
|
|
120
|
+
top: h
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function s({ anchor: i, placement: a = "bottom-start", offset: s = 6, crossOffset: c = 0, viewportMargin: l = 8 }) {
|
|
124
|
+
let u = t(null), [d, f] = n(r);
|
|
125
|
+
return e(() => {
|
|
126
|
+
if (i === null) return;
|
|
127
|
+
let e = () => {
|
|
128
|
+
let e = u.current;
|
|
129
|
+
if (e === null) return;
|
|
130
|
+
let { left: t, top: n } = o({
|
|
131
|
+
anchorRect: i.getBoundingClientRect(),
|
|
132
|
+
crossOffset: c,
|
|
133
|
+
floatingHeight: e.offsetHeight,
|
|
134
|
+
floatingWidth: e.offsetWidth,
|
|
135
|
+
offset: s,
|
|
136
|
+
placement: a,
|
|
137
|
+
viewportHeight: window.innerHeight,
|
|
138
|
+
viewportMargin: l,
|
|
139
|
+
viewportWidth: window.innerWidth
|
|
140
|
+
});
|
|
141
|
+
f({
|
|
142
|
+
position: "fixed",
|
|
143
|
+
left: t,
|
|
144
|
+
top: n
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
e(), window.addEventListener("resize", e), window.addEventListener("scroll", e, !0);
|
|
148
|
+
let t = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
|
|
149
|
+
e();
|
|
150
|
+
});
|
|
151
|
+
return t?.observe(i), u.current !== null && t?.observe(u.current), () => {
|
|
152
|
+
window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0), t?.disconnect();
|
|
153
|
+
};
|
|
154
|
+
}, [
|
|
155
|
+
i,
|
|
156
|
+
a,
|
|
157
|
+
s,
|
|
158
|
+
c,
|
|
159
|
+
l
|
|
160
|
+
]), {
|
|
161
|
+
floatingRef: u,
|
|
162
|
+
style: d
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { s as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hamster-note/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Reusable React components for HamsterNote products.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,11 +77,15 @@
|
|
|
77
77
|
"build": "yarn typecheck && vite build --config vite.lib.config.ts",
|
|
78
78
|
"build:demo": "yarn typecheck && vite build",
|
|
79
79
|
"preview": "vite preview --host 0.0.0.0 --port 9810 --strictPort",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"test:coverage": "vitest run --coverage",
|
|
82
|
+
"test:e2e": "playwright test",
|
|
83
|
+
"test:e2e:update": "playwright test --update-snapshots",
|
|
80
84
|
"typecheck": "tsc --noEmit",
|
|
81
85
|
"lint": "eslint . --max-warnings 0",
|
|
82
86
|
"format": "prettier --write .",
|
|
83
87
|
"format:check": "prettier --check .",
|
|
84
|
-
"check": "yarn typecheck && yarn lint && yarn format:check"
|
|
88
|
+
"check": "yarn typecheck && yarn lint && yarn format:check && yarn test"
|
|
85
89
|
},
|
|
86
90
|
"peerDependencies": {
|
|
87
91
|
"react": "^19.0.0",
|
|
@@ -89,20 +93,29 @@
|
|
|
89
93
|
},
|
|
90
94
|
"devDependencies": {
|
|
91
95
|
"@eslint/js": "10.0.1",
|
|
96
|
+
"@playwright/test": "1.61.0",
|
|
97
|
+
"@testing-library/dom": "10.4.1",
|
|
98
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
99
|
+
"@testing-library/react": "^16.3.2",
|
|
100
|
+
"@testing-library/user-event": "^14.6.1",
|
|
101
|
+
"@types/node": "^26.1.2",
|
|
92
102
|
"@types/react": "19.2.17",
|
|
93
103
|
"@types/react-dom": "19.2.3",
|
|
94
104
|
"@vitejs/plugin-react": "6.0.3",
|
|
105
|
+
"@vitest/coverage-v8": "4.1.6",
|
|
95
106
|
"eslint": "10.7.0",
|
|
96
107
|
"eslint-plugin-react-hooks": "7.1.1",
|
|
97
108
|
"eslint-plugin-react-refresh": "0.5.3",
|
|
98
109
|
"globals": "17.7.0",
|
|
110
|
+
"jsdom": "^30.0.0",
|
|
99
111
|
"prettier": "3.9.5",
|
|
100
112
|
"react": "19.2.7",
|
|
101
113
|
"react-dom": "19.2.7",
|
|
102
114
|
"typescript": "6.0.3",
|
|
103
115
|
"typescript-eslint": "8.64.0",
|
|
104
116
|
"vite": "8.1.5",
|
|
105
|
-
"vite-plugin-dts": "5.0.3"
|
|
117
|
+
"vite-plugin-dts": "5.0.3",
|
|
118
|
+
"vitest": "4.1.6"
|
|
106
119
|
},
|
|
107
120
|
"engines": {
|
|
108
121
|
"node": "^20.19.0 || >=22.12.0"
|
package/dist/button-DRz0VTkf.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* empty css */
|
|
2
|
-
import { jsx as e } from "react/jsx-runtime";
|
|
3
|
-
//#region src/components/button/Button.tsx
|
|
4
|
-
function t({ children: t, className: n, size: r = "medium", type: i = "button", variant: a = "secondary", ...o }) {
|
|
5
|
-
return /* @__PURE__ */ e("button", {
|
|
6
|
-
className: [
|
|
7
|
-
"hn-button",
|
|
8
|
-
`hn-button--${a}`,
|
|
9
|
-
`hn-button--${r}`,
|
|
10
|
-
n
|
|
11
|
-
].filter(Boolean).join(" "),
|
|
12
|
-
type: i,
|
|
13
|
-
...o,
|
|
14
|
-
children: t
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
export { t };
|
package/dist/dialog-B4xS5zlK.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/* empty css */
|
|
2
|
-
import { t as e } from "./use-modal-K9L8aPS0.js";
|
|
3
|
-
import { Fragment as t, jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
-
import { createPortal as i } from "react-dom";
|
|
5
|
-
//#region src/components/dialog/Dialog.tsx
|
|
6
|
-
function a({ children: a, className: o, title: s, description: c, open: l, onClose: u, closeOnEsc: d = !0, closeOnBackdrop: f = !0, ref: p, style: m, ...h }) {
|
|
7
|
-
let { dataState: g, mounted: _, backdropRef: v, panelRef: y, titleId: b, descriptionId: x, handlePanelKeyDown: S, handleBackdropPointerDown: C } = e({
|
|
8
|
-
open: l,
|
|
9
|
-
onClose: u,
|
|
10
|
-
closeOnEsc: d,
|
|
11
|
-
closeOnBackdrop: f
|
|
12
|
-
});
|
|
13
|
-
if (!_ || typeof document > "u") return null;
|
|
14
|
-
let w = ["hn-dialog__panel", o].filter(Boolean).join(" "), T = s === void 0 ? void 0 : b, E = c === void 0 ? void 0 : x, D = (e) => {
|
|
15
|
-
y.current = e, typeof p == "function" ? p(e) : p != null && (p.current = e);
|
|
16
|
-
};
|
|
17
|
-
return i(/* @__PURE__ */ r(t, { children: [/* @__PURE__ */ n("div", {
|
|
18
|
-
className: "hn-dialog__backdrop",
|
|
19
|
-
"data-state": g,
|
|
20
|
-
onPointerDown: C,
|
|
21
|
-
ref: v
|
|
22
|
-
}), /* @__PURE__ */ r("div", {
|
|
23
|
-
...h,
|
|
24
|
-
"aria-describedby": E,
|
|
25
|
-
"aria-labelledby": T,
|
|
26
|
-
"aria-modal": "true",
|
|
27
|
-
className: w,
|
|
28
|
-
"data-state": g,
|
|
29
|
-
onKeyDown: S,
|
|
30
|
-
ref: D,
|
|
31
|
-
role: "dialog",
|
|
32
|
-
style: m,
|
|
33
|
-
tabIndex: -1,
|
|
34
|
-
children: [
|
|
35
|
-
s === void 0 ? null : /* @__PURE__ */ n("h2", {
|
|
36
|
-
className: "hn-dialog__title",
|
|
37
|
-
id: b,
|
|
38
|
-
children: s
|
|
39
|
-
}),
|
|
40
|
-
c === void 0 ? null : /* @__PURE__ */ n("p", {
|
|
41
|
-
className: "hn-dialog__description",
|
|
42
|
-
id: x,
|
|
43
|
-
children: c
|
|
44
|
-
}),
|
|
45
|
-
/* @__PURE__ */ n("div", {
|
|
46
|
-
className: "hn-dialog__content",
|
|
47
|
-
children: a
|
|
48
|
-
})
|
|
49
|
-
]
|
|
50
|
-
})] }), document.body);
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { a as t };
|
package/dist/drawer-DoeuGAHD.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/* empty css */
|
|
2
|
-
import { t as e } from "./use-modal-K9L8aPS0.js";
|
|
3
|
-
import { Fragment as t, jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
-
import { createPortal as i } from "react-dom";
|
|
5
|
-
//#region src/components/drawer/Drawer.tsx
|
|
6
|
-
function a({ children: a, className: o, title: s, description: c, open: l, onClose: u, placement: d = "right", size: f, closeOnEsc: p = !0, closeOnBackdrop: m = !0, ref: h, style: g, ..._ }) {
|
|
7
|
-
let { dataState: v, mounted: y, backdropRef: b, panelRef: x, titleId: S, descriptionId: C, handlePanelKeyDown: w, handleBackdropPointerDown: T } = e({
|
|
8
|
-
open: l,
|
|
9
|
-
onClose: u,
|
|
10
|
-
closeOnEsc: p,
|
|
11
|
-
closeOnBackdrop: m
|
|
12
|
-
});
|
|
13
|
-
if (!y || typeof document > "u") return null;
|
|
14
|
-
let E = [
|
|
15
|
-
"hn-drawer__panel",
|
|
16
|
-
`hn-drawer__panel--${d}`,
|
|
17
|
-
o
|
|
18
|
-
].filter(Boolean).join(" "), D = {
|
|
19
|
-
...f === void 0 ? {} : { "--hn-drawer-size": `${String(f)}px` },
|
|
20
|
-
...g
|
|
21
|
-
}, O = s === void 0 ? void 0 : S, k = c === void 0 ? void 0 : C, A = (e) => {
|
|
22
|
-
x.current = e, typeof h == "function" ? h(e) : h != null && (h.current = e);
|
|
23
|
-
};
|
|
24
|
-
return i(/* @__PURE__ */ r(t, { children: [/* @__PURE__ */ n("div", {
|
|
25
|
-
className: "hn-drawer__backdrop",
|
|
26
|
-
"data-state": v,
|
|
27
|
-
onPointerDown: T,
|
|
28
|
-
ref: b
|
|
29
|
-
}), /* @__PURE__ */ r("div", {
|
|
30
|
-
..._,
|
|
31
|
-
"aria-describedby": k,
|
|
32
|
-
"aria-labelledby": O,
|
|
33
|
-
"aria-modal": "true",
|
|
34
|
-
className: E,
|
|
35
|
-
"data-state": v,
|
|
36
|
-
onKeyDown: w,
|
|
37
|
-
ref: A,
|
|
38
|
-
role: "dialog",
|
|
39
|
-
style: D,
|
|
40
|
-
tabIndex: -1,
|
|
41
|
-
children: [
|
|
42
|
-
s === void 0 ? null : /* @__PURE__ */ n("h2", {
|
|
43
|
-
className: "hn-drawer__title",
|
|
44
|
-
id: S,
|
|
45
|
-
children: s
|
|
46
|
-
}),
|
|
47
|
-
c === void 0 ? null : /* @__PURE__ */ n("p", {
|
|
48
|
-
className: "hn-drawer__description",
|
|
49
|
-
id: C,
|
|
50
|
-
children: c
|
|
51
|
-
}),
|
|
52
|
-
/* @__PURE__ */ n("div", {
|
|
53
|
-
className: "hn-drawer__content",
|
|
54
|
-
children: a
|
|
55
|
-
})
|
|
56
|
-
]
|
|
57
|
-
})] }), document.body);
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
export { a as t };
|