@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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useState as P, useRef as z, useCallback as f, useEffect as H } from "react";
|
|
2
|
+
const w = (m) => typeof m == "function" ? m() : m ?? 1 / 0;
|
|
3
|
+
function V(m = {}) {
|
|
4
|
+
const {
|
|
5
|
+
size: y,
|
|
6
|
+
defaultSize: R = 0,
|
|
7
|
+
min: b = 0,
|
|
8
|
+
max: E,
|
|
9
|
+
axis: t = "x",
|
|
10
|
+
invert: p = !1,
|
|
11
|
+
step: M = 16,
|
|
12
|
+
onResize: k,
|
|
13
|
+
onResizeStart: D,
|
|
14
|
+
onResizeEnd: g,
|
|
15
|
+
disabled: c = !1
|
|
16
|
+
} = m, [F, K] = P(R), [S, A] = P(!1), v = y ?? F, u = z(v);
|
|
17
|
+
u.current = v;
|
|
18
|
+
const i = z({ onResize: k, onResizeStart: D, onResizeEnd: g });
|
|
19
|
+
i.current = { onResize: k, onResizeStart: D, onResizeEnd: g };
|
|
20
|
+
const a = z({ min: b, max: E });
|
|
21
|
+
a.current = { min: b, max: E };
|
|
22
|
+
const C = f((e, r = w(a.current.max)) => {
|
|
23
|
+
const n = a.current.min;
|
|
24
|
+
return Math.min(Math.max(e, n), Math.max(n, r));
|
|
25
|
+
}, []), s = f(
|
|
26
|
+
(e, r) => {
|
|
27
|
+
const n = C(e, r);
|
|
28
|
+
return y === void 0 && K(n), u.current = n, i.current.onResize?.(n, e), n;
|
|
29
|
+
},
|
|
30
|
+
[C, y]
|
|
31
|
+
), U = f((e) => {
|
|
32
|
+
s(e);
|
|
33
|
+
}, [s]), I = f(() => {
|
|
34
|
+
if (c) return;
|
|
35
|
+
i.current.onResizeStart?.();
|
|
36
|
+
const e = s(R);
|
|
37
|
+
i.current.onResizeEnd?.(e);
|
|
38
|
+
}, [s, R, c]), h = z(null);
|
|
39
|
+
H(() => {
|
|
40
|
+
if (!S) return;
|
|
41
|
+
const e = document.body, r = e.style.userSelect, n = e.style.cursor;
|
|
42
|
+
e.style.userSelect = "none", e.style.cursor = t === "x" ? "col-resize" : "row-resize";
|
|
43
|
+
const o = (x) => {
|
|
44
|
+
const d = h.current;
|
|
45
|
+
if (!d) return;
|
|
46
|
+
let L = (t === "x" ? x.clientX : x.clientY) - d.start;
|
|
47
|
+
p && (L = -L), s(d.size + L, d.max);
|
|
48
|
+
}, l = () => {
|
|
49
|
+
h.current = null, A(!1), i.current.onResizeEnd?.(u.current);
|
|
50
|
+
};
|
|
51
|
+
return window.addEventListener("pointermove", o), window.addEventListener("pointerup", l), window.addEventListener("pointercancel", l), () => {
|
|
52
|
+
window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", l), window.removeEventListener("pointercancel", l), e.style.userSelect = r, e.style.cursor = n;
|
|
53
|
+
};
|
|
54
|
+
}, [S, t, p, s]);
|
|
55
|
+
const X = f(
|
|
56
|
+
(e) => {
|
|
57
|
+
if (!(c || e.button > 0)) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
try {
|
|
60
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
h.current = {
|
|
64
|
+
start: t === "x" ? e.clientX : e.clientY,
|
|
65
|
+
size: u.current,
|
|
66
|
+
max: w(a.current.max)
|
|
67
|
+
}, i.current.onResizeStart?.(), A(!0);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[t, c]
|
|
71
|
+
), Y = f(
|
|
72
|
+
(e) => {
|
|
73
|
+
if (c) return;
|
|
74
|
+
const r = w(a.current.max), n = M * (e.shiftKey ? 10 : 1);
|
|
75
|
+
let o = null;
|
|
76
|
+
const l = t === "x" ? "ArrowLeft" : "ArrowUp", x = t === "x" ? "ArrowRight" : "ArrowDown";
|
|
77
|
+
if (e.key === l ? o = u.current + (p ? n : -n) : e.key === x ? o = u.current + (p ? -n : n) : e.key === "Home" ? o = a.current.min : e.key === "End" && (o = Number.isFinite(r) ? r : u.current), o === null) return;
|
|
78
|
+
e.preventDefault(), i.current.onResizeStart?.();
|
|
79
|
+
const d = s(o, r);
|
|
80
|
+
i.current.onResizeEnd?.(d);
|
|
81
|
+
},
|
|
82
|
+
[s, t, c, p, M]
|
|
83
|
+
), N = w(E);
|
|
84
|
+
return {
|
|
85
|
+
size: v,
|
|
86
|
+
setSize: U,
|
|
87
|
+
isResizing: S,
|
|
88
|
+
reset: I,
|
|
89
|
+
handleProps: {
|
|
90
|
+
onPointerDown: X,
|
|
91
|
+
onKeyDown: Y,
|
|
92
|
+
onDoubleClick: I,
|
|
93
|
+
role: "separator",
|
|
94
|
+
"aria-orientation": t === "x" ? "vertical" : "horizontal",
|
|
95
|
+
"aria-valuenow": Math.round(v),
|
|
96
|
+
"aria-valuemin": b,
|
|
97
|
+
"aria-valuemax": Number.isFinite(N) ? Math.round(N) : void 0,
|
|
98
|
+
"aria-disabled": c || void 0,
|
|
99
|
+
tabIndex: 0
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
V as useResizable
|
|
105
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type Theme = 'light' | 'dark' | 'system';
|
|
2
|
+
export type ResolvedTheme = 'light' | 'dark';
|
|
3
|
+
export interface UseThemeOptions {
|
|
4
|
+
/** localStorage key. Must match the pre-paint script's. @default 'crk-theme' */
|
|
5
|
+
storageKey?: string;
|
|
6
|
+
/** Attribute written on `<html>`. @default 'data-theme' */
|
|
7
|
+
attribute?: string;
|
|
8
|
+
/** Theme used when nothing is stored. @default 'system' */
|
|
9
|
+
defaultTheme?: Theme;
|
|
10
|
+
}
|
|
11
|
+
export interface UseThemeResult {
|
|
12
|
+
/** The chosen mode. */
|
|
13
|
+
theme: Theme;
|
|
14
|
+
/** What is actually shown: `system` resolved through `prefers-color-scheme`. */
|
|
15
|
+
resolved: ResolvedTheme;
|
|
16
|
+
setTheme: (theme: Theme) => void;
|
|
17
|
+
/** light → dark → system → light. */
|
|
18
|
+
toggle: () => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Light / dark / system theme switch for the `--crk-*` tokens.
|
|
22
|
+
*
|
|
23
|
+
* Persists the choice (localStorage, cross-tab), writes `data-theme` on
|
|
24
|
+
* `<html>` (`light` / `dark` / `system` — the stylesheet follows the OS
|
|
25
|
+
* preference only for `system`), and reports the `resolved` scheme. Every hook instance stays
|
|
26
|
+
* in sync. Pair with `THEME_INIT_SCRIPT` in `<head>` to avoid a flash of the
|
|
27
|
+
* wrong theme on load.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const { theme, resolved, setTheme, toggle } = useTheme();
|
|
31
|
+
* <button onClick={toggle}>{resolved === 'dark' ? '🌙' : '☀️'}</button>
|
|
32
|
+
*/
|
|
33
|
+
export declare function useTheme(options?: UseThemeOptions): UseThemeResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect as p, useCallback as i } from "react";
|
|
2
|
+
import { usePersistedState as y } from "./usePersistedState.js";
|
|
3
|
+
import { useMediaQuery as g } from "./useMediaQuery.js";
|
|
4
|
+
const s = ["light", "dark", "system"];
|
|
5
|
+
function a(r, o) {
|
|
6
|
+
typeof document > "u" || document.documentElement.setAttribute(r, o);
|
|
7
|
+
}
|
|
8
|
+
function T(r = {}) {
|
|
9
|
+
const { storageKey: o = "crk-theme", attribute: t = "data-theme", defaultTheme: m = "system" } = r, [c, u] = y(o, m), e = s.includes(c) ? c : m, f = g("(prefers-color-scheme: dark)"), l = e === "system" ? f ? "dark" : "light" : e;
|
|
10
|
+
p(() => {
|
|
11
|
+
a(t, e);
|
|
12
|
+
}, [t, e]);
|
|
13
|
+
const n = i(
|
|
14
|
+
(d) => {
|
|
15
|
+
u(d), a(t, d);
|
|
16
|
+
},
|
|
17
|
+
[u, t]
|
|
18
|
+
), h = i(() => {
|
|
19
|
+
n(s[(s.indexOf(e) + 1) % s.length]);
|
|
20
|
+
}, [e, n]);
|
|
21
|
+
return { theme: e, resolved: l, setTheme: n, toggle: h };
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
T as useTheme
|
|
25
|
+
};
|