@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.
Files changed (46) hide show
  1. package/README.md +313 -73
  2. package/dist/{icon-DNZLJUqH.js → Icon-BBSPOBTI.js} +25 -11
  3. package/dist/button-DjMS8bKj.js +20 -0
  4. package/dist/button.js +1 -1
  5. package/dist/components/button/Button.d.ts +3 -2
  6. package/dist/components/dialog/Dialog.d.ts +3 -1
  7. package/dist/components/drawer/Drawer.d.ts +3 -1
  8. package/dist/components/icon/icon-names.d.ts +3 -3
  9. package/dist/components/menu/Menu.d.ts +11 -19
  10. package/dist/components/menu/Menu.placement.test.d.ts +1 -0
  11. package/dist/components/menu/MenuSubmenu.d.ts +13 -0
  12. package/dist/components/menu/MenuSurface.d.ts +12 -0
  13. package/dist/components/menu/menu-tree-context.d.ts +9 -0
  14. package/dist/components/popover/use-anchor-position.d.ts +16 -1
  15. package/dist/components/popover/use-anchor-position.test.d.ts +1 -0
  16. package/dist/components/theme/theme-context.d.ts +10 -0
  17. package/dist/{confirm-3eBmopl8.js → confirm-Faavk_5T.js} +4 -5
  18. package/dist/confirm.js +1 -1
  19. package/dist/dialog-BYlEUJ_j.js +102 -0
  20. package/dist/dialog.js +1 -1
  21. package/dist/drawer-BV9RFSna.js +120 -0
  22. package/dist/drawer.js +1 -1
  23. package/dist/hamster-note-components.css +1 -1
  24. package/dist/icon-BFAcjkFI.js +5 -0
  25. package/dist/icon.js +2 -1
  26. package/dist/index.js +10 -9
  27. package/dist/menu-B4WwCQyw.js +179 -0
  28. package/dist/menu.js +1 -1
  29. package/dist/{popover-baLHE3lf.js → popover-D00SlGpL.js} +1 -1
  30. package/dist/popover.js +1 -1
  31. package/dist/test/fields-and-cards.test.d.ts +1 -0
  32. package/dist/test/imperative-apis.test.d.ts +1 -0
  33. package/dist/test/modals.test.d.ts +1 -0
  34. package/dist/test/primitives.test.d.ts +1 -0
  35. package/dist/test/setup.d.ts +0 -0
  36. package/dist/test/theme-and-popover.test.d.ts +1 -0
  37. package/dist/{theme-C0p_hpKk.js → theme-CVNLJL1G.js} +29 -21
  38. package/dist/theme-context-CdWvVVP8.js +8 -0
  39. package/dist/theme.js +1 -1
  40. package/dist/use-anchor-position-D3QBcIet.js +166 -0
  41. package/package.json +16 -3
  42. package/dist/button-DRz0VTkf.js +0 -18
  43. package/dist/dialog-B4xS5zlK.js +0 -53
  44. package/dist/drawer-DoeuGAHD.js +0 -60
  45. package/dist/menu-Dj-Dje_l.js +0 -153
  46. package/dist/use-anchor-position-DWle8yoL.js +0 -87
@@ -1,153 +0,0 @@
1
- /* empty css */
2
- import { t as e } from "./use-anchor-position-DWle8yoL.js";
3
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
4
- import { useEffect as r, useRef as i, useState as a } from "react";
5
- import { createPortal as o } from "react-dom";
6
- //#region src/components/menu/Menu.tsx
7
- function s({ children: n, className: r, anchor: i = null, placement: a = "bottom-start", anchorOffset: s = 6, anchorCrossOffset: c = 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: s,
12
- crossOffset: c,
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" ? o(y, document.body) : y;
32
- }
33
- function c({ children: e, className: r, shortcut: i, tone: a = "default", type: o = "button", ...s }) {
34
- let c = [
35
- "hn-menu__item",
36
- `hn-menu__item--${a}`,
37
- r
38
- ].filter(Boolean).join(" ");
39
- return /* @__PURE__ */ n("button", {
40
- ...s,
41
- className: c,
42
- role: "menuitem",
43
- type: o,
44
- children: [/* @__PURE__ */ t("span", {
45
- className: "hn-menu__item-label",
46
- children: e
47
- }), i != null && i !== "" ? /* @__PURE__ */ t("span", {
48
- className: "hn-menu__shortcut",
49
- children: i
50
- }) : null]
51
- });
52
- }
53
- function l({ className: e, ...n }) {
54
- let r = ["hn-menu__separator", e].filter(Boolean).join(" ");
55
- return /* @__PURE__ */ t("hr", {
56
- ...n,
57
- className: r
58
- });
59
- }
60
- function u({ children: e, className: n, ...r }) {
61
- let i = ["hn-menu__label", n].filter(Boolean).join(" ");
62
- return /* @__PURE__ */ t("div", {
63
- ...r,
64
- className: i,
65
- children: e
66
- });
67
- }
68
- var d = 150, f = 200;
69
- function p({ label: e, children: o, className: c, disabled: l = !1, "aria-label": u, ...p }) {
70
- let [m, h] = a(!1), g = i(null), _ = i(null), [v, y] = a(null), b = i(null), x = () => {
71
- g.current !== null && (clearTimeout(g.current), g.current = null);
72
- }, S = (e, t) => {
73
- x(), g.current = setTimeout(() => {
74
- h(e), g.current = null;
75
- }, t);
76
- };
77
- r(() => () => {
78
- g.current !== null && (clearTimeout(g.current), g.current = null);
79
- }, []);
80
- let C = () => {
81
- l || S(!0, d);
82
- }, w = () => {
83
- S(!1, f);
84
- }, T = () => {
85
- l || (x(), h((e) => !e));
86
- }, E = () => {
87
- let e = b.current;
88
- if (e === null) return;
89
- let t = e.querySelector("[role=\"menuitem\"]");
90
- t === null ? e.focus() : t.focus();
91
- }, D = (e) => {
92
- if (!l) switch (e.key) {
93
- case "ArrowRight":
94
- case "Enter":
95
- case " ":
96
- e.preventDefault(), x(), h(!0), requestAnimationFrame(() => {
97
- E();
98
- });
99
- break;
100
- }
101
- }, O = (e) => {
102
- switch (e.key) {
103
- case "ArrowLeft":
104
- case "Escape":
105
- e.preventDefault(), x(), h(!1), _.current?.focus();
106
- break;
107
- }
108
- }, k = u ?? (typeof e == "string" ? e : void 0), A = [
109
- "hn-menu__submenu",
110
- m ? "hn-menu__submenu--open" : void 0,
111
- c
112
- ].filter(Boolean).join(" "), j = (e) => {
113
- _.current = e, y(e);
114
- };
115
- return /* @__PURE__ */ n("div", {
116
- ...p,
117
- className: A,
118
- onPointerEnter: l ? void 0 : C,
119
- onPointerLeave: l ? void 0 : w,
120
- children: [/* @__PURE__ */ n("button", {
121
- "aria-expanded": m,
122
- "aria-haspopup": "menu",
123
- className: "hn-menu__item hn-menu__submenu-trigger",
124
- disabled: l,
125
- onClick: T,
126
- onKeyDown: D,
127
- ref: j,
128
- role: "menuitem",
129
- type: "button",
130
- children: [/* @__PURE__ */ t("span", {
131
- className: "hn-menu__item-label",
132
- children: e
133
- }), /* @__PURE__ */ t("span", {
134
- "aria-hidden": "true",
135
- className: "hn-menu__submenu-chevron",
136
- children: "▸"
137
- })]
138
- }), m ? /* @__PURE__ */ t(s, {
139
- anchor: v,
140
- anchorCrossOffset: -6,
141
- anchorOffset: 2,
142
- "aria-label": k,
143
- className: "hn-menu__submenu-panel",
144
- onKeyDown: O,
145
- placement: "right-start",
146
- ref: b,
147
- tabIndex: -1,
148
- children: o
149
- }) : null]
150
- });
151
- }
152
- //#endregion
153
- export { p as a, l as i, c as n, u as r, s as t };
@@ -1,87 +0,0 @@
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
- };
14
- function a(e) {
15
- let [t, n] = e.split("-");
16
- return {
17
- side: t,
18
- align: n
19
- };
20
- }
21
- function o(e, t, n, r, o, s, c) {
22
- let l = window.innerWidth, u = window.innerHeight, { side: d, align: f } = a(r), p = (r) => {
23
- switch (r) {
24
- case "bottom": return e.bottom + o + n > u - c;
25
- case "top": return e.top - o - n < c;
26
- case "right": return e.right + o + t > l - c;
27
- case "left": return e.left - o - t < c;
28
- }
29
- }, m = d;
30
- if (p(d)) {
31
- let e = i[d];
32
- p(e) || (m = e);
33
- }
34
- let h = 0, g = 0;
35
- switch (m) {
36
- case "bottom":
37
- h = e.bottom + o;
38
- break;
39
- case "top":
40
- h = e.top - o - n;
41
- break;
42
- case "right":
43
- g = e.right + o;
44
- break;
45
- case "left":
46
- g = e.left - o - t;
47
- break;
48
- }
49
- return m === "top" || m === "bottom" ? (g = f === "start" ? e.left : e.right - t, g += s) : (h = f === "start" ? e.top : e.bottom - n, h += s), g = Math.min(Math.max(g, c), Math.max(c, l - t - c)), h = Math.min(Math.max(h, c), Math.max(c, u - n - c)), {
50
- left: g,
51
- top: h
52
- };
53
- }
54
- function s({ anchor: i, placement: a = "bottom-start", offset: s = 6, crossOffset: c = 0, viewportMargin: l = 8 }) {
55
- let u = t(null), [d, f] = n(r);
56
- return e(() => {
57
- if (i === null) return;
58
- let e = () => {
59
- let e = u.current;
60
- if (e === null) return;
61
- let { left: t, top: n } = o(i.getBoundingClientRect(), e.offsetWidth, e.offsetHeight, a, s, c, l);
62
- f({
63
- position: "fixed",
64
- left: t,
65
- top: n
66
- });
67
- };
68
- e(), window.addEventListener("resize", e), window.addEventListener("scroll", e, !0);
69
- let t = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
70
- e();
71
- });
72
- return t?.observe(i), u.current !== null && t?.observe(u.current), () => {
73
- window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0), t?.disconnect();
74
- };
75
- }, [
76
- i,
77
- a,
78
- s,
79
- c,
80
- l
81
- ]), {
82
- floatingRef: u,
83
- style: d
84
- };
85
- }
86
- //#endregion
87
- export { s as t };