@overdoser/react-toolkit 0.18.0 → 0.20.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/AGENTS.md +51 -7
- package/CHANGELOG.md +162 -0
- package/components/Accordion/Accordion.d.ts +94 -0
- package/components/Accordion/Accordion.js +180 -0
- package/components/Accordion/Accordion.module.scss.js +36 -0
- package/components/Accordion/index.d.ts +2 -0
- package/components/Alert/Alert.d.ts +29 -1
- package/components/Alert/Alert.js +44 -30
- package/components/Alert/Alert.module.scss.js +24 -16
- package/components/Alert/index.d.ts +1 -1
- package/components/Card/Card.d.ts +86 -0
- package/components/Card/Card.js +132 -0
- package/components/Card/Card.module.scss.js +60 -0
- package/components/Card/index.d.ts +2 -0
- package/components/Chip/Chip.d.ts +86 -0
- package/components/Chip/Chip.js +141 -0
- package/components/Chip/Chip.module.scss.js +59 -0
- package/components/Chip/index.d.ts +2 -0
- package/components/CodeBlock/CodeBlock.d.ts +78 -0
- package/components/CodeBlock/CodeBlock.js +120 -0
- package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
- package/components/CodeBlock/index.d.ts +2 -0
- package/components/CommandPalette/CommandPalette.d.ts +141 -0
- package/components/CommandPalette/CommandPalette.js +397 -0
- package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
- package/components/CommandPalette/index.d.ts +2 -0
- package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
- package/components/ConfirmDialog/ConfirmDialog.js +201 -0
- package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
- package/components/ConfirmDialog/index.d.ts +2 -0
- package/components/Drawer/Drawer.d.ts +1 -0
- package/components/Drawer/Drawer.js +35 -36
- package/components/Drawer/Drawer.module.scss.js +20 -18
- package/components/Dropdown/Dropdown.d.ts +47 -7
- package/components/Dropdown/Dropdown.js +174 -81
- package/components/Dropdown/Dropdown.module.scss.js +40 -22
- package/components/Dropdown/DropdownItem.d.ts +31 -2
- package/components/Dropdown/DropdownItem.js +54 -27
- package/components/Dropdown/DropdownLabel.d.ts +11 -0
- package/components/Dropdown/DropdownLabel.js +11 -0
- package/components/Dropdown/DropdownSeparator.d.ts +12 -0
- package/components/Dropdown/DropdownSeparator.js +11 -0
- package/components/Dropdown/dropdownContext.d.ts +6 -0
- package/components/Dropdown/dropdownContext.js +5 -0
- package/components/Dropdown/index.d.ts +8 -2
- package/components/Dropdown/useContextMenu.d.ts +32 -0
- package/components/Dropdown/useContextMenu.js +18 -0
- package/components/EmptyState/EmptyState.d.ts +53 -0
- package/components/EmptyState/EmptyState.js +55 -0
- package/components/EmptyState/EmptyState.module.scss.js +25 -0
- package/components/EmptyState/index.d.ts +2 -0
- package/components/Form/FormField.js +25 -24
- package/components/ImageViewer/ImageViewer.d.ts +105 -0
- package/components/ImageViewer/ImageViewer.js +201 -0
- package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
- package/components/ImageViewer/index.d.ts +4 -0
- package/components/ImageViewer/useZoomPan.d.ts +94 -0
- package/components/ImageViewer/useZoomPan.js +141 -0
- package/components/Kbd/Kbd.d.ts +26 -0
- package/components/Kbd/Kbd.js +22 -0
- package/components/Kbd/Kbd.module.scss.js +17 -0
- package/components/Kbd/index.d.ts +2 -0
- package/components/KeyValueList/KeyValueList.d.ts +84 -0
- package/components/KeyValueList/KeyValueList.js +127 -0
- package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
- package/components/KeyValueList/index.d.ts +2 -0
- package/components/Modal/Modal.d.ts +1 -0
- package/components/Modal/Modal.js +40 -41
- package/components/Modal/Modal.module.scss.js +18 -16
- package/components/PageHeader/PageHeader.d.ts +61 -0
- package/components/PageHeader/PageHeader.js +73 -0
- package/components/PageHeader/PageHeader.module.scss.js +43 -0
- package/components/PageHeader/index.d.ts +2 -0
- package/components/ProgressBar/ProgressBar.d.ts +74 -0
- package/components/ProgressBar/ProgressBar.js +90 -0
- package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
- package/components/ProgressBar/index.d.ts +2 -0
- package/components/RelativeTime/RelativeTime.d.ts +45 -0
- package/components/RelativeTime/RelativeTime.js +43 -0
- package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
- package/components/RelativeTime/index.d.ts +2 -0
- package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
- package/components/SegmentedControl/SegmentedControl.js +131 -0
- package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
- package/components/SegmentedControl/index.d.ts +2 -0
- package/components/SplitPane/SplitPane.d.ts +61 -0
- package/components/SplitPane/SplitPane.js +171 -0
- package/components/SplitPane/SplitPane.module.scss.js +25 -0
- package/components/SplitPane/index.d.ts +2 -0
- package/components/StatCard/StatCard.d.ts +105 -0
- package/components/StatCard/StatCard.js +127 -0
- package/components/StatCard/StatCard.module.scss.js +72 -0
- package/components/StatCard/index.d.ts +2 -0
- package/components/StatusDot/StatusDot.d.ts +33 -0
- package/components/StatusDot/StatusDot.js +39 -0
- package/components/StatusDot/StatusDot.module.scss.js +32 -0
- package/components/StatusDot/index.d.ts +2 -0
- package/components/Table/Table.d.ts +140 -17
- package/components/Table/Table.js +382 -210
- package/components/Table/Table.module.scss.js +68 -46
- package/components/Table/index.d.ts +1 -1
- package/components/Table/useTableSort.d.ts +1 -1
- package/components/ThemeToggle/ThemeToggle.d.ts +40 -0
- package/components/ThemeToggle/ThemeToggle.js +98 -0
- package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
- package/components/ThemeToggle/index.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.js +29 -28
- package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
- package/components/inputs/Input/Input.d.ts +33 -1
- package/components/inputs/Input/Input.js +94 -35
- package/components/inputs/Input/Input.module.scss.js +14 -12
- package/components/inputs/Radio/Radio.d.ts +5 -4
- package/components/inputs/Radio/Radio.js +55 -50
- package/components/inputs/Radio/Radio.module.scss.js +12 -10
- package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
- package/components/inputs/SearchInput/SearchInput.js +116 -0
- package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
- package/components/inputs/SearchInput/index.d.ts +2 -0
- package/components/inputs/Select/Select.d.ts +52 -0
- package/components/inputs/Select/Select.js +494 -385
- package/components/inputs/Select/Select.module.scss.js +34 -30
- package/components/inputs/Switch/Switch.d.ts +15 -0
- package/components/inputs/Switch/Switch.js +8 -0
- package/components/inputs/Switch/index.d.ts +2 -0
- package/hooks/useDebouncedValue.d.ts +15 -0
- package/hooks/useDebouncedValue.js +15 -0
- package/hooks/useElementSize.d.ts +20 -0
- package/hooks/useElementSize.js +23 -0
- package/hooks/useKeyboard.d.ts +49 -5
- package/hooks/useKeyboard.js +66 -16
- package/hooks/useMediaQuery.d.ts +14 -0
- package/hooks/useMediaQuery.js +16 -0
- package/hooks/useNow.d.ts +14 -0
- package/hooks/useNow.js +35 -0
- package/hooks/usePersistedState.d.ts +30 -0
- package/hooks/usePersistedState.js +99 -0
- package/hooks/useResizable.d.ts +66 -0
- package/hooks/useResizable.js +105 -0
- package/hooks/useTheme.d.ts +33 -0
- package/hooks/useTheme.js +25 -0
- package/index.css +1 -1
- package/index.d.ts +58 -4
- package/index.js +208 -132
- package/index.layered.css +1 -1
- package/llms.txt +620 -26
- package/manifest.json +1795 -99
- package/package.json +1 -1
- package/recipes/confirm-modal.tsx +65 -53
- package/recipes/floating-copy-button.tsx +32 -28
- package/utils/formatBytes.d.ts +21 -0
- package/utils/formatBytes.js +14 -0
- package/utils/index.d.ts +6 -0
- package/utils/themeScript.d.ts +19 -0
- package/utils/themeScript.js +9 -0
- package/utils/timeAgo.d.ts +33 -0
- package/utils/timeAgo.js +37 -0
|
@@ -1,131 +1,224 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import
|
|
1
|
+
import { jsx as u, jsxs as v } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as me, useState as $, useRef as E, useId as fe, useCallback as y, useEffect as ee, useLayoutEffect as he } from "react";
|
|
3
|
+
import { createPortal as te } from "react-dom";
|
|
4
|
+
import l from "clsx";
|
|
5
5
|
import t from "./Dropdown.module.scss.js";
|
|
6
|
-
import { useEscapeLayer as
|
|
7
|
-
import { usePortalPosition as
|
|
8
|
-
|
|
6
|
+
import { useEscapeLayer as ge, EscapeLayerProvider as pe } from "../../hooks/useEscapeLayer.js";
|
|
7
|
+
import { usePortalPosition as ve } from "../../hooks/usePortalPosition.js";
|
|
8
|
+
import { DropdownMenuContext as ye } from "./dropdownContext.js";
|
|
9
|
+
const ne = '[role="menuitem"]:not(:disabled), [role="menuitemcheckbox"]:not(:disabled)', g = 8, we = me(
|
|
9
10
|
({
|
|
10
|
-
trigger:
|
|
11
|
-
children:
|
|
12
|
-
align:
|
|
13
|
-
className:
|
|
14
|
-
style:
|
|
15
|
-
id:
|
|
16
|
-
onOpen:
|
|
17
|
-
onClose:
|
|
18
|
-
options:
|
|
19
|
-
placeholder:
|
|
20
|
-
value:
|
|
21
|
-
onChange:
|
|
11
|
+
trigger: A,
|
|
12
|
+
children: re,
|
|
13
|
+
align: L = "left",
|
|
14
|
+
className: O,
|
|
15
|
+
style: K,
|
|
16
|
+
id: W,
|
|
17
|
+
onOpen: z,
|
|
18
|
+
onClose: T,
|
|
19
|
+
options: f,
|
|
20
|
+
placeholder: oe = "Select...",
|
|
21
|
+
value: H,
|
|
22
|
+
onChange: j,
|
|
22
23
|
error: q = !1,
|
|
23
24
|
fullWidth: a = !0,
|
|
24
|
-
portal:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, [s]), A = b(() => {
|
|
34
|
-
x((e) => {
|
|
35
|
-
const f = !e;
|
|
36
|
-
return f ? y?.() : s?.(), f;
|
|
37
|
-
});
|
|
38
|
-
}, [y, s]), B = b(
|
|
25
|
+
portal: w = !0,
|
|
26
|
+
open: B,
|
|
27
|
+
onOpenChange: _,
|
|
28
|
+
anchor: o,
|
|
29
|
+
classes: i
|
|
30
|
+
}, G) => {
|
|
31
|
+
const [ie, ce] = $(!1), D = B !== void 0, n = D ? B : ie, M = E(n);
|
|
32
|
+
M.current = n;
|
|
33
|
+
const k = E(null), s = E(null), b = E(null), I = fe(), N = o !== void 0, U = N && o !== null, V = !!f || A !== void 0 || !N, x = y(
|
|
39
34
|
(e) => {
|
|
40
|
-
|
|
35
|
+
e !== M.current && (D || ce(e), _?.(e), e ? z?.() : T?.());
|
|
41
36
|
},
|
|
42
|
-
[
|
|
37
|
+
[D, _, z, T]
|
|
43
38
|
);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
ee(() => {
|
|
40
|
+
n && s.current && s.current.querySelector(ne)?.focus();
|
|
41
|
+
}, [n]);
|
|
42
|
+
const h = y(() => {
|
|
43
|
+
x(!1), b.current?.focus();
|
|
44
|
+
}, [x]), F = y(() => {
|
|
45
|
+
x(!M.current);
|
|
46
|
+
}, [x]), le = y((e) => {
|
|
47
|
+
const m = s.current;
|
|
48
|
+
if (!m) return;
|
|
49
|
+
const r = Array.from(m.querySelectorAll(ne));
|
|
50
|
+
if (r.length === 0) return;
|
|
51
|
+
const d = r.indexOf(document.activeElement), c = (P) => {
|
|
52
|
+
r[(P + r.length) % r.length]?.focus();
|
|
53
|
+
};
|
|
54
|
+
switch (e.key) {
|
|
55
|
+
case "ArrowDown":
|
|
56
|
+
e.preventDefault(), c(d + 1);
|
|
57
|
+
return;
|
|
58
|
+
case "ArrowUp":
|
|
59
|
+
e.preventDefault(), c(d - 1);
|
|
60
|
+
return;
|
|
61
|
+
case "Home":
|
|
62
|
+
e.preventDefault(), c(0);
|
|
63
|
+
return;
|
|
64
|
+
case "End":
|
|
65
|
+
e.preventDefault(), c(r.length - 1);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && e.key !== " ") {
|
|
69
|
+
const P = e.key.toLowerCase();
|
|
70
|
+
for (let S = 1; S <= r.length; S++) {
|
|
71
|
+
const Z = r[(d + S) % r.length];
|
|
72
|
+
if ((Z.textContent ?? "").trim().toLowerCase().startsWith(P)) {
|
|
73
|
+
e.preventDefault(), Z.focus();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, []), [R, J] = $(null);
|
|
79
|
+
he(() => {
|
|
80
|
+
if (!n || !o || !s.current || typeof window > "u") {
|
|
81
|
+
J(null);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const e = s.current.getBoundingClientRect(), m = document.documentElement.clientWidth || window.innerWidth, r = document.documentElement.clientHeight || window.innerHeight;
|
|
85
|
+
let d = o.x, c = o.y;
|
|
86
|
+
d + e.width > m - g && (d = o.x - e.width), c + e.height > r - g && (c = o.y - e.height), d = Math.max(g, Math.min(d, m - g - e.width)), c = Math.max(g, Math.min(c, r - g - e.height)), J({ top: Math.round(c), left: Math.round(d) });
|
|
87
|
+
}, [n, o?.x, o?.y]);
|
|
88
|
+
const de = y(
|
|
89
|
+
(e) => {
|
|
90
|
+
j?.(e), h();
|
|
91
|
+
},
|
|
92
|
+
[j, h]
|
|
93
|
+
);
|
|
94
|
+
ee(() => {
|
|
95
|
+
if (!n) return;
|
|
96
|
+
const e = (m) => {
|
|
97
|
+
const r = m.target;
|
|
98
|
+
k.current?.contains(r) || s.current?.contains(r) || h();
|
|
49
99
|
};
|
|
50
100
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
51
|
-
}, [
|
|
52
|
-
const
|
|
101
|
+
}, [n, h]);
|
|
102
|
+
const ue = ge(h, n), p = ve(b, n && w && !U), ae = { close: h }, Q = f?.find((e) => e.value === H)?.label, X = f ? Q || oe : A, Y = f && !Q, se = f ? f.map((e) => /* @__PURE__ */ u(
|
|
53
103
|
"button",
|
|
54
104
|
{
|
|
55
105
|
type: "button",
|
|
56
106
|
role: "menuitem",
|
|
57
|
-
className:
|
|
107
|
+
className: l(
|
|
58
108
|
t.item,
|
|
59
109
|
e.disabled && t.itemDisabled,
|
|
60
|
-
e.value ===
|
|
61
|
-
|
|
110
|
+
e.value === H && t.itemSelected,
|
|
111
|
+
i?.item
|
|
62
112
|
),
|
|
63
113
|
disabled: e.disabled,
|
|
64
|
-
onClick: () =>
|
|
114
|
+
onClick: () => de(e.value),
|
|
65
115
|
children: e.label
|
|
66
116
|
},
|
|
67
117
|
e.value
|
|
68
|
-
)) :
|
|
118
|
+
)) : re, C = (e) => /* @__PURE__ */ u(
|
|
69
119
|
"div",
|
|
70
120
|
{
|
|
71
|
-
ref:
|
|
72
|
-
id:
|
|
73
|
-
className:
|
|
121
|
+
ref: s,
|
|
122
|
+
id: I,
|
|
123
|
+
className: l(
|
|
74
124
|
t.menu,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
!
|
|
78
|
-
|
|
125
|
+
n && t.menuOpen,
|
|
126
|
+
L === "left" ? t.alignLeft : t.alignRight,
|
|
127
|
+
!w && a && t.fullWidth,
|
|
128
|
+
i?.menu
|
|
79
129
|
),
|
|
80
130
|
style: e,
|
|
81
131
|
role: "menu",
|
|
82
|
-
|
|
132
|
+
onKeyDown: le,
|
|
133
|
+
children: /* @__PURE__ */ u(pe, { value: ue, children: /* @__PURE__ */ u(ye.Provider, { value: ae, children: se }) })
|
|
83
134
|
}
|
|
84
135
|
);
|
|
85
|
-
return /* @__PURE__ */
|
|
136
|
+
return N ? /* @__PURE__ */ v(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
ref: G,
|
|
140
|
+
className: l(t.root, V && a && t.fullWidth, i?.root, O),
|
|
141
|
+
style: K,
|
|
142
|
+
children: [
|
|
143
|
+
V && /* @__PURE__ */ u("div", { ref: k, style: a ? { width: "100%" } : void 0, children: /* @__PURE__ */ v(
|
|
144
|
+
"button",
|
|
145
|
+
{
|
|
146
|
+
ref: b,
|
|
147
|
+
id: W,
|
|
148
|
+
type: "button",
|
|
149
|
+
className: l(
|
|
150
|
+
t.trigger,
|
|
151
|
+
n && t.triggerOpen,
|
|
152
|
+
q && t.triggerError,
|
|
153
|
+
a && t.fullWidth,
|
|
154
|
+
i?.trigger
|
|
155
|
+
),
|
|
156
|
+
onClick: F,
|
|
157
|
+
"aria-expanded": n,
|
|
158
|
+
"aria-haspopup": "menu",
|
|
159
|
+
"aria-controls": n ? I : void 0,
|
|
160
|
+
children: [
|
|
161
|
+
/* @__PURE__ */ u("span", { className: l(t.triggerLabel, Y && t.placeholder, i?.triggerLabel), children: X }),
|
|
162
|
+
/* @__PURE__ */ u("span", { className: l(t.chevron, i?.chevron), "aria-hidden": "true" })
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
) }),
|
|
166
|
+
n && U && typeof document < "u" && te(
|
|
167
|
+
C({
|
|
168
|
+
position: "fixed",
|
|
169
|
+
top: R?.top ?? o.y,
|
|
170
|
+
left: R?.left ?? o.x,
|
|
171
|
+
visibility: R ? void 0 : "hidden",
|
|
172
|
+
zIndex: "var(--crk-z-floating)"
|
|
173
|
+
}),
|
|
174
|
+
document.body
|
|
175
|
+
)
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
) : /* @__PURE__ */ v(
|
|
86
179
|
"div",
|
|
87
180
|
{
|
|
88
|
-
ref:
|
|
89
|
-
className:
|
|
90
|
-
style:
|
|
181
|
+
ref: G,
|
|
182
|
+
className: l(t.root, a && t.fullWidth, i?.root, O),
|
|
183
|
+
style: K,
|
|
91
184
|
children: [
|
|
92
|
-
/* @__PURE__ */
|
|
93
|
-
/* @__PURE__ */
|
|
185
|
+
/* @__PURE__ */ v("div", { ref: k, style: a ? { width: "100%" } : void 0, children: [
|
|
186
|
+
/* @__PURE__ */ v(
|
|
94
187
|
"button",
|
|
95
188
|
{
|
|
96
|
-
ref:
|
|
97
|
-
id:
|
|
189
|
+
ref: b,
|
|
190
|
+
id: W,
|
|
98
191
|
type: "button",
|
|
99
|
-
className:
|
|
192
|
+
className: l(
|
|
100
193
|
t.trigger,
|
|
101
|
-
|
|
194
|
+
n && t.triggerOpen,
|
|
102
195
|
q && t.triggerError,
|
|
103
196
|
a && t.fullWidth,
|
|
104
|
-
|
|
197
|
+
i?.trigger
|
|
105
198
|
),
|
|
106
|
-
onClick:
|
|
107
|
-
"aria-expanded":
|
|
199
|
+
onClick: F,
|
|
200
|
+
"aria-expanded": n,
|
|
108
201
|
"aria-haspopup": "menu",
|
|
109
|
-
"aria-controls":
|
|
202
|
+
"aria-controls": n ? I : void 0,
|
|
110
203
|
children: [
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
/* @__PURE__ */
|
|
204
|
+
/* @__PURE__ */ u("span", { className: l(t.triggerLabel, Y && t.placeholder, i?.triggerLabel), children: X }),
|
|
205
|
+
/* @__PURE__ */ u("span", { className: l(t.chevron, i?.chevron), "aria-hidden": "true" })
|
|
113
206
|
]
|
|
114
207
|
}
|
|
115
208
|
),
|
|
116
|
-
!
|
|
209
|
+
!w && C()
|
|
117
210
|
] }),
|
|
118
|
-
|
|
119
|
-
|
|
211
|
+
w && n && typeof document < "u" && te(
|
|
212
|
+
C({
|
|
120
213
|
position: "fixed",
|
|
121
|
-
top:
|
|
122
|
-
left:
|
|
214
|
+
top: p.top + 4,
|
|
215
|
+
left: L === "right" ? void 0 : p.left,
|
|
123
216
|
// clientWidth, not innerWidth: `right` on a fixed element is
|
|
124
217
|
// measured from the viewport edge inside the scrollbar, while
|
|
125
218
|
// innerWidth includes it — the menu would shift left by the
|
|
126
219
|
// scrollbar width whenever the page scrolls.
|
|
127
|
-
right:
|
|
128
|
-
minWidth:
|
|
220
|
+
right: L === "right" ? document.documentElement.clientWidth - (p.left + p.width) : void 0,
|
|
221
|
+
minWidth: p.width,
|
|
129
222
|
zIndex: "var(--crk-z-floating)"
|
|
130
223
|
}),
|
|
131
224
|
document.body
|
|
@@ -135,7 +228,7 @@ const Y = J(
|
|
|
135
228
|
);
|
|
136
229
|
}
|
|
137
230
|
);
|
|
138
|
-
|
|
231
|
+
we.displayName = "Dropdown";
|
|
139
232
|
export {
|
|
140
|
-
|
|
233
|
+
we as Dropdown
|
|
141
234
|
};
|
|
@@ -1,35 +1,53 @@
|
|
|
1
|
-
const e = "crk-root-an8Cf",
|
|
1
|
+
const e = "crk-root-an8Cf", t = "crk-fullWidth-S-uVk", r = "crk-trigger-LwPaD", c = "crk-triggerOpen-U4pa9", i = "crk-triggerLabel-QLITs", n = "crk-triggerError-3jlu1", o = "crk-placeholder-fWdch", l = "crk-chevron-jmDNe", m = "crk-menu-fxnKL", s = "crk-menuOpen-HF-Y1", a = "crk-alignLeft-buCDJ", g = "crk-alignRight-05P9w", k = "crk-item-f-Rhh", h = "crk-itemDisabled-L-d6i", d = "crk-itemSelected-Fwmuo", p = "crk-itemDanger-b1A4e", u = "crk-itemChecked-xY5Cf", b = "crk-itemCheck-IZYaJ", f = "crk-itemIcon-3Gh8c", D = "crk-itemLabel-YdjzN", L = "crk-itemDescription-eM-fw", C = "crk-itemShortcut-33qnD", S = "crk-separator-C0jdb", O = "crk-label-Rd7NT", I = {
|
|
2
2
|
root: e,
|
|
3
|
-
fullWidth:
|
|
4
|
-
trigger:
|
|
3
|
+
fullWidth: t,
|
|
4
|
+
trigger: r,
|
|
5
5
|
triggerOpen: c,
|
|
6
|
-
triggerLabel:
|
|
7
|
-
triggerError:
|
|
8
|
-
placeholder:
|
|
9
|
-
chevron:
|
|
10
|
-
menu:
|
|
6
|
+
triggerLabel: i,
|
|
7
|
+
triggerError: n,
|
|
8
|
+
placeholder: o,
|
|
9
|
+
chevron: l,
|
|
10
|
+
menu: m,
|
|
11
11
|
menuOpen: s,
|
|
12
12
|
alignLeft: a,
|
|
13
|
-
alignRight:
|
|
13
|
+
alignRight: g,
|
|
14
14
|
item: k,
|
|
15
|
-
itemDisabled:
|
|
16
|
-
itemSelected:
|
|
15
|
+
itemDisabled: h,
|
|
16
|
+
itemSelected: d,
|
|
17
|
+
itemDanger: p,
|
|
18
|
+
itemChecked: u,
|
|
19
|
+
itemCheck: b,
|
|
20
|
+
itemIcon: f,
|
|
21
|
+
itemLabel: D,
|
|
22
|
+
itemDescription: L,
|
|
23
|
+
itemShortcut: C,
|
|
24
|
+
separator: S,
|
|
25
|
+
label: O
|
|
17
26
|
};
|
|
18
27
|
export {
|
|
19
28
|
a as alignLeft,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
g as alignRight,
|
|
30
|
+
l as chevron,
|
|
31
|
+
I as default,
|
|
32
|
+
t as fullWidth,
|
|
24
33
|
k as item,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
b as itemCheck,
|
|
35
|
+
u as itemChecked,
|
|
36
|
+
p as itemDanger,
|
|
37
|
+
L as itemDescription,
|
|
38
|
+
h as itemDisabled,
|
|
39
|
+
f as itemIcon,
|
|
40
|
+
D as itemLabel,
|
|
41
|
+
d as itemSelected,
|
|
42
|
+
C as itemShortcut,
|
|
43
|
+
O as label,
|
|
44
|
+
m as menu,
|
|
28
45
|
s as menuOpen,
|
|
29
|
-
|
|
46
|
+
o as placeholder,
|
|
30
47
|
e as root,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
n as
|
|
48
|
+
S as separator,
|
|
49
|
+
r as trigger,
|
|
50
|
+
n as triggerError,
|
|
51
|
+
i as triggerLabel,
|
|
34
52
|
c as triggerOpen
|
|
35
53
|
};
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
import { ComponentPropsWithRef } from 'react';
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
import { DropdownClasses } from './Dropdown';
|
|
3
|
+
export type DropdownItemClasses = Partial<Pick<DropdownClasses, 'item' | 'itemIcon' | 'itemLabel' | 'itemDescription' | 'itemShortcut' | 'itemCheck'>>;
|
|
2
4
|
export interface DropdownItemProps extends ComponentPropsWithRef<'button'> {
|
|
3
5
|
/** Non-interactive when true. @default false */
|
|
4
6
|
disabled?: boolean;
|
|
7
|
+
/** Destructive action styling (danger text, danger-light hover). @default false */
|
|
8
|
+
danger?: boolean;
|
|
9
|
+
/** Leading icon slot (fixed width, `aria-hidden`). */
|
|
10
|
+
icon?: ReactNode;
|
|
11
|
+
/** Trailing shortcut hint, e.g. `<Kbd keys={['⌘', 'D']} />`. Hidden from the accessible name. */
|
|
12
|
+
shortcut?: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Makes the item checkable: renders `role="menuitemcheckbox"` with
|
|
15
|
+
* `aria-checked` and a leading check-mark slot that keeps alignment when
|
|
16
|
+
* unchecked. `undefined` = a plain action item.
|
|
17
|
+
*/
|
|
18
|
+
checked?: boolean;
|
|
19
|
+
/** Second, muted line under the label. */
|
|
20
|
+
description?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Close the menu after `onClick` (unless the click was `preventDefault()`ed).
|
|
23
|
+
* @default true for action items, false for checkable items
|
|
24
|
+
*/
|
|
25
|
+
closeOnSelect?: boolean;
|
|
26
|
+
/** Override class names on internal elements. */
|
|
27
|
+
classes?: DropdownItemClasses;
|
|
5
28
|
}
|
|
6
29
|
/**
|
|
7
30
|
* Action item rendered inside a `<Dropdown>` (menu mode).
|
|
8
|
-
* Renders as a `<button role="menuitem"
|
|
31
|
+
* Renders as a `<button role="menuitem">` (or `menuitemcheckbox` when
|
|
32
|
+
* `checked` is set); supports all native button props.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* <DropdownItem icon={<TrashIcon />} shortcut={<Kbd keys={['⌘', '⌫']} />} danger onClick={remove}>
|
|
36
|
+
* Delete
|
|
37
|
+
* </DropdownItem>
|
|
9
38
|
*/
|
|
10
39
|
export declare const DropdownItem: import('react').ForwardRefExoticComponent<Omit<DropdownItemProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import { jsxs as c, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as N, useContext as b } from "react";
|
|
3
|
+
import o from "clsx";
|
|
4
|
+
import e from "./Dropdown.module.scss.js";
|
|
5
|
+
import { DropdownMenuContext as w } from "./dropdownContext.js";
|
|
6
|
+
const I = N(
|
|
6
7
|
({
|
|
7
|
-
disabled:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
disabled: d = !1,
|
|
9
|
+
danger: u = !1,
|
|
10
|
+
icon: m,
|
|
11
|
+
shortcut: a,
|
|
12
|
+
checked: r,
|
|
13
|
+
description: l,
|
|
14
|
+
closeOnSelect: p,
|
|
15
|
+
classes: t,
|
|
16
|
+
className: h,
|
|
17
|
+
children: f,
|
|
18
|
+
onClick: k,
|
|
19
|
+
...v
|
|
20
|
+
}, x) => {
|
|
21
|
+
const C = b(w), n = r !== void 0, D = p ?? !n;
|
|
22
|
+
return /* @__PURE__ */ c(
|
|
23
|
+
"button",
|
|
24
|
+
{
|
|
25
|
+
ref: x,
|
|
26
|
+
type: "button",
|
|
27
|
+
role: n ? "menuitemcheckbox" : "menuitem",
|
|
28
|
+
"aria-checked": n ? r : void 0,
|
|
29
|
+
className: o(
|
|
30
|
+
e.item,
|
|
31
|
+
d && e.itemDisabled,
|
|
32
|
+
u && e.itemDanger,
|
|
33
|
+
n && r && e.itemChecked,
|
|
34
|
+
t?.item,
|
|
35
|
+
h
|
|
36
|
+
),
|
|
37
|
+
disabled: d,
|
|
38
|
+
onClick: (s) => {
|
|
39
|
+
k?.(s), D && !s.defaultPrevented && C?.close();
|
|
40
|
+
},
|
|
41
|
+
...v,
|
|
42
|
+
children: [
|
|
43
|
+
n && /* @__PURE__ */ i("span", { className: o(e.itemCheck, t?.itemCheck), "aria-hidden": "true", children: r && /* @__PURE__ */ i("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ i("path", { d: "M3 8.5l3 3 7-7" }) }) }),
|
|
44
|
+
m != null && /* @__PURE__ */ i("span", { className: o(e.itemIcon, t?.itemIcon), "aria-hidden": "true", children: m }),
|
|
45
|
+
/* @__PURE__ */ c("span", { className: o(e.itemLabel, t?.itemLabel), children: [
|
|
46
|
+
f,
|
|
47
|
+
l != null && /* @__PURE__ */ i("span", { className: o(e.itemDescription, t?.itemDescription), children: l })
|
|
48
|
+
] }),
|
|
49
|
+
a != null && /* @__PURE__ */ i("span", { className: o(e.itemShortcut, t?.itemShortcut), "aria-hidden": "true", children: a })
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
27
54
|
);
|
|
28
|
-
|
|
55
|
+
I.displayName = "DropdownItem";
|
|
29
56
|
export {
|
|
30
|
-
|
|
57
|
+
I as DropdownItem
|
|
31
58
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from 'react';
|
|
2
|
+
export type DropdownLabelProps = ComponentPropsWithRef<'div'>;
|
|
3
|
+
/**
|
|
4
|
+
* Non-interactive section heading inside a `<Dropdown>` menu
|
|
5
|
+
* (small, uppercase, muted). Skipped by keyboard navigation.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <DropdownLabel>View</DropdownLabel>
|
|
9
|
+
* <DropdownItem checked={grid} onClick={toggleGrid}>Grid</DropdownItem>
|
|
10
|
+
*/
|
|
11
|
+
export declare const DropdownLabel: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as l } from "react";
|
|
3
|
+
import p from "clsx";
|
|
4
|
+
import s from "./Dropdown.module.scss.js";
|
|
5
|
+
const t = l(
|
|
6
|
+
({ className: o, children: r, ...e }, m) => /* @__PURE__ */ a("div", { ref: m, role: "presentation", className: p(s.label, o), ...e, children: r })
|
|
7
|
+
);
|
|
8
|
+
t.displayName = "DropdownLabel";
|
|
9
|
+
export {
|
|
10
|
+
t as DropdownLabel
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from 'react';
|
|
2
|
+
export type DropdownSeparatorProps = ComponentPropsWithRef<'div'>;
|
|
3
|
+
/**
|
|
4
|
+
* Hairline between groups of items inside a `<Dropdown>` menu.
|
|
5
|
+
* Skipped by keyboard navigation.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <DropdownItem>Rename</DropdownItem>
|
|
9
|
+
* <DropdownSeparator />
|
|
10
|
+
* <DropdownItem danger>Delete</DropdownItem>
|
|
11
|
+
*/
|
|
12
|
+
export declare const DropdownSeparator: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as t } from "react";
|
|
3
|
+
import e from "clsx";
|
|
4
|
+
import m from "./Dropdown.module.scss.js";
|
|
5
|
+
const s = t(
|
|
6
|
+
({ className: r, ...o }, a) => /* @__PURE__ */ p("div", { ref: a, role: "separator", className: e(m.separator, r), ...o })
|
|
7
|
+
);
|
|
8
|
+
s.displayName = "DropdownSeparator";
|
|
9
|
+
export {
|
|
10
|
+
s as DropdownSeparator
|
|
11
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface DropdownMenuContextValue {
|
|
2
|
+
/** Close the enclosing menu (after an item was activated). */
|
|
3
|
+
close: () => void;
|
|
4
|
+
}
|
|
5
|
+
/** Provided by `Dropdown` around its menu so items can close it on activation. */
|
|
6
|
+
export declare const DropdownMenuContext: import('react').Context<DropdownMenuContextValue | null>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export { Dropdown } from './Dropdown';
|
|
2
|
-
export type { DropdownProps, DropdownClasses, DropdownOption } from './Dropdown';
|
|
2
|
+
export type { DropdownProps, DropdownClasses, DropdownOption, DropdownAnchor } from './Dropdown';
|
|
3
3
|
export { DropdownItem } from './DropdownItem';
|
|
4
|
-
export type { DropdownItemProps } from './DropdownItem';
|
|
4
|
+
export type { DropdownItemProps, DropdownItemClasses } from './DropdownItem';
|
|
5
|
+
export { DropdownSeparator } from './DropdownSeparator';
|
|
6
|
+
export type { DropdownSeparatorProps } from './DropdownSeparator';
|
|
7
|
+
export { DropdownLabel } from './DropdownLabel';
|
|
8
|
+
export type { DropdownLabelProps } from './DropdownLabel';
|
|
9
|
+
export { useContextMenu } from './useContextMenu';
|
|
10
|
+
export type { UseContextMenuResult, ContextMenuAnchor } from './useContextMenu';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MouseEvent as ReactMouseEvent } from 'react';
|
|
2
|
+
export interface ContextMenuAnchor {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UseContextMenuResult {
|
|
7
|
+
/** Viewport point to pass as `Dropdown`'s `anchor`. */
|
|
8
|
+
anchor: ContextMenuAnchor | null;
|
|
9
|
+
/** Pass as `Dropdown`'s `open`. */
|
|
10
|
+
open: boolean;
|
|
11
|
+
/** Pass as `Dropdown`'s `onOpenChange`. */
|
|
12
|
+
onOpenChange: (open: boolean) => void;
|
|
13
|
+
/** Attach to the element's `onContextMenu`: prevents the native menu and opens at the pointer. */
|
|
14
|
+
onContextMenu: (e: ReactMouseEvent) => void;
|
|
15
|
+
/** Open programmatically at a viewport point. */
|
|
16
|
+
openAt: (point: ContextMenuAnchor) => void;
|
|
17
|
+
/** Close the menu. */
|
|
18
|
+
close: () => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* State helper for a right-click menu built on `<Dropdown anchor>`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const menu = useContextMenu();
|
|
26
|
+
* <div onContextMenu={menu.onContextMenu}>Right-click me</div>
|
|
27
|
+
* <Dropdown anchor={menu.anchor} open={menu.open} onOpenChange={menu.onOpenChange}>
|
|
28
|
+
* <DropdownItem onClick={rename}>Rename</DropdownItem>
|
|
29
|
+
* </Dropdown>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useContextMenu(): UseContextMenuResult;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useState as a, useCallback as t, useMemo as f } from "react";
|
|
2
|
+
function x() {
|
|
3
|
+
const [s, p] = a(null), [c, o] = a(!1), n = t((e) => {
|
|
4
|
+
p(e), o(!0);
|
|
5
|
+
}, []), u = t(
|
|
6
|
+
(e) => {
|
|
7
|
+
e.preventDefault(), n({ x: e.clientX, y: e.clientY });
|
|
8
|
+
},
|
|
9
|
+
[n]
|
|
10
|
+
), l = t(() => o(!1), []), r = t((e) => o(e), []);
|
|
11
|
+
return f(
|
|
12
|
+
() => ({ anchor: s, open: c, onOpenChange: r, onContextMenu: u, openAt: n, close: l }),
|
|
13
|
+
[s, c, r, u, n, l]
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
x as useContextMenu
|
|
18
|
+
};
|