@okjt/dashboard 0.7.0 → 0.8.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/dist/TwoPaneDialog.js +67 -0
- package/dist/TwoPaneForm.js +154 -0
- package/dist/index.js +7 -0
- package/dist/toolbar-glass.css +68 -0
- package/dist/useFilteredItems.js +28 -10
- package/dist/useGlassToolbar.js +67 -0
- package/package.json +6 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef } from "react";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
|
+
function TwoPaneDialog({ open, title, subtitle, sections, active, onSelect, onClose, footer, children }) {
|
|
5
|
+
const titleId = useId();
|
|
6
|
+
const panelRef = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!open) return void 0;
|
|
9
|
+
const onKey = (e) => {
|
|
10
|
+
if (e.key === "Escape") onClose();
|
|
11
|
+
};
|
|
12
|
+
document.addEventListener("keydown", onKey);
|
|
13
|
+
const previous = document.activeElement;
|
|
14
|
+
panelRef.current?.focus();
|
|
15
|
+
return () => {
|
|
16
|
+
document.removeEventListener("keydown", onKey);
|
|
17
|
+
previous?.focus?.();
|
|
18
|
+
};
|
|
19
|
+
}, [open, onClose]);
|
|
20
|
+
if (!open) return null;
|
|
21
|
+
return /* @__PURE__ */ jsx("div", { className: "fixed inset-0 z-[150] flex items-stretch justify-center bg-ink/40 sm:items-center sm:p-6", children: /* @__PURE__ */ jsxs(
|
|
22
|
+
"div",
|
|
23
|
+
{
|
|
24
|
+
ref: panelRef,
|
|
25
|
+
tabIndex: -1,
|
|
26
|
+
role: "dialog",
|
|
27
|
+
"aria-modal": "true",
|
|
28
|
+
"aria-labelledby": titleId,
|
|
29
|
+
className: "flex h-full w-full flex-col overflow-hidden bg-surface shadow-xl outline-none sm:h-[min(44rem,90vh)] sm:max-w-5xl sm:rounded-2xl",
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ jsxs("header", { className: "flex items-start justify-between gap-4 border-b border-line px-5 py-4", children: [
|
|
32
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
33
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, className: "truncate !font-sans !text-lg !font-semibold !text-ink", children: title }),
|
|
34
|
+
subtitle && /* @__PURE__ */ jsx("p", { className: "mt-0.5 text-sm text-tone-500", children: subtitle })
|
|
35
|
+
] }),
|
|
36
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: onClose, className: "rounded-full p-2 text-tone-500 hover:bg-tint", "aria-label": "Close", children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })
|
|
37
|
+
] }),
|
|
38
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-1 flex-col sm:flex-row", children: [
|
|
39
|
+
/* @__PURE__ */ jsx("nav", { "aria-label": "Sections", className: "shrink-0 border-b border-line bg-paper sm:w-56 sm:border-b-0 sm:border-r", children: /* @__PURE__ */ jsx("ol", { className: "flex gap-1 overflow-x-auto p-2 sm:flex-col sm:p-3", children: sections.map((s, i) => {
|
|
40
|
+
const on = s.id === active;
|
|
41
|
+
return /* @__PURE__ */ jsx("li", { className: "shrink-0", children: /* @__PURE__ */ jsxs(
|
|
42
|
+
"button",
|
|
43
|
+
{
|
|
44
|
+
type: "button",
|
|
45
|
+
onClick: () => onSelect(s.id),
|
|
46
|
+
"aria-current": on ? "step" : void 0,
|
|
47
|
+
className: `flex w-full items-start gap-3 rounded-xl px-3 py-2 text-left transition-colors ${on ? "bg-ink text-white" : "text-body hover:bg-tint"}`,
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsx("span", { className: `mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-full text-[11px] font-semibold ${on ? "bg-white/20" : s.done ? "bg-positive text-white" : "bg-line text-soft"}`, children: s.done && !on ? "\u2713" : i + 1 }),
|
|
50
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0", children: [
|
|
51
|
+
/* @__PURE__ */ jsx("span", { className: "block text-sm font-semibold", children: s.label }),
|
|
52
|
+
s.hint && /* @__PURE__ */ jsx("span", { className: `hidden text-xs sm:block ${on ? "text-white/70" : "text-tone-500"}`, children: s.hint })
|
|
53
|
+
] })
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
) }, s.id);
|
|
57
|
+
}) }) }),
|
|
58
|
+
/* @__PURE__ */ jsx("section", { className: "min-h-0 flex-1 overflow-y-auto p-5", children })
|
|
59
|
+
] }),
|
|
60
|
+
footer && /* @__PURE__ */ jsx("footer", { className: "flex flex-wrap items-center justify-end gap-2 border-t border-line px-5 py-3", children: footer })
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
) });
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
TwoPaneDialog as default
|
|
67
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ArrowLeft, ArrowRight, Save } from "lucide-react";
|
|
4
|
+
import { Button } from "@okjt/ui";
|
|
5
|
+
import TwoPaneDialog from "./TwoPaneDialog.js";
|
|
6
|
+
const CHECK = "check";
|
|
7
|
+
function TwoPaneForm({
|
|
8
|
+
open,
|
|
9
|
+
title,
|
|
10
|
+
subtitle,
|
|
11
|
+
sections,
|
|
12
|
+
initial,
|
|
13
|
+
validate = () => ({}),
|
|
14
|
+
onClose,
|
|
15
|
+
onSubmit,
|
|
16
|
+
submitLabel = "Save",
|
|
17
|
+
draftKey = null
|
|
18
|
+
}) {
|
|
19
|
+
const [values, setValues] = useState(initial);
|
|
20
|
+
const [touched, setTouched] = useState({});
|
|
21
|
+
const [active, setActive] = useState(sections[0]?.id);
|
|
22
|
+
const [saving, setSaving] = useState(false);
|
|
23
|
+
const [restored, setRestored] = useState(false);
|
|
24
|
+
const [visited, setVisited] = useState(() => /* @__PURE__ */ new Set());
|
|
25
|
+
const opened = useRef(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!open) {
|
|
28
|
+
opened.current = false;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (opened.current) return;
|
|
32
|
+
opened.current = true;
|
|
33
|
+
let draft = null;
|
|
34
|
+
try {
|
|
35
|
+
draft = draftKey ? JSON.parse(localStorage.getItem(`draft:${draftKey}`) || "null") : null;
|
|
36
|
+
} catch {
|
|
37
|
+
draft = null;
|
|
38
|
+
}
|
|
39
|
+
setValues(draft ? { ...initial, ...draft } : initial);
|
|
40
|
+
setRestored(!!draft);
|
|
41
|
+
setTouched({});
|
|
42
|
+
setVisited(/* @__PURE__ */ new Set());
|
|
43
|
+
setActive(sections[0]?.id);
|
|
44
|
+
}, [open]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!open || !draftKey || !opened.current) return;
|
|
47
|
+
try {
|
|
48
|
+
localStorage.setItem(`draft:${draftKey}`, JSON.stringify(values));
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}, [values, open, draftKey]);
|
|
52
|
+
const errors = useMemo(() => Object.fromEntries(Object.entries(validate(values) || {}).filter(([, m]) => m)), [values, validate]);
|
|
53
|
+
const sectionOf = (name) => sections.find((s) => s.fields?.includes(name))?.id;
|
|
54
|
+
const sectionErrors = (s) => (s.fields || []).filter((f) => errors[f]);
|
|
55
|
+
if (!open) return null;
|
|
56
|
+
const clearDraft = () => {
|
|
57
|
+
if (draftKey) try {
|
|
58
|
+
localStorage.removeItem(`draft:${draftKey}`);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const set = (name) => (e) => setValues((v) => ({ ...v, [name]: e?.target ? e.target.type === "checkbox" ? e.target.checked : e.target.value : e }));
|
|
63
|
+
const field = (name) => ({ name, value: values[name] ?? "", onChange: set(name) });
|
|
64
|
+
const error = (name) => touched[name] ? errors[name] : null;
|
|
65
|
+
const onBlur = (e) => {
|
|
66
|
+
if (e.target.name) setTouched((t) => ({ ...t, [e.target.name]: true }));
|
|
67
|
+
};
|
|
68
|
+
const go = (id) => {
|
|
69
|
+
setVisited((v) => new Set(v).add(active));
|
|
70
|
+
setActive(id);
|
|
71
|
+
};
|
|
72
|
+
const all = [...sections, { id: CHECK, label: "Check details", hint: Object.keys(errors).length ? `${Object.keys(errors).length} to fix` : "Ready to save" }];
|
|
73
|
+
const index = all.findIndex((s) => s.id === active);
|
|
74
|
+
const current = sections.find((s) => s.id === active);
|
|
75
|
+
const submit = async () => {
|
|
76
|
+
if (Object.keys(errors).length) {
|
|
77
|
+
setTouched(Object.fromEntries(Object.keys(errors).map((k) => [k, true])));
|
|
78
|
+
go(CHECK);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setSaving(true);
|
|
82
|
+
try {
|
|
83
|
+
await onSubmit(values);
|
|
84
|
+
clearDraft();
|
|
85
|
+
onClose();
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
setSaving(false);
|
|
89
|
+
};
|
|
90
|
+
const discard = () => {
|
|
91
|
+
clearDraft();
|
|
92
|
+
onClose();
|
|
93
|
+
};
|
|
94
|
+
return /* @__PURE__ */ jsx(
|
|
95
|
+
TwoPaneDialog,
|
|
96
|
+
{
|
|
97
|
+
open: true,
|
|
98
|
+
title,
|
|
99
|
+
subtitle: restored ? "We kept what you\u2019d typed last time." : subtitle,
|
|
100
|
+
sections: all.map((s) => ({
|
|
101
|
+
id: s.id,
|
|
102
|
+
label: s.label,
|
|
103
|
+
hint: s.id === CHECK ? s.hint : sectionErrors(s).length && sectionErrors(s).some((f) => touched[f]) ? "Something to fix" : s.hint,
|
|
104
|
+
done: s.id !== CHECK && visited.has(s.id) && !sectionErrors(s).length
|
|
105
|
+
})),
|
|
106
|
+
active,
|
|
107
|
+
onSelect: go,
|
|
108
|
+
onClose,
|
|
109
|
+
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
110
|
+
draftKey && restored && /* @__PURE__ */ jsx(Button, { onClick: discard, children: "Discard draft" }),
|
|
111
|
+
index > 0 && /* @__PURE__ */ jsx(Button, { icon: ArrowLeft, onClick: () => go(all[index - 1].id), children: "Back" }),
|
|
112
|
+
active !== CHECK && /* @__PURE__ */ jsx(Button, { icon: ArrowRight, onClick: () => go(all[index + 1].id), children: "Next" }),
|
|
113
|
+
/* @__PURE__ */ jsx(Button, { edit: true, variant: "secondary", icon: Save, loading: saving, onClick: submit, children: submitLabel })
|
|
114
|
+
] }),
|
|
115
|
+
children: /* @__PURE__ */ jsxs("form", { onBlur, onSubmit: (e) => {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
submit();
|
|
118
|
+
}, noValidate: true, children: [
|
|
119
|
+
current && /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
120
|
+
current.intro && /* @__PURE__ */ jsx("p", { className: "text-sm text-tone-500", children: current.intro }),
|
|
121
|
+
current.render({ values, set, field, error, setValues })
|
|
122
|
+
] }),
|
|
123
|
+
active === CHECK && /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
|
|
124
|
+
Object.keys(errors).length > 0 && /* @__PURE__ */ jsxs("div", { role: "alert", className: "rounded-xl border border-amber-200 bg-amber-50 p-3 text-sm text-amber-900", children: [
|
|
125
|
+
/* @__PURE__ */ jsx("p", { className: "font-semibold", children: "Before saving:" }),
|
|
126
|
+
/* @__PURE__ */ jsx("ul", { className: "mt-1 space-y-1", children: Object.entries(errors).map(([name, message]) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", { type: "button", className: "underline", onClick: () => go(sectionOf(name) || sections[0].id), children: message }) }, name)) })
|
|
127
|
+
] }),
|
|
128
|
+
sections.filter((s) => s.summary).map((s) => {
|
|
129
|
+
const rows = s.summary(values).filter(([, v]) => v !== null && v !== void 0 && v !== "");
|
|
130
|
+
return /* @__PURE__ */ jsxs("section", { children: [
|
|
131
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
132
|
+
/* @__PURE__ */ jsx("h3", { className: "font-semibold text-ink", children: s.label }),
|
|
133
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "text-sm text-accent hover:underline", onClick: () => go(s.id), children: "Change" })
|
|
134
|
+
] }),
|
|
135
|
+
rows.length ? /* @__PURE__ */ jsx("dl", { className: "mt-1 grid gap-x-4 gap-y-1 text-sm sm:grid-cols-[10rem_1fr]", children: rows.map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "contents", children: [
|
|
136
|
+
/* @__PURE__ */ jsx("dt", { className: "text-tone-500", children: label }),
|
|
137
|
+
/* @__PURE__ */ jsx("dd", { className: "text-body", children: value })
|
|
138
|
+
] }, label)) }) : /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-tone-500", children: "Nothing filled in." })
|
|
139
|
+
] }, s.id);
|
|
140
|
+
})
|
|
141
|
+
] }),
|
|
142
|
+
/* @__PURE__ */ jsx("button", { type: "submit", className: "hidden", "aria-hidden": "true", tabIndex: -1 })
|
|
143
|
+
] })
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
function FieldError({ message }) {
|
|
148
|
+
if (!message) return null;
|
|
149
|
+
return /* @__PURE__ */ jsx("p", { role: "alert", className: "-mt-2 text-xs text-amber-800", children: message });
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
FieldError,
|
|
153
|
+
TwoPaneForm as default
|
|
154
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,9 @@ import { default as default44 } from "./ConfirmPasswordPage.js";
|
|
|
61
61
|
import { default as default45 } from "./TwoFactorForm.js";
|
|
62
62
|
import { default as default46 } from "./AcceptInvitePage.js";
|
|
63
63
|
import { default as default47 } from "./AccountMenu.js";
|
|
64
|
+
import { default as default48 } from "./TwoPaneDialog.js";
|
|
65
|
+
import { default as default49, FieldError } from "./TwoPaneForm.js";
|
|
66
|
+
import { default as default50 } from "./useGlassToolbar.js";
|
|
64
67
|
export {
|
|
65
68
|
default46 as AcceptInvitePage,
|
|
66
69
|
default47 as AccountMenu,
|
|
@@ -100,6 +103,7 @@ export {
|
|
|
100
103
|
default15 as DeleteButton,
|
|
101
104
|
default14 as EditableFieldset,
|
|
102
105
|
default17 as EmptyState,
|
|
106
|
+
FieldError,
|
|
103
107
|
default42 as ForgotPasswordPage,
|
|
104
108
|
default36 as GoogleButton,
|
|
105
109
|
default40 as GoogleCallbackPage,
|
|
@@ -116,6 +120,8 @@ export {
|
|
|
116
120
|
default5 as StatCard,
|
|
117
121
|
default16 as ToggleButton,
|
|
118
122
|
default45 as TwoFactorForm,
|
|
123
|
+
default48 as TwoPaneDialog,
|
|
124
|
+
default49 as TwoPaneForm,
|
|
119
125
|
default20 as UnsavedChangesStatus,
|
|
120
126
|
default41 as VerifyEmailPage,
|
|
121
127
|
default30 as VersionHistoryDrawer,
|
|
@@ -141,6 +147,7 @@ export {
|
|
|
141
147
|
default23 as useCrudHandlers,
|
|
142
148
|
useDashboard,
|
|
143
149
|
default25 as useFilteredItems,
|
|
150
|
+
default50 as useGlassToolbar,
|
|
144
151
|
useGuardedNavigate,
|
|
145
152
|
useHasUnsavedChanges,
|
|
146
153
|
useModules,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @okjt/dashboard/toolbar-glass.css: on phones, the floating toolbar becomes
|
|
3
|
+
* a glass bar at the bottom, lifted from Naoa. Import it once to turn it on:
|
|
4
|
+
*
|
|
5
|
+
* import '@okjt/dashboard/toolbar-glass.css';
|
|
6
|
+
*
|
|
7
|
+
* and call useGlassToolbar() in the dashboard, which tucks the bar away while
|
|
8
|
+
* the page scrolls down and switches it to solid on a device that drops
|
|
9
|
+
* frames with the blur on (html.toolbar-tucked, html.toolbar-solid). Solid
|
|
10
|
+
* too when the person asks for less transparency or the browser can't blur.
|
|
11
|
+
*
|
|
12
|
+
* Colours (defaults are Naoa's warm white; keep text contrast AA over your
|
|
13
|
+
* darkest content):
|
|
14
|
+
* --okjt-toolbar-glass-bg the glass rgba(255, 249, 245, 0.88)
|
|
15
|
+
* --okjt-toolbar-solid-bg the solid fallback #FFF9F5
|
|
16
|
+
* --okjt-toolbar-glass-border rgba(255, 255, 255, 0.6)
|
|
17
|
+
* --okjt-toolbar-glass-shadow 0 10px 30px rgba(31, 24, 19, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.7)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/* Phones: the toolbar packs its controls tighter, so it covers less of the
|
|
21
|
+
page. Menus that open from it keep their normal sizes. */
|
|
22
|
+
@media (max-width: 639.98px) {
|
|
23
|
+
.admin-floating-toolbar :is(button, select):not(:where([class*="absolute"] *)) {
|
|
24
|
+
padding: 0.5rem 0.6rem;
|
|
25
|
+
min-height: 2.25rem;
|
|
26
|
+
font-size: 0.75rem;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@media (max-width: 639.98px) {
|
|
31
|
+
.admin-theme .admin-floating-toolbar {
|
|
32
|
+
background: var(--okjt-toolbar-glass-bg, rgba(255, 249, 245, 0.88)) !important;
|
|
33
|
+
-webkit-backdrop-filter: blur(18px) saturate(170%);
|
|
34
|
+
backdrop-filter: blur(18px) saturate(170%);
|
|
35
|
+
border: 1px solid var(--okjt-toolbar-glass-border, rgba(255, 255, 255, 0.6));
|
|
36
|
+
box-shadow: var(--okjt-toolbar-glass-shadow, 0 10px 30px rgba(31, 24, 19, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.7)) !important;
|
|
37
|
+
border-radius: 1.5rem;
|
|
38
|
+
}
|
|
39
|
+
.admin-theme .admin-floating-toolbar :is(button, select) { min-height: 2.75rem; } /* 44px touch targets */
|
|
40
|
+
.admin-theme .admin-floating-toolbar [class*="bottom-full"] button { min-height: 2.75rem; font-size: 0.875rem; }
|
|
41
|
+
/* The wrapper the kit positions (its first child is the bar). `translate`,
|
|
42
|
+
not `transform`: framer-motion owns the wrapper's transform. */
|
|
43
|
+
.admin-theme div:has(> .admin-floating-toolbar) {
|
|
44
|
+
transition: translate 420ms cubic-bezier(0.34, 1.4, 0.64, 1), opacity 240ms ease;
|
|
45
|
+
}
|
|
46
|
+
html.toolbar-tucked div:has(> .admin-floating-toolbar) {
|
|
47
|
+
translate: -50% calc(100% + 1.5rem) !important;
|
|
48
|
+
opacity: 0 !important; /* framer-motion sets an inline opacity */
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
}
|
|
51
|
+
html.toolbar-solid .admin-floating-toolbar {
|
|
52
|
+
background: var(--okjt-toolbar-solid-bg, #FFF9F5) !important;
|
|
53
|
+
-webkit-backdrop-filter: none;
|
|
54
|
+
backdrop-filter: none;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
@media (max-width: 639.98px) and (prefers-reduced-transparency: reduce) {
|
|
58
|
+
.admin-theme .admin-floating-toolbar {
|
|
59
|
+
background: var(--okjt-toolbar-solid-bg, #FFF9F5) !important;
|
|
60
|
+
-webkit-backdrop-filter: none;
|
|
61
|
+
backdrop-filter: none;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
|
|
65
|
+
.admin-theme .admin-floating-toolbar { background: var(--okjt-toolbar-solid-bg, #FFF9F5) !important; }
|
|
66
|
+
}
|
|
67
|
+
/* Reduced motion: the kit's MotionConfig stops the springs; make the tuck
|
|
68
|
+
instant in your own reduced-motion rule if you have one. */
|
package/dist/useFilteredItems.js
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
function useFilteredItems(items,
|
|
2
|
+
function useFilteredItems(items, queryOrOptions, legacyFilterFn) {
|
|
3
|
+
const options = queryOrOptions && typeof queryOrOptions === "object" ? queryOrOptions : { searchQuery: queryOrOptions, filterFn: legacyFilterFn };
|
|
4
|
+
const { searchQuery, filterFn, searchFields, where, sortFn } = options;
|
|
5
|
+
const fieldsKey = searchFields ? searchFields.join(",") : "";
|
|
6
|
+
const whereKey = where ? JSON.stringify(where) : "";
|
|
3
7
|
return useMemo(() => {
|
|
4
8
|
if (!items) return [];
|
|
9
|
+
let list = items;
|
|
10
|
+
const conditions = where ? Object.entries(where).filter(([, v]) => v !== void 0 && v !== null && v !== "") : [];
|
|
11
|
+
if (conditions.length) {
|
|
12
|
+
list = list.filter((item) => conditions.every(([field, value]) => String(item?.[field]) === String(value)));
|
|
13
|
+
}
|
|
5
14
|
const searchLower = (searchQuery || "").toLowerCase();
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
if (searchLower) {
|
|
16
|
+
list = list.filter((item) => {
|
|
17
|
+
if (filterFn) return filterFn(item, searchLower);
|
|
18
|
+
if (searchFields) {
|
|
19
|
+
return searchFields.some((field) => {
|
|
20
|
+
const value = item?.[field];
|
|
21
|
+
return value !== void 0 && value !== null && String(value).toLowerCase().includes(searchLower);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return Object.values(item).some((val) => {
|
|
25
|
+
if (typeof val === "string") return val.toLowerCase().includes(searchLower);
|
|
26
|
+
if (val && typeof val === "object") return JSON.stringify(val).toLowerCase().includes(searchLower);
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
13
29
|
});
|
|
14
|
-
}
|
|
15
|
-
|
|
30
|
+
}
|
|
31
|
+
if (sortFn) list = [...list].sort(sortFn);
|
|
32
|
+
return list;
|
|
33
|
+
}, [items, searchQuery, filterFn, fieldsKey, whereKey, sortFn]);
|
|
16
34
|
}
|
|
17
35
|
export {
|
|
18
36
|
useFilteredItems as default
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const PHONE = "(max-width: 639.98px)";
|
|
3
|
+
const PROBE_FRAMES = 45;
|
|
4
|
+
const SLOW_FRAME_MS = 22;
|
|
5
|
+
function useGlassToolbar({ storageKey = "okjt-toolbar-solid" } = {}) {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const root = document.documentElement;
|
|
8
|
+
const phone = window.matchMedia?.(PHONE);
|
|
9
|
+
let solid = false;
|
|
10
|
+
try {
|
|
11
|
+
solid = localStorage.getItem(storageKey) === "1";
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
root.classList.toggle("toolbar-solid", solid);
|
|
15
|
+
let last = /* @__PURE__ */ new Map();
|
|
16
|
+
let probing = false;
|
|
17
|
+
let probed = solid;
|
|
18
|
+
const probe = () => {
|
|
19
|
+
if (probed || probing || !phone?.matches || !CSS.supports?.("backdrop-filter", "blur(1px)")) return;
|
|
20
|
+
probing = true;
|
|
21
|
+
const times = [];
|
|
22
|
+
let prev = performance.now();
|
|
23
|
+
const tick = (now) => {
|
|
24
|
+
times.push(now - prev);
|
|
25
|
+
prev = now;
|
|
26
|
+
if (times.length < PROBE_FRAMES) {
|
|
27
|
+
requestAnimationFrame(tick);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const avg = times.slice(5).reduce((a, b) => a + b, 0) / (times.length - 5);
|
|
31
|
+
probed = true;
|
|
32
|
+
probing = false;
|
|
33
|
+
if (avg > SLOW_FRAME_MS) {
|
|
34
|
+
root.classList.add("toolbar-solid");
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(storageKey, "1");
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
requestAnimationFrame(tick);
|
|
42
|
+
};
|
|
43
|
+
const onScroll = (e) => {
|
|
44
|
+
if (!phone?.matches) {
|
|
45
|
+
root.classList.remove("toolbar-tucked");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const el = e.target === document ? document.scrollingElement : e.target;
|
|
49
|
+
if (!el || typeof el.scrollTop !== "number" || el.closest?.('.admin-floating-toolbar, [role="dialog"]')) return;
|
|
50
|
+
const top = el.scrollTop;
|
|
51
|
+
const delta = top - (last.get(el) ?? top);
|
|
52
|
+
last.set(el, top);
|
|
53
|
+
if (delta > 6 && top > 80) root.classList.add("toolbar-tucked");
|
|
54
|
+
else if (delta < -6 || top <= 80) root.classList.remove("toolbar-tucked");
|
|
55
|
+
probe();
|
|
56
|
+
};
|
|
57
|
+
document.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
58
|
+
return () => {
|
|
59
|
+
document.removeEventListener("scroll", onScroll, { capture: true });
|
|
60
|
+
root.classList.remove("toolbar-tucked", "toolbar-solid");
|
|
61
|
+
last = /* @__PURE__ */ new Map();
|
|
62
|
+
};
|
|
63
|
+
}, [storageKey]);
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
useGlassToolbar as default
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okjt/dashboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Dashboard pages for OKJTech projects: page layout, hero, summary cards, floating toolbar with search and filters, side panel, lists, bulk actions, one way to save, and working together: presence, version history, sharing; the dashboard shell, sign-in pages and account menu",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
"directory": "packages/dashboard"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
|
-
".": "./dist/index.js"
|
|
13
|
+
".": "./dist/index.js",
|
|
14
|
+
"./toolbar-glass.css": "./dist/toolbar-glass.css"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist",
|
|
17
18
|
"README.md"
|
|
18
19
|
],
|
|
19
|
-
"sideEffects":
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"*.css"
|
|
22
|
+
],
|
|
20
23
|
"scripts": {
|
|
21
24
|
"build": "node build.mjs",
|
|
22
25
|
"prepack": "node build.mjs",
|