@hamster-note/components 0.2.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +411 -0
  3. package/dist/badge-BxBwSGqN.js +16 -0
  4. package/dist/badge.d.ts +2 -0
  5. package/dist/badge.js +2 -0
  6. package/dist/button-DRz0VTkf.js +18 -0
  7. package/dist/button.d.ts +2 -0
  8. package/dist/button.js +2 -0
  9. package/dist/components/badge/Badge.d.ts +7 -0
  10. package/dist/components/badge/index.d.ts +2 -0
  11. package/dist/components/button/Button.d.ts +9 -0
  12. package/dist/components/button/index.d.ts +2 -0
  13. package/dist/components/confirm/Confirm.d.ts +24 -0
  14. package/dist/components/confirm/confirm.d.ts +3 -0
  15. package/dist/components/confirm/index.d.ts +3 -0
  16. package/dist/components/dialog/Dialog.d.ts +11 -0
  17. package/dist/components/dialog/index.d.ts +2 -0
  18. package/dist/components/dialog/use-modal.d.ts +22 -0
  19. package/dist/components/drawer/Drawer.d.ts +14 -0
  20. package/dist/components/drawer/index.d.ts +2 -0
  21. package/dist/components/icon/Icon.d.ts +28 -0
  22. package/dist/components/icon/icon-names.d.ts +15 -0
  23. package/dist/components/icon/index.d.ts +4 -0
  24. package/dist/components/kbd/Kbd.d.ts +6 -0
  25. package/dist/components/kbd/index.d.ts +2 -0
  26. package/dist/components/loading/Loading.d.ts +12 -0
  27. package/dist/components/loading/index.d.ts +3 -0
  28. package/dist/components/loading/loading.d.ts +3 -0
  29. package/dist/components/menu/Menu.d.ts +25 -0
  30. package/dist/components/menu/index.d.ts +2 -0
  31. package/dist/components/note-card/NoteCard.d.ts +9 -0
  32. package/dist/components/note-card/index.d.ts +2 -0
  33. package/dist/components/popover/Popover.d.ts +21 -0
  34. package/dist/components/popover/index.d.ts +2 -0
  35. package/dist/components/popover/use-anchor-position.d.ts +14 -0
  36. package/dist/components/text-field/TextField.d.ts +7 -0
  37. package/dist/components/text-field/index.d.ts +2 -0
  38. package/dist/components/theme/ThemeProvider.d.ts +77 -0
  39. package/dist/components/theme/index.d.ts +4 -0
  40. package/dist/components/theme/theme.d.ts +87 -0
  41. package/dist/confirm-3eBmopl8.js +109 -0
  42. package/dist/confirm.d.ts +2 -0
  43. package/dist/confirm.js +2 -0
  44. package/dist/dialog-B4xS5zlK.js +53 -0
  45. package/dist/dialog.d.ts +2 -0
  46. package/dist/dialog.js +2 -0
  47. package/dist/drawer-DoeuGAHD.js +60 -0
  48. package/dist/drawer.d.ts +2 -0
  49. package/dist/drawer.js +2 -0
  50. package/dist/hamster-note-components.css +2 -0
  51. package/dist/icon-C40ONpMt.js +451 -0
  52. package/dist/icon.d.ts +2 -0
  53. package/dist/icon.js +2 -0
  54. package/dist/index.d.ts +26 -0
  55. package/dist/index.js +14 -0
  56. package/dist/kbd-D9XXd3qf.js +39 -0
  57. package/dist/kbd.d.ts +2 -0
  58. package/dist/kbd.js +2 -0
  59. package/dist/loading-BpykjzMR.js +88 -0
  60. package/dist/loading.d.ts +2 -0
  61. package/dist/loading.js +2 -0
  62. package/dist/menu-B6uuZFif.js +142 -0
  63. package/dist/menu.d.ts +2 -0
  64. package/dist/menu.js +2 -0
  65. package/dist/note-card-Dm-WbNTO.js +50 -0
  66. package/dist/note-card.d.ts +2 -0
  67. package/dist/note-card.js +2 -0
  68. package/dist/popover-Qg_fA2A_.js +165 -0
  69. package/dist/popover.d.ts +2 -0
  70. package/dist/popover.js +2 -0
  71. package/dist/text-field-B8Scu04G.js +31 -0
  72. package/dist/text-field.d.ts +2 -0
  73. package/dist/text-field.js +2 -0
  74. package/dist/theme-C0p_hpKk.js +67 -0
  75. package/dist/theme.d.ts +2 -0
  76. package/dist/theme.js +2 -0
  77. package/dist/use-modal-K9L8aPS0.js +82 -0
  78. package/package.json +111 -0
@@ -0,0 +1,142 @@
1
+ /* empty css */
2
+ import { r as e, t } from "./popover-Qg_fA2A_.js";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ import { useEffect as i, useRef as a, useState as o } from "react";
5
+ import { createPortal as s } from "react-dom";
6
+ //#region src/components/menu/Menu.tsx
7
+ function c({ children: e, className: t, ...r }) {
8
+ let i = ["hn-menu", t].filter(Boolean).join(" ");
9
+ return /* @__PURE__ */ n("div", {
10
+ ...r,
11
+ className: i,
12
+ role: "menu",
13
+ children: e
14
+ });
15
+ }
16
+ function l({ children: e, className: t, shortcut: i, tone: a = "default", type: o = "button", ...s }) {
17
+ let c = [
18
+ "hn-menu__item",
19
+ `hn-menu__item--${a}`,
20
+ t
21
+ ].filter(Boolean).join(" ");
22
+ return /* @__PURE__ */ r("button", {
23
+ ...s,
24
+ className: c,
25
+ role: "menuitem",
26
+ type: o,
27
+ children: [/* @__PURE__ */ n("span", {
28
+ className: "hn-menu__item-label",
29
+ children: e
30
+ }), i != null && i !== "" ? /* @__PURE__ */ n("span", {
31
+ className: "hn-menu__shortcut",
32
+ children: i
33
+ }) : null]
34
+ });
35
+ }
36
+ function u({ className: e, ...t }) {
37
+ let r = ["hn-menu__separator", e].filter(Boolean).join(" ");
38
+ return /* @__PURE__ */ n("hr", {
39
+ ...t,
40
+ className: r
41
+ });
42
+ }
43
+ function d({ children: e, className: t, ...r }) {
44
+ let i = ["hn-menu__label", t].filter(Boolean).join(" ");
45
+ return /* @__PURE__ */ n("div", {
46
+ ...r,
47
+ className: i,
48
+ children: e
49
+ });
50
+ }
51
+ var f = 150, p = 200;
52
+ function m({ label: l, children: u, className: d, disabled: m = !1, "aria-label": h, ...g }) {
53
+ let [_, v] = o(!1), y = a(null), b = a(null), [x, S] = o(null), C = a(null), { floatingRef: w, style: T } = e({
54
+ anchor: _ ? x : null,
55
+ placement: "right-start",
56
+ offset: 2,
57
+ crossOffset: -7
58
+ }), E = () => {
59
+ y.current !== null && (clearTimeout(y.current), y.current = null);
60
+ }, D = (e, t) => {
61
+ E(), y.current = setTimeout(() => {
62
+ v(e), y.current = null;
63
+ }, t);
64
+ };
65
+ i(() => () => {
66
+ y.current !== null && (clearTimeout(y.current), y.current = null);
67
+ }, []);
68
+ let O = () => {
69
+ m || D(!0, f);
70
+ }, k = () => {
71
+ D(!1, p);
72
+ }, A = () => {
73
+ m || (E(), v((e) => !e));
74
+ }, j = () => {
75
+ let e = C.current;
76
+ if (e === null) return;
77
+ let t = e.querySelector("[role=\"menuitem\"]");
78
+ t === null ? e.focus() : t.focus();
79
+ }, M = (e) => {
80
+ if (!m) switch (e.key) {
81
+ case "ArrowRight":
82
+ case "Enter":
83
+ case " ":
84
+ e.preventDefault(), E(), v(!0), requestAnimationFrame(() => {
85
+ j();
86
+ });
87
+ break;
88
+ }
89
+ }, N = (e) => {
90
+ switch (e.key) {
91
+ case "ArrowLeft":
92
+ case "Escape":
93
+ e.preventDefault(), E(), v(!1), b.current?.focus();
94
+ break;
95
+ }
96
+ }, P = h ?? (typeof l == "string" ? l : void 0), F = [
97
+ "hn-menu__submenu",
98
+ _ ? "hn-menu__submenu--open" : void 0,
99
+ d
100
+ ].filter(Boolean).join(" "), I = (e) => {
101
+ C.current = e, w.current = e;
102
+ }, L = (e) => {
103
+ b.current = e, S(e);
104
+ };
105
+ return /* @__PURE__ */ r("div", {
106
+ ...g,
107
+ className: F,
108
+ onPointerEnter: m ? void 0 : O,
109
+ onPointerLeave: m ? void 0 : k,
110
+ children: [/* @__PURE__ */ r("button", {
111
+ "aria-expanded": _,
112
+ "aria-haspopup": "menu",
113
+ className: "hn-menu__item hn-menu__submenu-trigger",
114
+ disabled: m,
115
+ onClick: A,
116
+ onKeyDown: M,
117
+ ref: L,
118
+ role: "menuitem",
119
+ type: "button",
120
+ children: [/* @__PURE__ */ n("span", {
121
+ className: "hn-menu__item-label",
122
+ children: l
123
+ }), /* @__PURE__ */ n("span", {
124
+ "aria-hidden": "true",
125
+ className: "hn-menu__submenu-chevron",
126
+ children: "▸"
127
+ })]
128
+ }), _ ? s(/* @__PURE__ */ n("div", {
129
+ className: "hn-menu__submenu-panel",
130
+ ref: I,
131
+ style: T,
132
+ children: /* @__PURE__ */ n(t, { children: /* @__PURE__ */ n(c, {
133
+ "aria-label": P,
134
+ onKeyDown: N,
135
+ tabIndex: -1,
136
+ children: u
137
+ }) })
138
+ }), document.body) : null]
139
+ });
140
+ }
141
+ //#endregion
142
+ export { m as a, u as i, l as n, d as r, c as t };
package/dist/menu.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components/menu/index.js'
2
+ export {}
package/dist/menu.js ADDED
@@ -0,0 +1,2 @@
1
+ import { a as e, i as t, n, r, t as i } from "./menu-B6uuZFif.js";
2
+ export { i as Menu, n as MenuItem, r as MenuLabel, t as MenuSeparator, e as MenuSubmenu };
@@ -0,0 +1,50 @@
1
+ /* empty css */
2
+ import { Fragment as e, jsx as t, jsxs as n } from "react/jsx-runtime";
3
+ //#region src/components/note-card/NoteCard.tsx
4
+ function r({ excerpt: r, meta: i, title: a }) {
5
+ return /* @__PURE__ */ n(e, { children: [/* @__PURE__ */ n("div", {
6
+ className: "hn-note-card__heading",
7
+ children: [/* @__PURE__ */ t("h3", {
8
+ className: "hn-note-card__title",
9
+ children: a
10
+ }), /* @__PURE__ */ t("p", {
11
+ className: "hn-note-card__excerpt",
12
+ children: r
13
+ })]
14
+ }), /* @__PURE__ */ t("p", {
15
+ className: "hn-note-card__meta",
16
+ children: i
17
+ })] });
18
+ }
19
+ function i({ className: e, excerpt: i, meta: a, onClick: o, selected: s = !1, title: c, ...l }) {
20
+ let u = [
21
+ "hn-note-card",
22
+ s ? "hn-note-card--selected" : void 0,
23
+ e
24
+ ].filter(Boolean).join(" ");
25
+ return o === void 0 ? /* @__PURE__ */ t("article", {
26
+ className: u,
27
+ ...l,
28
+ children: /* @__PURE__ */ t(r, {
29
+ excerpt: i,
30
+ meta: a,
31
+ title: c
32
+ })
33
+ }) : /* @__PURE__ */ n("article", {
34
+ className: `${u} hn-note-card--interactive`,
35
+ ...l,
36
+ children: [/* @__PURE__ */ t("button", {
37
+ "aria-label": c,
38
+ "aria-pressed": s,
39
+ className: "hn-note-card__action",
40
+ onClick: o,
41
+ type: "button"
42
+ }), /* @__PURE__ */ t(r, {
43
+ excerpt: i,
44
+ meta: a,
45
+ title: c
46
+ })]
47
+ });
48
+ }
49
+ //#endregion
50
+ export { i as t };
@@ -0,0 +1,2 @@
1
+ export * from './components/note-card/index.js'
2
+ export {}
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./note-card-Dm-WbNTO.js";
2
+ export { e as NoteCard };
@@ -0,0 +1,165 @@
1
+ /* empty css */
2
+ import { jsx as e } from "react/jsx-runtime";
3
+ import { createContext as t, useContext as n, useLayoutEffect as r, useRef as i, useState as a } from "react";
4
+ import { createPortal as o } from "react-dom";
5
+ //#region src/components/popover/use-anchor-position.ts
6
+ var s = {
7
+ position: "fixed",
8
+ top: 0,
9
+ left: 0,
10
+ visibility: "hidden"
11
+ }, c = {
12
+ top: "bottom",
13
+ bottom: "top",
14
+ left: "right",
15
+ right: "left"
16
+ };
17
+ function l(e) {
18
+ let [t, n] = e.split("-");
19
+ return {
20
+ side: t,
21
+ align: n
22
+ };
23
+ }
24
+ function u(e, t, n, r, i, a, o) {
25
+ let s = window.innerWidth, u = window.innerHeight, { side: d, align: f } = l(r), p = (r) => {
26
+ switch (r) {
27
+ case "bottom": return e.bottom + i + n > u - o;
28
+ case "top": return e.top - i - n < o;
29
+ case "right": return e.right + i + t > s - o;
30
+ case "left": return e.left - i - t < o;
31
+ }
32
+ }, m = d;
33
+ if (p(d)) {
34
+ let e = c[d];
35
+ p(e) || (m = e);
36
+ }
37
+ let h = 0, g = 0;
38
+ switch (m) {
39
+ case "bottom":
40
+ h = e.bottom + i;
41
+ break;
42
+ case "top":
43
+ h = e.top - i - n;
44
+ break;
45
+ case "right":
46
+ g = e.right + i;
47
+ break;
48
+ case "left":
49
+ g = e.left - i - t;
50
+ break;
51
+ }
52
+ return m === "top" || m === "bottom" ? (g = f === "start" ? e.left : e.right - t, g += a) : (h = f === "start" ? e.top : e.bottom - n, h += a), g = Math.min(Math.max(g, o), Math.max(o, s - t - o)), h = Math.min(Math.max(h, o), Math.max(o, u - n - o)), {
53
+ left: g,
54
+ top: h
55
+ };
56
+ }
57
+ function d({ anchor: e, placement: t = "bottom-start", offset: n = 6, crossOffset: o = 0, viewportMargin: c = 8 }) {
58
+ let l = i(null), [d, f] = a(s);
59
+ return r(() => {
60
+ if (e === null) return;
61
+ let r = () => {
62
+ let r = l.current;
63
+ if (r === null) return;
64
+ let { left: i, top: a } = u(e.getBoundingClientRect(), r.offsetWidth, r.offsetHeight, t, n, o, c);
65
+ f({
66
+ position: "fixed",
67
+ left: i,
68
+ top: a
69
+ });
70
+ };
71
+ r(), window.addEventListener("resize", r), window.addEventListener("scroll", r, !0);
72
+ let i = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
73
+ r();
74
+ });
75
+ return i?.observe(e), l.current !== null && i?.observe(l.current), () => {
76
+ window.removeEventListener("resize", r), window.removeEventListener("scroll", r, !0), i?.disconnect();
77
+ };
78
+ }, [
79
+ e,
80
+ t,
81
+ n,
82
+ o,
83
+ c
84
+ ]), {
85
+ floatingRef: l,
86
+ style: d
87
+ };
88
+ }
89
+ //#endregion
90
+ //#region src/components/popover/Popover.tsx
91
+ var f = t(null);
92
+ function p(e) {
93
+ return e === "vertical" ? "horizontal" : "vertical";
94
+ }
95
+ function m(e, t) {
96
+ if (e === void 0) return {};
97
+ switch (e) {
98
+ case "top": return {
99
+ position: "fixed",
100
+ top: t,
101
+ left: "50%",
102
+ transform: "translateX(-50%)"
103
+ };
104
+ case "bottom": return {
105
+ position: "fixed",
106
+ bottom: t,
107
+ left: "50%",
108
+ transform: "translateX(-50%)"
109
+ };
110
+ case "left": return {
111
+ position: "fixed",
112
+ left: t,
113
+ top: "50%",
114
+ transform: "translateY(-50%)"
115
+ };
116
+ case "right": return {
117
+ position: "fixed",
118
+ right: t,
119
+ top: "50%",
120
+ transform: "translateY(-50%)"
121
+ };
122
+ }
123
+ }
124
+ function h({ children: t, className: n, theme: r = "dark", orientation: i = "horizontal", edge: a, edgeOffset: s = 16, anchor: c = null, placement: l = "bottom-start", anchorOffset: u = 6, viewportMargin: p = 8, ref: h, style: g, ..._ }) {
125
+ let v = c !== null, { floatingRef: y, style: b } = d({
126
+ anchor: c,
127
+ placement: l,
128
+ offset: u,
129
+ viewportMargin: p
130
+ }), x = [
131
+ "hn-popover",
132
+ v ? "hn-popover--floating" : void 0,
133
+ n
134
+ ].filter(Boolean).join(" "), S = v ? {
135
+ ...b,
136
+ ...g
137
+ } : {
138
+ ...m(a, s),
139
+ ...g
140
+ }, C = (e) => {
141
+ y.current = e, typeof h == "function" ? h(e) : h != null && (h.current = e);
142
+ }, w = /* @__PURE__ */ e(f.Provider, {
143
+ value: i,
144
+ children: /* @__PURE__ */ e("div", {
145
+ ..._,
146
+ className: x,
147
+ "data-theme": r,
148
+ "data-orientation": i,
149
+ ref: C,
150
+ style: S,
151
+ children: t
152
+ })
153
+ });
154
+ return v && typeof document < "u" ? o(w, document.body) : w;
155
+ }
156
+ function g({ className: t, ...r }) {
157
+ let i = ["hn-popover__separator", t].filter(Boolean).join(" "), a = n(f);
158
+ return /* @__PURE__ */ e("hr", {
159
+ ...r,
160
+ "aria-orientation": p(a),
161
+ className: i
162
+ });
163
+ }
164
+ //#endregion
165
+ export { g as n, d as r, h as t };
@@ -0,0 +1,2 @@
1
+ export * from './components/popover/index.js'
2
+ export {}
@@ -0,0 +1,2 @@
1
+ import { n as e, t } from "./popover-Qg_fA2A_.js";
2
+ export { t as Popover, e as PopoverSeparator };
@@ -0,0 +1,31 @@
1
+ /* empty css */
2
+ import { jsx as e, jsxs as t } from "react/jsx-runtime";
3
+ import { useId as n } from "react";
4
+ //#region src/components/text-field/TextField.tsx
5
+ function r({ "aria-describedby": r, error: i, hint: a, id: o, label: s, ...c }) {
6
+ let l = n(), u = o ?? l, d = i ?? a, f = d === void 0 ? void 0 : `${u}-message`, p = [r, f].filter(Boolean).join(" ") || void 0;
7
+ return /* @__PURE__ */ t("div", {
8
+ className: i === void 0 ? "hn-text-field" : "hn-text-field hn-text-field--invalid",
9
+ children: [
10
+ /* @__PURE__ */ e("label", {
11
+ className: "hn-text-field__label",
12
+ htmlFor: u,
13
+ children: s
14
+ }),
15
+ /* @__PURE__ */ e("input", {
16
+ "aria-describedby": p,
17
+ "aria-invalid": i !== void 0 || void 0,
18
+ className: "hn-text-field__control",
19
+ id: u,
20
+ ...c
21
+ }),
22
+ d === void 0 ? null : /* @__PURE__ */ e("p", {
23
+ className: "hn-text-field__message",
24
+ id: f,
25
+ children: d
26
+ })
27
+ ]
28
+ });
29
+ }
30
+ //#endregion
31
+ export { r as t };
@@ -0,0 +1,2 @@
1
+ export * from './components/text-field/index.js'
2
+ export {}
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./text-field-B8Scu04G.js";
2
+ export { e as TextField };
@@ -0,0 +1,67 @@
1
+ /* empty css */
2
+ import { jsx as e } from "react/jsx-runtime";
3
+ //#region src/components/theme/theme.ts
4
+ var t = {
5
+ violet: {
6
+ accent: "#7c83ff",
7
+ accentHover: "#9197ff",
8
+ focusRingColor: "rgb(145 151 255 / 42%)"
9
+ },
10
+ blue: {
11
+ accent: "#60a5fa",
12
+ accentHover: "#7db6fb",
13
+ focusRingColor: "rgb(96 165 250 / 42%)"
14
+ },
15
+ teal: {
16
+ accent: "#2dd4bf",
17
+ accentHover: "#4fdcc9",
18
+ focusRingColor: "rgb(45 212 191 / 42%)"
19
+ },
20
+ orange: {
21
+ accent: "#fb923c",
22
+ accentHover: "#fca45c",
23
+ focusRingColor: "rgb(251 146 60 / 42%)"
24
+ },
25
+ pink: {
26
+ accent: "#f472b6",
27
+ accentHover: "#f68cc4",
28
+ focusRingColor: "rgb(244 114 182 / 42%)"
29
+ }
30
+ };
31
+ function n(e) {
32
+ return e in t;
33
+ }
34
+ //#endregion
35
+ //#region src/components/theme/ThemeProvider.tsx
36
+ function r(e) {
37
+ if (n(e)) {
38
+ let n = t[e];
39
+ return {
40
+ dataAccent: e,
41
+ style: {
42
+ "--hn-color-accent": n.accent,
43
+ "--hn-color-accent-hover": n.accentHover,
44
+ "--hn-focus-ring": `0 0 0 3px ${n.focusRingColor}`
45
+ }
46
+ };
47
+ }
48
+ return {
49
+ dataAccent: "custom",
50
+ style: { "--hn-color-accent": e }
51
+ };
52
+ }
53
+ function i({ accent: t = "violet", children: n, className: i, mode: a = "dark", style: o }) {
54
+ let { dataAccent: s, style: c } = r(t);
55
+ return /* @__PURE__ */ e("div", {
56
+ className: ["hn-theme", i].filter(Boolean).join(" "),
57
+ "data-accent": s,
58
+ "data-mode": a,
59
+ style: {
60
+ ...c,
61
+ ...o
62
+ },
63
+ children: n
64
+ });
65
+ }
66
+ //#endregion
67
+ export { t as n, n as r, i as t };
@@ -0,0 +1,2 @@
1
+ export * from './components/theme/index.js'
2
+ export {}
package/dist/theme.js ADDED
@@ -0,0 +1,2 @@
1
+ import { n as e, r as t, t as n } from "./theme-C0p_hpKk.js";
2
+ export { e as THEME_ACCENTS, n as ThemeProvider, t as isThemeAccentPreset };
@@ -0,0 +1,82 @@
1
+ import { useEffect as e, useId as t, useLayoutEffect as n, useMemo as r, useRef as i, useState as a } from "react";
2
+ //#region src/components/dialog/use-modal.ts
3
+ function o(e) {
4
+ return !(e.getAttribute("aria-hidden") === "true" || e.hasAttribute("hidden"));
5
+ }
6
+ function s(e) {
7
+ return Array.from(e.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), textarea:not([disabled]), select:not([disabled]), [tabindex]")).filter((e) => o(e));
8
+ }
9
+ function c({ open: o, onClose: c, closeOnEsc: l = !0, closeOnBackdrop: u = !0, exitDuration: d = 180 }) {
10
+ let [f, p] = a("closed"), m = i(null), h = i(null), g = i(null), _ = i(""), v = i(!1), y = t(), b = t(), x = r(() => o ? f === "closed" || f === "leaving" ? "entering" : f : f === "entering" || f === "open" ? "leaving" : f, [o, f]);
11
+ e(() => {
12
+ if (x !== "entering") return;
13
+ let e = setTimeout(() => {
14
+ p("open");
15
+ }, 180);
16
+ return () => {
17
+ clearTimeout(e);
18
+ };
19
+ }, [x]), e(() => {
20
+ if (x !== "leaving") return;
21
+ let e = setTimeout(() => {
22
+ p("closed");
23
+ }, d);
24
+ return () => {
25
+ clearTimeout(e);
26
+ };
27
+ }, [x, d]), e(() => {
28
+ if (x !== "entering" && x !== "closed") return;
29
+ if (x === "entering") {
30
+ let e = document.activeElement;
31
+ e instanceof HTMLElement && (g.current = e), v.current ||= (_.current = document.body.style.overflow, document.body.style.overflow = "hidden", !0);
32
+ let t = requestAnimationFrame(() => {
33
+ let e = m.current;
34
+ if (e === null) return;
35
+ let t = s(e);
36
+ t.length > 0 ? t[0]?.focus() : e.focus();
37
+ });
38
+ return () => {
39
+ cancelAnimationFrame(t);
40
+ };
41
+ }
42
+ let e = g.current;
43
+ e !== null && (document.contains(e) && e.focus(), g.current = null), v.current &&= (document.body.style.overflow = _.current, _.current = "", !1);
44
+ }, [x]), e(() => () => {
45
+ v.current &&= (document.body.style.overflow = _.current, _.current = "", !1);
46
+ }, []);
47
+ let S = i(l), C = i(u), w = i(c);
48
+ return n(() => {
49
+ S.current = l, C.current = u, w.current = c;
50
+ }), {
51
+ phase: x,
52
+ mounted: x !== "closed",
53
+ dataState: x === "leaving" ? "exit" : x === "entering" || x === "open" ? "enter" : void 0,
54
+ panelRef: m,
55
+ backdropRef: h,
56
+ titleId: y,
57
+ descriptionId: b,
58
+ handlePanelKeyDown: (e) => {
59
+ if (S.current && e.key === "Escape") {
60
+ e.preventDefault(), w.current();
61
+ return;
62
+ }
63
+ if (e.key !== "Tab") return;
64
+ let t = m.current;
65
+ if (t === null) return;
66
+ let n = s(t);
67
+ if (n.length === 0) {
68
+ e.preventDefault(), t.focus();
69
+ return;
70
+ }
71
+ let r = n[0], i = n[n.length - 1];
72
+ if (r === void 0 || i === void 0) return;
73
+ let a = document.activeElement;
74
+ e.shiftKey ? (a === r || a === t || !t.contains(a)) && (e.preventDefault(), i.focus()) : (a === i || !t.contains(a)) && (e.preventDefault(), r.focus());
75
+ },
76
+ handleBackdropPointerDown: (e) => {
77
+ C.current && e.target === h.current && w.current();
78
+ }
79
+ };
80
+ }
81
+ //#endregion
82
+ export { c as t };
package/package.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "name": "@hamster-note/components",
3
+ "version": "0.2.0",
4
+ "description": "Reusable React components for HamsterNote products.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "sideEffects": [
11
+ "**/*.css"
12
+ ],
13
+ "main": "./dist/index.js",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./button": {
22
+ "types": "./dist/button.d.ts",
23
+ "import": "./dist/button.js"
24
+ },
25
+ "./icon": {
26
+ "types": "./dist/icon.d.ts",
27
+ "import": "./dist/icon.js"
28
+ },
29
+ "./badge": {
30
+ "types": "./dist/badge.d.ts",
31
+ "import": "./dist/badge.js"
32
+ },
33
+ "./confirm": {
34
+ "types": "./dist/confirm.d.ts",
35
+ "import": "./dist/confirm.js"
36
+ },
37
+ "./dialog": {
38
+ "types": "./dist/dialog.d.ts",
39
+ "import": "./dist/dialog.js"
40
+ },
41
+ "./drawer": {
42
+ "types": "./dist/drawer.d.ts",
43
+ "import": "./dist/drawer.js"
44
+ },
45
+ "./kbd": {
46
+ "types": "./dist/kbd.d.ts",
47
+ "import": "./dist/kbd.js"
48
+ },
49
+ "./loading": {
50
+ "types": "./dist/loading.d.ts",
51
+ "import": "./dist/loading.js"
52
+ },
53
+ "./menu": {
54
+ "types": "./dist/menu.d.ts",
55
+ "import": "./dist/menu.js"
56
+ },
57
+ "./note-card": {
58
+ "types": "./dist/note-card.d.ts",
59
+ "import": "./dist/note-card.js"
60
+ },
61
+ "./popover": {
62
+ "types": "./dist/popover.d.ts",
63
+ "import": "./dist/popover.js"
64
+ },
65
+ "./text-field": {
66
+ "types": "./dist/text-field.d.ts",
67
+ "import": "./dist/text-field.js"
68
+ },
69
+ "./theme": {
70
+ "types": "./dist/theme.d.ts",
71
+ "import": "./dist/theme.js"
72
+ },
73
+ "./styles.css": "./dist/hamster-note-components.css"
74
+ },
75
+ "scripts": {
76
+ "dev": "vite",
77
+ "build": "yarn typecheck && vite build --config vite.lib.config.ts",
78
+ "build:demo": "yarn typecheck && vite build",
79
+ "preview": "vite preview --host 0.0.0.0 --port 9810 --strictPort",
80
+ "typecheck": "tsc --noEmit",
81
+ "lint": "eslint . --max-warnings 0",
82
+ "format": "prettier --write .",
83
+ "format:check": "prettier --check .",
84
+ "check": "yarn typecheck && yarn lint && yarn format:check"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "^19.0.0",
88
+ "react-dom": "^19.0.0"
89
+ },
90
+ "devDependencies": {
91
+ "@eslint/js": "10.0.1",
92
+ "@types/react": "19.2.17",
93
+ "@types/react-dom": "19.2.3",
94
+ "@vitejs/plugin-react": "6.0.3",
95
+ "eslint": "10.7.0",
96
+ "eslint-plugin-react-hooks": "7.1.1",
97
+ "eslint-plugin-react-refresh": "0.5.3",
98
+ "globals": "17.7.0",
99
+ "prettier": "3.9.5",
100
+ "react": "19.2.7",
101
+ "react-dom": "19.2.7",
102
+ "typescript": "6.0.3",
103
+ "typescript-eslint": "8.64.0",
104
+ "vite": "8.1.5",
105
+ "vite-plugin-dts": "5.0.3"
106
+ },
107
+ "engines": {
108
+ "node": "^20.19.0 || >=22.12.0"
109
+ },
110
+ "packageManager": "yarn@1.22.22"
111
+ }